Transfer

The Sodium Wallet is compatible with various methods for sending transactions

Simple Transfer

// send 1eth to 0x812D3C67d283F3b9d1F1E347DF37F0C7fbD6a0B0
const transaction = {
  to: "0x812D3C67d283F3b9d1F1E347DF37F0C7fbD6a0B0",
  value: "1000000000000000000"
}

const signer = wallet.getSigner()
const txnResponse = await signer.sendTransaction(transaction)
console.log(txnResponse)

// wait for the transaction to be mined
await txnResponse.wait()

It creates a transaction object with the destination address and amount in wei, gets a Signer from the wallet, and calls sendTransaction() to send the signed transaction.

Transfer ERC20

// ERC20 contract address to send from
const erc20ContractAddress = "";
// Destination address for the transfer
const recipientAddress = "";
// Transfer amount
const amount = "";

const erc20Interface = new ethers.utils.Interface([
  'function transfer(address _to, uint256 _value)'
])

// Encode an ERC-20 token transfer to recipient of the specified amount
const data = erc20Interface.encodeFunctionData(
  'transfer', [recipientAddress, amount]
)

const transaction = {
  to: erc20ContractAddress,
  data
}

const signer = wallet.getSigner()
const txnResponse = await signer.sendTransaction(transaction)
console.log(txnResponse)

// wait for the transaction to be mined
await txnResponse.wait()

It encodes an ERC20 transfer call, creates a transaction with the data, and sends the transaction.

Batch Transactions

Sodium Wallet supports batch transactions.

This is useful for scenarios like token approval.

It shows how to send multiple transactions in a single call by passing an array of transactions to sendTransactionBatch(). This allows executing multiple transactions as one on-chain.

In summary:

  • sendTransaction() sends a single ether or ERC20 transaction

  • sendTransactionBatch() sends multiple transactions in a single call

  • encodeFunctionData() encodes an ERC20 transfer call

  • getSigner() obtains a Signer to sign transactions from the wallet

Last updated