exchange.IO("transfer", ...)
Transfers the chain's native coin (such as ETH or BNB) or an ERC20 token out of the configured wallet.
exchange.IO(k, to, amount)
exchange.IO(k, to, amount, token)Examples
Transfer ETH and USDC, then wait for the transaction to be confirmed on-chain.
javascript
function main() {
var TO = "0xRecipientAddress"
// Transfer 0.05 ETH; use "all" to transfer the full balance
var r = exchange.IO("transfer", TO, "0.05")
if (!r) {
Log("Transfer failed:", GetLastError())
return
}
Log("Sent", r.amount, r.token, "tx:", r.txHash)
// Wait up to 3 minutes for on-chain confirmation
var rc = exchange.IO("receipt", r.txHash, 180000)
if (rc.pending) {
Log("Not on-chain yet")
} else {
Log("Result:", rc.status, "block:", rc.blockNumber, "fee:", rc.fee)
}
// Transfer 10 USDC
var r2 = exchange.IO("transfer", TO, "10", "USDC")
Log(r2 ? r2.txHash : GetLastError())
}Returns
| Type | Description |
object / null value | When the transaction is broadcast successfully, returns |
Arguments
| Name | Type | Required | Description |
k | string | Yes | Always |
to | string | Yes | Recipient address: a 20-byte hexadecimal address that starts with |
amount | string / number | Yes | Amount to transfer, in human-readable units (for example, |
token | string | No | Token to transfer. It can be a token name (such as |
See Also
Uniswap / PancakeSwap Aerodrome / Velodrome KyberSwap 1inch exchange.IO exchange.IO("receipt") exchange.IO("token") exchange.IO("wrap")
Remarks
In the following cases an error is raised before signing and no transaction is sent: an invalid address format, the zero address, a transfer to the wallet itself, an amount of 0, an amount larger than the balance, or a token that cannot be identified.
When the whole native-coin balance is transferred (all) on an EIP-1559 chain, the maximum fee quoted for this transaction is reserved. Because the fee actually charged is lower than the reserve, a very small balance stays in the wallet.
The priority fee (tip) is the larger of the node's suggested value and the median priority fee in recent blocks. This keeps a transaction from staying unconfirmed for a long time when the node suggests 0.
A transfer is a real on-chain transaction and cannot be reversed once sent. Before sending to an exchange deposit address, make sure the exchange accepts deposits on this chain.