How to Swap
Use Stargate to transfer an asset across blockchains.
function swap(
uint16 _dstChainId,
uint256 _srcPoolId,
uint256 _dstPoolId,
address payable _refundAddress,
uint256 _amountLD,
uint256 _minAmountLD,
lzTxObj memory _lzTxParams,
bytes calldata _to,
bytes calldata _payload
) external payable override nonReentrant {// perform a Stargate swap() in a solidity smart contract function
// the msg.value is the "fee" that Stargate needs to pay for the cross chain message
IStargateRouter(routerAddress).swap{value:msg.value}(
10006, // send to Fuji (use LayerZero chainId)
1, // source pool id
1, // dest pool id
msg.sender, // refund adddress. extra gas (if any) is returned to this address
_amountLD, // quantity to swap in LD, (local decimals)
_minAmountLD, // the min qty you would accept in LD (local decimals)
IStargateRouter.lzTxObj(0, 0, "0x") // 0 additional gasLimit increase, 0 airdrop, at 0x address
abi.encodePacked(msg.sender), // the address to send the tokens to on the destination
bytes("") // bytes param, if you wish to send additional payload you can abi.encode() them here
);Last updated
