Permit2
contract to enable allowance management. To get the benefits of Transactions V2,
you must grant a USDC token allowance to the Permit2 contract.
This guide shows three examples of how to grant a USDC token allowance to the
Permit2 contract. The
Permit2 documentation
provides additional examples of how to grant this allowance.
Prerequisites
The examples on this page show how to grant a USDC token allowance to thePermit2 contract using a
Circle Wallets developer-controlled wallet or a
generic EIP-1193 Ethereum wallet. The headless example is for a bring-your-own-
wallet (BYOW) OFI that signs transactions in its backend. Before you begin,
ensure you have:
-
If you are following the Circle Wallets example:
- A Circle Developer Account
- A developer-controlled wallet
- Node.js and npm installed on your development machine
- A project set up as described in the following section
Set up your project
-
Initialize a new Node.js project and install dependencies:
-
In the project root, create a
.envfile and add the following variables:ThePERMIT2_CONTRACT_ADDRESSis the same across all EVM blockchains (0x000000000022D473030F116dDEE9F6B43aC78BA3), but you should verify it with the blockchain explorer on the chain you are using. You can find theUSDC_CONTRACT_ADDRESSon the USDC contract address page.If you are following the Circle Wallets example, you will also need to add the following variables:The USDC token has 6 decimals. Set the allowance to cover the expected payment amount plus any associated fees. For a $100 payment, setAPPROVAL_AMOUNTto at least100000000(100 * 106) plus the fees converted to raw USDC units.If you are following the EIP-1193 Ethereum wallet example, or your Circle Wallet is on the genericEVM/EVM-TESTNETchain, you will also need to add the following variable: -
Create an
index.tsfile. You’ll add code step by step in the following sections. Run it withnpx tsx index.ts.
Grant a USDC token allowance to the Permit2 contract
The following example code shows the process for granting a USDC token allowance
to the
Permit2 contract
using a Circle Wallets developer-controlled wallet or an EIP-1193 Ethereum
wallet.
- Circle Wallets
- Circle Wallets (generic EVM)
- Headless BYOW wallet
- EIP-1193 Ethereum Wallet
This example is for a Circle Wallets developer-controlled wallet on specific EVM
blockchains (for example,
ETH, ETH-SEPOLIA, MATIC, MATIC-AMOY, etc.). If
your Circle Wallet is on the generic EVM / EVM-TESTNET chain, use the
example in the “Circle Wallets (generic EVM)” tab.messageToBeSigned
returned by the
create transaction V2 endpoint.
Submit the resulting signature in the signedTransaction field of the
submit transaction V2 endpoint.