This quickstart uses Circle Wallets and Circle On/Off-Ramps as
examples; CPN does not require them. If you use your own wallet and USDC, see
Bring your own wallet for CPN
and Wallet provider
compatibility. For
Circle setup, follow the how-tos under Prerequisites.
Prerequisites
Before you begin this quickstart, ensure you have:- API keys created in CPN Console → Developer → API Keys with access to CPN and Programmable Wallets. If you fund USDC through Circle APIs for this exercise, you also need a key authorized for those Circle APIs endpoints.
- Completed operational wallet setup for the quickstart:
- Follow how to Set Up a Circle Wallet for CPN Payments, or use your own wallet that meets Wallet provider compatibility.
- You need the wallet ID of an EOA on the correct chain (
ETH-SEPOLIAwhen using testnet).
- Funded the operational wallet with enough USDC. For sandbox you can use the Circle faucet. For a guided Circle fiat-to-wallet path, follow how to Set Up Circle On/Off-Ramps for CPN Payments.
- Python installed on your development machine
- The latest
jwcrypto,web3,eth_utils,hexbytes, andeth_abilibraries are installed with thepippackage manager
- The latest
- cURL installed on your development machine
- Granted a USDC allowance to the
Permit2contract. See how to Grant USDC allowance to Permit2 for more information. - (Optional) a configured webhook notification endpoint
The base URL for all API endpoints is
https://api.circle.com/v1/cpn for both
sandbox and production environments. The API determines if a request is for
testnet or mainnet based on the key used to authenticate the request.Part 1: Request a quote
Request quotes for a USDC to MX payment with the SPEI payment method. Request quotes with the create a quote endpoint, providing the source currency and destination amount. You must specifytransactionVersion as VERSION_2. The endpoint returns a list of quotes from
various BFIs with the rate, expiration time, USDC settlement window, and unique
ID.
Quotes expire quickly (typically 30–60 seconds). If a quote expires before you
create the payment, the payment creation endpoint returns an error. Request a
new quote and restart from Part 1. Save the
id and quoteExpireDate from
the response so you can check expiration before proceeding.Part 2: Create a payment
Use the API to get the requirements for a payment, accept the quote, and create a payment.2.1. Get payment requirements
Call the/payments/requirements
endpoint with the quote ID to get the requirements for a payment. The endpoint
returns an object describing the required fields for the compliance check. The
optional field for each parameter defines if the parameter must be included in
the response constructed in the next step.
2.2. Encrypt the required fields
Construct a JSON object with the information requested in the previous step. For each schema, the properties that you must include are outlined by theoptional
field. Encrypt the object with the jwk certificate provided in the quote
response.
The correct format for travel rule data and beneficiary account data is a JSON
array of objects where each object contains two properties: name and value.
You can review an example of each field in how to
Encrypt Travel Rule Data.
Create a file called cpn_encryption.py and put the following code in it,
replacing the requirements_response_json parameter with the contents of the
response from the previous step, and the certificate_json parameter with the
jwk from the quote response. When you run the script, it outputs the encrypted
beneficiary and travel rule data to the console.
Python
2.3. Create a payment
After the quote is accepted, create a payment by calling the/payments endpoint. You need
to provide the quote ID and encrypted sender and receiver information. The
endpoint returns a unique payment ID and the initial status of the payment.
You must create the payment before the quote expires. If the quote has
expired, request a new quote and restart from Part 1. Once the payment is
created, save the payment
id and expireDate. You must complete the onchain
transaction before the payment expires.Shell
JSON
Part 3: Create a transaction
Use the API to create a blockchain transaction to transfer USDC. Sign the transaction locally, and use the API to broadcast it to the blockchain.This quickstart uses Circle Wallets (or your equivalent operational wallet) as
the originator wallet. Use the wallet ID from the
prerequisites section, including any funding you completed
via the Circle Wallet or Circle On/Off-Ramps how-tos.
3.1. Initiate the onchain transaction
Initiate the onchain funds transfer by calling the create transaction V2 endpoint with the payment ID from the previous step, and other transaction-related parameters. The endpoint returns an unsigned onchain transaction object and a transaction ID.3.2 Sign the onchain transaction
The following steps are for EVM blockchains. For Solana, you would follow a
similar process with some differences in the signing. Refer to how to Create
an Onchain Transaction for
more information.
/sign/typedData
endpoint, input the messageToBeSigned object from the previous step along with
your entity secret and wallet ID. The transaction parameter should be
stringified from the
messageToBeSigned field from the transaction response.
Shell
JSON
3.3. Submit the signed transaction
Use the/v2/cpn/payments/{paymentId}/transactions/{transactionId}/submit
endpoint to submit the transaction to be broadcast to the blockchain. You should
submit the EIP-712 typed data signature you obtained from the /sign/typedData
endpoint in step 3.2. as
signedTransaction.
Shell
JSON
transactionHash will be provided after transaction is in COMPLETED status.
You can monitor for the transactions webhook events to get the
transactionHash.