Comment on page

Contract: Pool-Based Transfer

Trigger cBridge contract `send` function to move user's assets to cBridge contract on source chain. Then cBridge gateway and Celer SGN will send assets to the user's asset on the destination chain

Implementation

Pool-based transfers are done via the Bridge contract, specifically via the send or sendNative functions. For advanced users, these two functions can be called from smart contracts, but please read the refund process before you proceed.
  • Transfer gas token(ETH): sendNative. No need to provide token address
  • Transfer ERC20 token: send. Token address is needed
/// SendNative
const transferTx = await transactor(
bridge.sendNative(
"0xaa47c83316edc05cf9ff7136296b026c5de7eccd", /// User's wallet Address
100000000, /// Transfer amount with decimal
4002, /// Destination chain id
1638864397751, /// Nonce
3000, /// Max slippage
{
value: 100000000, /// Same amount as above
},
),
).catch(e => {
/// Handle Error
});
/// Send
const transferTx = await transactor(
bridge.send(
"0xdad9d86885d217b92a47370e1e785897dd09a4f3", /// User's Wallet Address
"0x7d43aabc515c356145049227cee54b608342c0ad", /// Selected Token Address
10000000000, /// Transfer amount with decimal
5, /// Destination chain id
1638862397751, /// Nonce
780, /// Max slippage
),
).catch(e => {
/// Handle Error
});

Request Parameters

Name
Type
Description
receiver
String
User's wallet address
token
String
Token's address on source chain
amount
BigNumber
Token amount to be sent
dst_chain_id
BigNumber
Destination chain id
nonce
BigNumber
Current timestamp
max_slippage
BigNumber
Use the value given by amount estimation
If you want to use a max_slippage with your own calculation, please make sure it is not less than minimalMaxSlippage given by cBridge contract. Otherwise, the transaction will fail.
If receiver is a smart contract and the token you are sending is a wrapped native gas token on the destination chain, make sure the contract can receive native gas token by implementing fallback / receive functions.

TransferId Generation

When you submit on-chain send transaction, you can also generate a transfer id for future reference. For example, it is used for getTransferStatus and withdrawLiquidityForTransferRefund. It should be the same as transferId inside on-chain transaction log.
const transfer_id = ethers.utils.solidityKeccak256(
[
"address",
"address",
"address",
"uint256",
"uint64",
"uint64",
"uint64"
],
[
"0xdad9d86885d217b92a47370e1e785897dd09a4f3", /// User's wallet address,
"0xdad9d86885d217b92a47370e1e785897dd09a4f3", /// User's wallet address,
"0x7d43aabc515c356145049227cee54b608342c0ad", /// Wrap token address/ ERC20 token address
"10000000000", /// Send amount in String
"5", /// Destination chain id
"1638862397751", /// Nonce
"4002", /// Source chain id
],
)

Response

Since this function is an Ethereum on-chain transaction, the response is the corresponding transaction response.