Coinbase Commerce Onchain Payment Protocol

repository·master·Indexed 42 days ago

https://github.com/coinbase/commerce-onchain-payment-protocol

A protocol for secure, atomic cryptocurrency settlements between payers and merchants on Ethereum, Polygon, and Base. It utilizes Operators and signed TransferIntents to facilitate payments and emits Transferred events to confirm successful transactions.

Tokens
1.5K
Snippets
2
Records
4
Agent score
3%

What's inside Coinbase Commerce Onchain Payment Protocol

  1. How Operators and Transfer Intents work

    master

    The protocol relies on two main abstractions: Operators and Transfer Intents.

    1. Operators: Before use, an operator must register with the contract and specify a fee destination. Operators are responsible for setting up merchants and providing the UI for interaction. Registration is permissionless. Coinbase Commerce uses a specific address maintained by Coinbase as its operator.

    2. Transfer Intents: These are the primitives used to facilitate individual payments. A TransferIntent is a Solidity struct that must be signed by an operator. This signature ensures the intent cannot be forged or modified and allows operators to enforce policies (legal, internal, etc.) before a payment is allowed.

    TransferIntent Fields:

    • merchant: The merchant's address.
    • currency: The currency the merchant wishes to receive.
    • amount: The amount of that currency requested.
    • deadline: The expiration time for the payment.
    • payer: The payer's address.
    • chain: The chain the payer will pay on.
    • refundAddress: Where any refunds should be directed.
    • operator: The operator facilitating the payment.
    • fee: The fee the operator should receive.
    • id: A unique identifier for the payment.
    • signature: The operator's signature (and optional prefix).
  2. Monitor successful payments via Transferred events

    master

    When a payment is successful, the contract emits a Transferred event. You can listen for this event to confirm payment details.

    Event Fields:

    • operator: The operator address.
    • id: The unique ID of the TransferIntent.
    • merchant: The recipient address.
    • payer: The sender address.
    • inputToken: The token spent by the payer.
    • amount: The amount of the input token spent by the payer.
  3. Select the appropriate payment method for a TransferIntent

    master

    A frontend must select a payment method based on the settlement token, the input token, and how the payer allows token movement.

    Note: For EVM networks where ETH is not the native gas currency (e.g., Polygon), substitute ETH with the native currency (e.g., MATIC).

    - `transferNative`: The merchant wants ETH and the payer wants to pay ETH
    - `transferToken`: The merchant wants a token and the payer wants to pay with that token. Uses Permit2 for token movement.
    - `transferTokenPreApproved`: Same as `transferToken`, except the Transfers contract is directly approved by the payer for the payment token
    - `wrapAndTransfer`: The merchant wants WETH and the payer wants to pay ETH
    - `unwrapAndTransfer`: The merchant wants ETH and the payer wants to pay WETH
    - `unwrapAndTransferPreApproved`: Same as `unwrapAndTransfer`, except the Transfers contract is directly approved by the payer for WETH
    - `swapAndTransferUniswapV3Native`: The merchant wants a token and the payer wants to pay ETH. The token must have sufficient liquidity with ETH on Uniswap V3.
    - `swapAndTransferUniswapV3Token`: The merchant wants either ETH or a token and the payer wants to pay with a different token. The payment token must have sufficient liquidity with the settlement token on Uniswap V3.
    - `swapAndTransferUniswapV3TokenPreApproved`: Same as `swapAndTransferUniswapV3Token`, except the Transfers contract is directly approved by the payer for the payment token
  4. Deployments of the Commerce Onchain Payment Protocol

    master

    The protocol is deployed across Ethereum, Polygon, and Base. Note that the contract is non-upgradeable, so these addresses will change when new versions are released. Use the appropriate address for your target environment (Mainnet or Testnet).

    | Chain    | Environment     | Address                                      |
    | -------- | --------------- | -------------------------------------------- |
    | Ethereum | Mainnet         | `0x1DAe28D7007703196d6f456e810F67C33b51b25C` |
    | Ethereum | Sepolia Testnet | `0x96A08D8e8631b6dB52Ea0cbd7232d9A85d239147` |
    | Polygon  | Mainnet         | `0xc2252Ce3348B8dAf90583E53e07Be53d3aE728FB` |
    | Polygon  | Amoy Testnet    | `0x1A8f790a10D26bAd97dB8Da887D212eA49461cCC` |
    | Base     | Mainnet         | `0xeADE6bE02d043b3550bE19E960504dbA14A14971` |
    | Base     | Sepolia Testnet | `0x96A08D8e8631b6dB52Ea0cbd7232d9A85d239147` |