Circle APIs Documentation

Learn how to integrate with Circle APIs to accept traditional and stablecoin payments, embed digital wallets into your product or service, or power your internet marketplace.

✨ Swap USDC Across Blockchains

USDC is a fully collateralized US Dollar stablecoin present across multiple chains. With Circle APIs, developers can seamlessly swap USDC tokens from one of the supported chains to another.

In this guide we will walk you through an example where USDC funds are transferred from the Ethereum blockchain over to the Algorand blockchain. However, it makes no difference which chains you decide to use or in which order.

📘

Circle's USDC Cross-chain Bridge

Circle's solution is a "private bridge" approach, where Circle is involved as a counter-party to the swap operation. This means funds being swapped are temporarily kept in Circle's custody. Note that this process is fully automated and involves no human intervention.

1. Get an API key

The Circle Wallets API uses API keys as the mechanism to authenticate client requests. The API key must be set in the Authorization header of the request sent from your backend server. The format of the header is Bearer secret-key-value.

To obtain an API key for the sandbox environment, simply create an account (if you don't already have one) and generate a new key in settings - it only takes a few seconds.


Get an API key

2. Receive USDC from the Ethereum blockchain

You can transfer USDC from an external wallet on any of the supported chains into a Circle wallet you control. For the purpose of this guide we will begin by transferring USDC funds from an external Ethereum wallet.

We will begin by creating a new wallet to receive the external funds. You can create new hosted wallets using the create wallet endpoint. Use the command below (remember to create your own idempotency key).

# Replace ${YOUR_API_KEY} with your API key
curl -H 'Content-type: application/json' \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -X POST https://api-sandbox.circle.com/v1/wallets \
  --data '{"idempotencyKey": "4ddef365-f2fc-4a56-95f5-a214c84ba8f4"}'

You should receive a response like the below.

{
  "data":{
    "walletId":"1000005062",
    "entityId":"7cbdedb1-d526-46b4-af12-4162a002eb9c",
    "type":"end_user_wallet",
    "balances":[]
  }
}

Next, we will create a new Ethereum deposit address and associate it with the newly created wallet. You can create a new deposit address using the generate new address endpoint. You have to properly specify the currency (USD) and chain (ETH) attributes to ensure the API generates a USDC deposit address for the Ethereum blockchain. You can generate an address using the command below (generate your own idempotency key).

# Replace ${YOUR_API_KEY} with your API key
# Replace ${WALLET_ID} with the wallet id from the previous step
curl -H 'Accept: application/json' \
  -H 'content-type: application/json' \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -X POST --url https://api-sandbox.circle.com/v1/wallets/${WALLET_ID}/addresses \
  --data '{"idempotencyKey": "ed9a7b3b-b45f-4262-a8aa-8dfee5a4f31b", "currency": "USD", "chain": "ETH"}'

You will receive a response like the below.

{
  "data":{
    "address":"0x618b24211048c6ec8b29e8129c2bbc5cf80c9f0b",
    "currency":"USD",
    "chain":"ETH"
  }
}

Next, it's time to transfer the funds from the Ethereum blockchain. The sandbox environment is connected to the Ethereum Ropsten testing network, so you can send USDC from a Ropsten wallet into your Circle hosted wallet.

❗️

Do NOT send real / live USDC to addresses generated in the sandbox environment as your funds might be permanently lost.

You can obtain some USDC on Ropsten for testing by using a USDC faucet. Go to usdcfaucet.com and make sure you choose the Ropsten button. Paste the deposit address you created above (be very careful to not miss any characters) and hit Submit.

You will be able to monitor the transfer on the blockchain by using the Ropsten Etherscan link provided by the faucet, which should look like the below:

https://ropsten.etherscan.io/tx/0xdff7b1a6f62183b5...1aaf2fbb74bbdba6.

3. Check the Status of the Transfer

You can use the retrieve transfers endpoint to find transfers that are destined to the wallet you created earlier. You can use it as in the command below.

# Replace ${YOUR_API_KEY} with your API key
# Replace ${WALLET_ID} with the wallet id from the previous step
curl -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -X GET https://api-sandbox.circle.com/v1/transfers?destinationWalletId=${WALLET_ID}

You will receive a response like below.

{
  "data":[
    {
      "id":"9f6362f4-a3d2-396e-a1eb-b628ec3a29b2",
      "source":{
        "type":"blockchain",
        "chain":"ETH"
      },
      "destination":{
        "type":"wallet",
        "id":"1000005062",
        "address":"0x618b24211048c6ec8b29e8129c2bbc5cf80c9f0b"
      },
      "amount":{
        "amount":"1.00",
        "currency":"USD"
      },
      "transactionHash":"0xbd3085c3faed933f4093a7b93419ca934fa09d62fe62115d4b3f38a4a94e3a89",
      "status":"running",
      "createDate":"2020-09-21T18:50:06.202Z"
    }
  ]
}

You can look up the transactionHash on Etherscan's tracker on Ropsten.

As you can see on the response above, the status shows up initially as running because the transaction has been recently initiated. After waiting a few minutes for it to reach the required 30 block confirmations, the status will change to complete. Once it does so (and only once it does so), Circle will credit the receiving wallet with the value of the transfer.

At this point you have successfully received USDC from the Ethereum blockchain using the Circle Wallets API.

4. Send USDC to the Algorand blockchain

Once the receiving leg of the swap operation settles, you can initiate the second leg which is sending the USDC funds to an Algorand blockchain address.

You need to choose the Algorand blockchain address to send to (destination). Circle's sandbox environment is connected to the Algorand TestNet, so the destination blockchain address has to be a valid Algorand TestNet address.

📘

Algorand Wallet TestNet Account

You can download the Algorand Wallet, switch to TestNet under "Settings" > "Node Settings", and then obtain your account address from the main wallet screen.

Your Algorand TestNet wallet address should look similar to: BL27TI3CYMFX5URLYNBJJZGV4ABRYJJHBMLRR5OYSVPUVDIUAF66IR4COA.

🚧

Opt-in to Accept the USDC Asset

Algorand Standard Assets include a feature called "spam protection" that prevents unknown assets which may have tax, legal, or reputational risk from being sent to users without their explicit approval. In effect users must opt-in to accept new assets such as USDC. You can opt-in by selecting the "Add New Asset" option, and then searching for "USDC" (the USDC asset ID on Algorand TestNet is [10458941](https://developers.circle.com/docs/usdc-on-testnet#usdc-on-algorand-testnet)).

📘

ALGO Dispenser (Faucet)

In order to opt-in on the USDC asset (or any Algorand asset for that matter), you need to pay for a transaction. You can obtain some TestNet ALGO tokens on the TestNet ALGO Dispenser (Faucet).

To send funds to the external Algorand wallet, you will use the create wallet transfer endpoint.

Once again, you have to specify the correct pair of currency and chain attributes that suit the destination blockchain. You can create a USDC transfer to an Algorand blockchain address by using the command below.

# Replace ${YOUR_API_KEY} with your API key
# Replace ${YOUR_WALLET_ID} with your master wallet id
curl -H 'Accept: application/json' \
  -H 'Content-type: application/json' \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -X POST https://api-sandbox.circle.com/v1/transfers \
  --data '{"idempotencyKey": "fbba9d81-72f1-4bf8-97c8-99f1f28995e2", "source": {"type": "wallet", "id": "${YOUR_WALLET_ID}"}, "destination": {"type": "blockchain", "address": "BL27TI3CYMFX5URLYNBJJZGV4ABRYJJHBMLRR5OYSVPUVDIUAF66IR4COA", "chain": "ALGO"}, "amount": {"amount": "1.00", "currency": "USD"}}'

You should receive a response like the below.

{
  "data":{
    "id":"9dd86dfe-72e8-4182-9573-04196cc7d6cb",
    "source":{
      "type":"wallet",
      "id":"1000005062"
    },
    "destination":{
      "type":"blockchain",
      "address":"BL27TI3CYMFX5URLYNBJJZGV4ABRYJJHBMLRR5OYSVPUVDIUAF66IR4COA",
      "chain":"ALGO"
    },
    "amount":{
      "amount":"1.00",
      "currency":"USD"
    },
    "status":"pending",
    "createDate":"2020-09-21T20:31:39.507Z"
  }
}

5. Check the Status of the Transfer

Again, you can use the get transfer endpoint to retrieve details about the status of the transaction. You can use it as in the command below.

# Replace ${YOUR_API_KEY} with your API key
# Replace ${TRANSFER_ID} with the id of the transfer you created earlier
curl -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -X GET https://api-sandbox.circle.com/v1/transfers/${TRANSFER_ID}

You will receive a response like below.

{
  "data":{
    "id":"474a47af-b05b-4fab-a9b8-3b66748133b3",
    "source":{
      "type":"wallet",
      "id":"1000005062"
    },
    "destination":{
      "type":"blockchain",
      "address":"BL27TI3CYMFX5URLYNBJJZGV4ABRYJJHBMLRR5OYSVPUVDIUAF66IR4COA",
      "chain":"ALGO"
    },
    "amount":{
      "amount":"1.00",
      "currency":"USD"
    },
    "transactionHash":"PS74XNN7GHNQTVEV52ZMYHR3CWTKLJUFZ5U3DD43P5WO6GO5VDLQ",
    "status":"complete",
    "createDate":"2020-09-23T21:35:03.563Z"
  }
}

6. Did you see how fast that was? 😱😱😱

Right? Algorand transactions confirm in less than 5 seconds, so hold on to your hat.

7. Ready for the next step?

If you are in advanced stages of experimenting with our APIs and want to plan moving to production, please start by applying for a business account and subsequently reach out to sales. We'll be happy to walk you through to the next steps.

We can't wait to see what you are going to build!

Updated about a month ago


✨ Swap USDC Across Blockchains


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.