How to Integrate Front-end Bridges
Last updated
Last updated
To use an existing Bridge, the first task is to retrieve the Bridge information for the chain that it is being sent to. For instance you can get an object describing the Fantom Bridge (chainID: 250)
This is JSON describing all token bridges from all chains to Fantom. This is a very large object, but if we are interested in one particular token, say SHIBA INU, bridged from Ethereum, we can find the object member describing it
The DcrmAddress is generated by the SMPC network and is the address to which SHIB (and all other tokens being sent from Ethereum to Fantom) is transferred to. This can be a normal send transaction, though if it is a smart contract sending the tokens, it's address must be whitelisted before this can occur (contact team).
If you look at this contract, you see two types of transaction in addition to the normal Transfer and Approve functions: Swapin and Swapout.
The Swapin is the contract receiving instructions from the SMPC network, which detected that the DcrmAddress had been sent SHIB on Ethereum. The contract will then mint SHIB on Fantom.
The Swapout function is when a user sends SHIB back to Ethereum. The contract method swapout is called, which will cause the contract to burn the SHIB and the SMPC network will release SHIB to the destination address on Ethereum.
In this we can see the two functions swapin and swapout and we see the calls for _mint for swapin and to _burn for the swapout
The other parameters in the SrcToken and DestToken objects are related to fees and limits on transaction amounts.
MaximumSwap and MinimumSwap are the min and max amounts that can be swapped in wei,
BigValueThreshold is the amount after which a transfer will trigger a requirement for a manual authorization ("Big Amount")
SwapFeeRate is the percentage fee for amounts between the minumum and maximum fee.
PlusGasPricePercentage is how much gas beyond the estimated gas to pay to ensure that transactions are picked up from the mem pool.
DisableSwap is whether the Bridge is disabled or not ("false" for normal usage).
If we look at the SrcToken first, we see the ContractAddress is just the ERC20 contract on Ethereum
In the DestToken, we see that the SHIB token created on Fantom is the AnyswapV5ERC20 contract
The standard wrapped asset contract is called AnyswapV5ERC20 and is a superset of the standard ERC20 token. Here is the
The coder can use an API to check the transaction status for a source transaction hash. An example of this is for this transaction sending BNB from BSC to Fantom . You can interrogate the status for this cross chain transaction and we see that the returned JSON has "msg":"Success" and a lot more information about the cross chain transfer too.
There is more information on the github regarding the API here, including how to get the history for tokens and addresses