Etherspot
These are our V1 docs and will be deprecated soon. Please visit https://etherspot.fyi/introduction to use our new version of the SDK.
  • Welcome to Etherspot
    • Chains, Bridges & DEXes
    • Social Logins
    • Web3 Logins
  • Transaction Kit
    • Introduction
    • Code Sandboxes
    • Quick Start
    • React Hooks
      • useEtherspotAssets()
      • useEtherspotNfts()
      • useEtherspotHistory()
        • getAccountTransactions()
        • getAccountTransaction()
      • useEtherspotTransactions()
        • estimate()
        • send()
      • useEtherspotAddresses()
      • useEtherspotBalances()
    • React Components
      • <EtherspotTransactionKit />
      • <EtherspotBatches />
      • <EtherspotBatch />
      • <EtherspotTransaction />
      • <EtherspotContractTransaction />
      • <EtherspotApprovalTransaction />
      • <EtherspotTokenTransferTransaction />
  • BUIDLER React Component
    • Introduction
    • Installation
    • Integrate React Component
    • Shared Sessions
    • Wallet Connectors
    • Blocks
      • Send
      • Batching Transaction
      • Multicall Transaction
      • Swaps
      • Bridges
      • Custom Contract Interactions
      • Styling
    • Build Your Own Block
      • Cross-chain KLIMA DAO Staking
  • Etherspot SDK Guides
    • Requirements
    • Install Etherspot SDK
    • Bootstrap Etherspot SDK
      • Instantiate Etherspot SDK
    • Events
    • Etherspot Block Explorer
    • Etherspot Playground
    • Social Login using Etherspot SDK
    • Sponsored Transactions
  • Use Cases & Guides
    • Crosschain Streaming
    • Token Swaps
    • Transactions
      • Historical
      • Sending
    • Multi-chain Bridges
      • ERC20 Bridge
      • DAI - xDai Bridge
      • xDai - DAI Bridge
      • Native Token Bridge
    • Custom Contract Interaction
    • Multi-chain Assets
    • Multi-chain Gas Prices
    • Peer-to-Peer Payments
  • Reference
    • Etherspot SDK API Docs
    • Etherspot SDK on Github
    • Etherspot on NPM
    • Etherspot Playground
    • Etherspot Block Explorer
    • Etherspot Architecture
    • EIP-1271
    • Etherspot/Pillar Audit
  • Brand Assets
    • Etherspot Brand Assets
  • Security
    • Security
  • Get in touch
    • ⚒️Discord
    • Twitter
    • Telegram
Powered by GitBook
On this page
  • Getting started
  • Optional: Setting up a notifications subscription
  • Adding your transaction to a batch
  • Estimating your batch
  • Submitting your batch
  • Finished!

Was this helpful?

  1. Use Cases & Guides
  2. Transactions

Sending

Batching and sending transactions using Etherspot

PreviousHistoricalNextMulti-chain Bridges

Last updated 3 years ago

Was this helpful?

Before we continue, please ensure that you have had a look at our Supported Ethereum Chains, followed the steps in and how to . We're assuming that you have completed these steps before going forward.

Getting started

The Etherspot SDK makes it really easy for you to send a transaction on any of our Supported Ethereum Chains. The method call is the same for each chain.

const { account } = sdk.state;

Optional: Setting up a notifications subscription

Next, set up a listener against the SDK's notification subscription method. This will allow us to receive an event when the transaction has been confirmed, or enters any other state for that matter.

sdk
  .notifications$
  .subscribe(console.log);

Adding your transaction to a batch

When using Etherspot to send transactions, we first add the transaction to a "batch". A batch can contain many transactions for a more gas-efficient operation, but in this example - we're just going to add one transaction to the batch. It will behave as if we are just sending a single transaction.

await sdk.batchExecuteAccountTransaction({
  to: '0x0fd7508903376dab743a02743cadfdc2d92fceb8', // Destination Ethereum address
  value: 100, // This value is in wei
  data: null // Optional contract data payload
}).catch(console.error);

Once the above method, batchExecuteAccountTransaction has been executed, the instruction to send 100 wer to the Ethereum address 0x0fd7508903376dab743a02743cadfdc2d92fceb8.has been added into the batch. You can choose to continue adding more transactions to this batch.

Estimating your batch

At this point, your batch is ready to have the gas cost estimated. This gives you, or your users, the opportunity to see how much this transaction may cost on the chain that you have instantiated the SDK on. You can read more about instantiating the Etherspot SDK on different chains here:Supported Ethereum Chains.

const estimationResponse = await sdk
  .estimateGatewayBatch()
  .catch(console.error);
  
console.log('Gas estimated at:', estimationResponse);

If you're happy with the cost, proceed to the next and final step.

Submitting your batch

The final step is to submit your batch, containing your one or more transactions, to the Etherspot gateway. The Etherspot gateway will queue and manage your batch, and endeavour to do everything it can to get your transaction onto your chosen blockchain.

const submissionResponse = await sdk
  .submitGatewayBatch()
  .catch(console.error);

Do not send assets or native tokens from one chain (like xDai) to an address or contract address on another chain (like Polygon), it will not arrive and the transmitted funds will be lost. This requires the use of .

First let's fetch our account object. The state object contains all the essential information for the instantiated SDK when we performed the steps at . You can see what else resides in.the account class .

To see the full SDK reference for the batchExecuteAccountTransaction, click .

If you had previously set up a notification subscription , then this will fire with different events as your batch is queued, processed and eventually sent to the blockchain.

Finished!

🎉
Multi-chain Bridges
Bootstrap Etherspot SDK
here
here
Install Etherspot SDK
Bootstrap Etherspot SDK
here
Transaction Batching with Etherspot