srcChainIdspecifies the Ethereum chain id (
1) as the chain swap is being initiated
srcChainTokenInspecifies the USDT token address (
srcChainTokenInAmountspecifies the desired input amount: since USDT token contract uses 6 decimals (the number of digits that come after the decimal place when displaying token values on-screen), the simple math:
50 * 10^6leads to
50000000as the value representing 50 USDT tokens
dstChainIdspecified the Polygon network chain id (
137) as the target (destination) chain
dstChainTokenOutspecifies the address of the target token; since MATIC is not a typical ERC-20 token represented by a smart contract but rather a native coin (a one-of-a-kind token within each EVM chain), we use a null (or zero) address to distinguish it from other tokens.
slippageparameter defines a constraint that acts as a safeguard to protect from a possible price drop. By specifying
1(means 1%) we allow a DEX to perform exchange only if the actual outcome is not less than 99% of the estimated outcome.
executionFeeAmount=autoasks the estimator to include (and subtract it from the outcome) a minimum execution fee (included gas fee) sufficient to incentivize anyone to execute the transaction on the destination chain
estimation.dstChainTokenOutwe can see the actual amount of MATIC the user may receive as a result of the swap:
29570160331501581528 / 10^18), and at least 29.27 MATIC in a worst-case scenario (which corresponds to 99% of the estimated value since the slippage was initially set to 1%).
estimation.executionFeeobject containing details about the execution fee token and the amount which has been subtracted from the estimated outcome:
/transactionendpoint for that, which expects at least all the parameters the
/estimationendpoint does, and additionally two wallet addresses on the destination chain:
dstChainTokenOutRecipient, the address target tokens should be transferred to after the swap, and
dstChainFallbackAddress, the address target or intermediary tokens should be transferred in case of a failed swap (e.g., a swap may fail due to slippage constraints).
estimationobject has the same name and structure as inside the result of the
/estimationendpoint, you are already familiar with. It may contain values that are slightly differ from the previous call, as the prices of crypto assets are highly volatile, so don't be surprised to see a corrected estimation.
txobject has the following structure:
txobject speak for themselves:
tois the field the transaction should be sent to, and typically you should expect the address of one of the smart contracts responsible for forwarding;
datais the contents of the transaction, containing instructions related to swaps planned on the source or (and) on the destination chains, bridging settings, etc;
valueis the amount of native coins that must be sent along with the transaction.
valueis always positive, even if you plan to swap an ERC-20 token. This is because the underlying deBridge protocol takes a fixed amount in the base asset of the blockchain, and the API always includes it as the transaction value. In the above example, the
valueequals the current fixed fee, which is 0.001 ETH on the Ethereum blockchain. You can learn more about this by reading the deBridge protocol documentation. Soon we'll give everyone the ability to pay this fixed fee in the input asset rather than the native coin.
tx.tofield prior to submitting this transaction so it can transfer them on the behalf of the sender. This can be typically done by calling either
increaseAllowance()method of the smart contract which implements the token you are willing to swap. Approve at least the amount of tokens you are going to swap.
referralCodeparameter when calling the
/transactionendpoint. If you don't have it, you can get one by pressing the WAGMI button at https://app.debridge.finance/. Governance may thank you later for being an early builder.
databy calling the
/transactionendpoint provides the complete estimation of the route, so you might wonder about the purpose of the separate
/estimationendpoint. The reason is the performance and latency: doing numerous estimations in a row may be faster when calling
/estimationas it does not use some heavyweight calls used by the