Prerequisites
Before you begin this quickstart, ensure you have:- Obtained an API key for StableFX from Circle
- Set up a web3 provider or wallet that supports EIP-712 signatures and Permit2
- Granted a token allowance to the
Permit2contract. See How-to: Grant USDC Allowance to Permit2 for more information. - Installed cURL on your development machine
StableFX uses a single endpoint for all API requests. The base URL is
https://api.circle.com/. The StableFX API uses your API key for authentication
and to determine which environment to use. The TEST environment executes
against Arc testnet and returns mock data.When developing or testing your integration, you should use your TEST API key.
When you are ready to move to production, just update your code to use your
LIVE API key.Part 1: Request a quote
Request a quote for a USDC to EURC trade using the create a quote endpoint. You should provide a value for theamount parameter in either the to or from fields,
but not both.
Part 2: Create a trade
Accept the quote and create a trade on StableFX using the create a trade endpoint. You need to provide the quote ID and a randomly generated idempotency key in UUIDv4 format.Part 3: Confirm trade intent
Confirm your trade intent through the StableFX API before submitting the trade on the blockchain.3.1. Generate taker signature data
To submit the trade, you must first sign the trade intent typed data with an EIP-712 signature. To get the data to sign, call the generate trade presign data endpoint. Your request must include the ID of the trade in a confirmed status and the address of the recipient of the trade.3.2. Sign the data
Using aPermit2-compliant EIP-712 compatible wallet or application, sign the
data returned in the previous step.
3.3. Submit the trade signature
Confirm your trade intent by submitting the signed data to the register trade signature endpoint. This request must include the trade ID, the side of the trade that you are taking, the address of the wallet that signed the typed data, the message of the typed data, and the taker’s signature.200 response.
3.4. Confirm the trade is ready for funding
Before you submit funds onchain, you should confirm that the trade is ready for funding. To do this, call the get a trade by ID endpoint. A trade is ready for funding when the status ispending_settlement.
Part 4: Submit the funds onchain
Next, you need to deliver the funds onchain to complete the trade. The StableFX API can handle the onchain transaction for you using thePermit2 contract.
4.1. Get the funding signature data
To use the StableFX API to deliver the funds onchain, you must first sign the funding typed data with an EIP-712 signature. To get the data to sign, call the generate funding presign data endpoint. Your request must include the contract ID of the trade and the side of the trade that you are taking. The following an example request:4.2. Sign the funding data
Using aPermit2-compliant EIP-712 compatible wallet or application, sign the
data from the typedData field returned in the previous step.
4.3. Submit the funding signature
To deliver the funds onchain, you must submit the taker-specificPermit2 data
along with your signature to the
fund trade endpoint. The endpoint
allows you to submit either a single object or a batch of objects along with the
required signatures.
The following is an example request for a single trade:
200 response.
Note: It’s not required to submit the funding transaction through the
StableFX API. You can submit the transaction onchain using your own web3
provider or wallet.
4.4. Confirm the trade is funded
To confirm that the trade is funded, call the get a trade by ID endpoint. A trade is funded when the status istaker_funded.