DAI - xDai Bridge
Transfer of DAI tokens to xDai native tokens using token bridge
Before we continue, please ensure that you have had a look at our Supported Ethereum Chains, followed the steps in Install Etherspot SDK and how to Bootstrap Etherspot SDK. We're assuming that you have completed these steps before going forward.
In this example, we're going to show you how to send DAI to xDai using their TokenBridge and Etherspot.
🛑 Before we continue...
We're going to be using two Etherspot SDK instances here:
A
mainnetversion
↗️ We will use this instance to send our DAI from and ETH to pay the gas fees.
A
xDaiversion
↘️ We will use this instance to receive our xDai on the xDai chain.
⚠️ Make sure you've checked out Supported Ethereum Chains before you continue as we also show you the code to instantiate mainnet and xDai versions of the SDK. Remember to use the same private key for both SDK instances to get the same Ethereum address on both mainnet and xDai.
This example use case is quite simple and straight forward, as the TokenBridge is a managed service in itself, however this example is often a requirement for many bridge services and serves as a building block.
We're using mainnet to send assets for this example. For other networks, please ensure that you are using the correct contract addresses for that network.
Please make sure your that your mainnet Etherspot address is funded with DAI tokens and enough ETH to pay the gas fees required.
✉️ Sending DAI to TokenBridge
First, let's install a prerequisite NPM package we're going to need. The erc-20-abi package will provide us with the ERC20 token interface to interact with.
npm i erc-20-abiyarn erc-20-abiNext, let's retrieve the the abi from the erc-20-abi package.
Next, let's define our essential variables. We need the DAI token contract address and the Token Bridge contract address. Remember, on different networks, the contract address is different! The contract addresses before are for mainnet.
Next up, let's prepare our request to interact with the contract, and calculate the value we want to send.
Before we continue, let's clear the Etherspot SDK Transaction Batch queue. We're keeping the house clean 🧹
Finally, we're going to perform a series of steps to:
Add the transaction to the batch
Estimate the gas required to perform this transaction
Send the batch to Etherspot to be processed
🎉 Finished!
Once this process has completed, the TokenBridge service will send your xDai to the same address, but on the xDai chain.
Your xDai will arrive in the xDai version of your Etherspot address, which is accessible via the xDai version of your Etherspot SDK which was created earlier: xdaiEtherspotSdk. Did you miss that bit? Check out the "Before we continue" section: DAI - xDai Bridge.
🚏 Here are some helpful links:
Check out the Supported Ethereum Chains
Prototype your ideas now with the Etherspot Playground
Last updated
Was this helpful?