Capsule Docs
  • Introduction
  • Protocol Overview
    • Packaging and Shipping
      • Capsule Redemption Page
      • Capsule Relay
      • Example Integration
    • Use Cases
      • Compromised Address
      • Gasless Pickup
      • Gate Shipments
      • Time Locking Shipments
      • Walletless Pickup
      • Whitelisted Shipment
      • Wrong Address
    • Future
      • Capsule Invoice
      • Capsule Network
      • Lightning Bridging
    • Developer Walkthroughs
      • PostOffice.sol
      • Code Examples
        • Conditional Redemption
        • Conditional Shipment
        • Shipment POAPs
        • Whitelisted Redemption
  • Collaboration
    • Advertising
    • Partnership
  • Economics
    • Fee Structure
  • CapsuleNFT
    • Overview
      • Types of Capsule NFTs
      • Capsule Collections
        • Metamaster
        • Lockability
        • Private/Public
        • Collection Examples
        • Official Capsule Collections
    • Developer Walkthroughs
      • Developer Overview
      • Contracts
        • Capsule.sol
        • CapsuleFactory.sol
        • CapsuleMinter.sol
        • Testnets
          • Ethereum - Goerli
      • Developer - Mint a Capsule NFT
      • Developer - Redeem a Capsule NFT
      • Developer - Create a Capsule Collection
      • Developer - Managing a Capsule Collection
    • Use Cases
      • For Artists
      • For DeFi
      • For Gaming
    • Examples
      • Dollar Store Kids
    • Comparison to ERC-998
  • Additional Resources
    • FAQ
    • Official Links
    • Brand Kit
    • Legal
      • Terms of Use
      • Privacy Policy
      • Cookie Policy
      • CCPA Notice
      • Risks
    • Security
  • Send Feedback
    • Report a Bug
    • Contact Us
Powered by GitBook
On this page
  1. Protocol Overview
  2. Developer Walkthroughs
  3. Code Examples

Conditional Shipment

Conditional On-Chain Package Shipment

As an example, we can create a wrapper contract that will only allow users to ship a package if more than 1,000,000 USDC is included.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import "./PostOffice.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract MillionDollarShipmentService {
    using SafeERC20 for IERC20;

    PostOffice public postOffice;
    IERC20 public usdcToken;

    uint8 public constant USDC_DECIMALS = 6;
    uint256 public constant MIN_PACKAGE_VALUE = 1_000_000 * 10 ** USDC_DECIMALS;

    constructor(address _postOfficeAddress, address _usdcTokenAddress) {
        postOffice = PostOffice(_postOfficeAddress);
        usdcToken = IERC20(_usdcTokenAddress);
    }

    function createMillionDollarPackage(
        CapsuleData.CapsuleContent calldata packageContent_,
        PostOffice.SecurityInfo calldata securityInfo_,
        address receiver_,
        uint256 usdcAmount_
    ) external returns (uint256) {
        require(usdcAmount_ >= MIN_PACKAGE_VALUE, "Package value is below 1 million USDC");

        usdcToken.safeTransferFrom(msg.sender, address(this), usdcAmount_);

        return postOffice.shipPackage(packageContent_, securityInfo_, receiver_);
    }

    function pickup(
        uint256 packageId_,
        string calldata rawPassword_,
        string calldata salt_,
        bool shouldRedeem_
    ) external {
        postOffice.pickup(packageId_, rawPassword_, salt_, shouldRedeem_);
    }
}

MillionDollarShipmentService allows users to create a unique shipment by providing more than 1,000,000 USDC tokens. The createMillionDollarPackage method creates the package by transferring the USDC tokens from the sender to the contract if the million dollar criteria is met, and then invokes the shipPackage method from the PostOffice contract to initiate the shipment process.

PreviousConditional RedemptionNextShipment POAPs

Last updated 1 year ago