Integration Guide
To perform a cross chain swapOutToken() in solidity, here is an example:
For the native gas fee required for swapOutToken() you need to call getNativeFee() to get the amount you should send as msg.value.
getNativeFee() interface;
function getNativeFee(
address _token, //bridge token
uint256 _gasLimit, // call gas limit on target chain
uint256 _toChain // target chain id
) external view returns (uint256);swapOutToken() interface
function swapOutToken(
address _sender, // user account send this transation
address _token, // src token
bytes memory _to, // receiver account (if _swapData not empty _to must contract who implement IButterReceiver)
uint256 _amount, // token amount
uint256 _toChain, // target chain id
bytes calldata _swapData
) external payable returns (bytes32 orderId);First determine the swap fee by call getNativeFee(), then call swapOutToken() to transfer the asset to the destination chain.
// get native fee
uint256 value = IButterBridgeV3(bridgeAddress).getNativeFee(token,gasLimit,toChain);
// perform a butter swapOutToken() in a solidity smart contract function
IButterBridgeV3(bridgeAddress).swapOutToken{value:value}(
msg.sender, // user account send this transatio
token, // bridge token (zero address for native token)
toAddress, // target chain receiver address
amount, // bridge token amount
toChain, // target chain id
swapDat // encode swap Data
);To perform a swapOutToken() using ethers via a frontend, use the abi and call swapOutToken() on the Router contract instance:
BridgeParam.swapData if need call contract on target chain otherwise set '0x' for it
need call contract on target chain ? must make sure parameter _to is a contract and implement IButterReceiver.
IButterReceiver
Last updated