Sodium Documentation
  • Overview
    • Security Architecture
    • Key Management
    • Sodium Network
    • Compatible With ERC-4337
    • Trusted Execution Environment
    • Roadmap
  • SDK
    • Connect Wallet
    • Sign Messages
    • Transfer
    • Wallet Connector
      • web3.js
      • web3-react-v8
      • viem
      • wagmi
      • rainbowkit
      • web3-modal-v2
  • Terms
    • Terms of Use for Sodium Wallet
    • Privacy Policy
    • Sodium List of Restricted Regions
Powered by GitBook
On this page
  1. SDK

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.

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

// Destination address for the second transfer
const recipientAddress2 = "";
// Transfer amount for the second transfer
const amount2 = "";

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

// Encode two different ERC-20 token transfers
const data1 = erc20Interface.encodeFunctionData(
  'transfer', [recipient1Address, amount1]
)
const data2 = erc20Interface.encodeFunctionData(
  'transfer', [recipient2Address, amount2]
)

const transaction1 = {
  to: erc20ContractAddress,
  data: data1
}

const transaction2 = {
  to: erc20ContractAddress,
  data: data2
}

// Send a multiple transactions as a single bundle which is executed as one transaction on chain.
const signer = wallet.getSigner()
const txnResponse = await signer.sendTransactionBatch([transaction1, transaction2])
console.log(txnResponse)

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

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

PreviousSign MessagesNextWallet Connector

Last updated 2 years ago