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
  • View or fork now on CodeSandbox
  • Bootstrap a React App
  • Install Transaction Kit
  • Create a Web3 Provider
  • Wrap your <App /> with <EtherspotTransactionKit />
  • Build a UI
  • Congratulations!

Was this helpful?

  1. Transaction Kit

Quick Start

Get started quickly with TransactionKit

PreviousCode SandboxesNextReact Hooks

Last updated 2 years ago

Was this helpful?

View or fork now on CodeSandbox

The Quick Start below is available as a well documented, fully functioning live example on CodeSandbox.

Otherwise, please keep following the instructions below.

Bootstrap a React App

Let's keep it simple and use create-react-app here. Run the following command in a directory of your choice:

npx create-react-app txkit-quickstart

The above command will install and bootstrap a basic React App into a directory called txkit-quickstart. Once the installation has finished, change directory into your newly bootstrapped React app by typing:

cd txkit-quickstart

Install Transaction Kit

Next, install TransactionKit and Ethers

npm i @etherspot/transaction-kit [email protected]
// or
yarn add @etherspot/transaction-kit [email protected]

Create a Web3 Provider

A Web3 provider ultimately provides access to blockchain account, also known as a wallet.

For the Quick Start example, we will randomly generate a wallet.

index.tsx / index.js
import { EtherspotTransactionKit } from '@etherspot/transaction-kit';
import { ethers } from 'ethers';

// ...

const randomWallet = ethers.Wallet.createRandom();
const providerWallet = new ethers.Wallet(randomWallet.privateKey);

Wrap your <App /> with <EtherspotTransactionKit />

Wrap your React <App /> tag in the <EtherspotTransactionKit /> tag. This will turbocharge your React app with the power of Etherspot and everything that the platform can offer.

index.tsx / index.js
root.render(
  <React.StrictMode>
    <EtherspotTransactionKit
      provider={providerWallet} /* The random wallet we created above */
      chainId={80001} /* Polygon Testnet - Mumbai */
    >
      <App />
    </EtherspotTransactionKit>
  </React.StrictMode>
);

Get yourself some Polygon Mumbai Testnet funds

In order to execute a transaction, you need to fund your randomly created account with Test MATIC, the native token on Polygon Mumbai. You can get some for free below.

Build a UI

We're going to start with a simple example - sending some MATIC to another address. TransactionKit makes this really, really easy. Have a look at the code below.

import {
  EtherspotBatches,
  EtherspotBatch,
  EtherspotTransaction,
  useEtherspotUi,
  useEtherspotAddresses,
} from '@etherspot/transaction-kit';

// In your main function body...

const { estimate, send } = useEtherspotTransactions();
const etherspotAddresses = useEtherspotAddresses();

const [address, setAddress] = useState('0x271Ae6E03257264F0F7cb03506b12A027Ec53B31');
const [amount, setAmount] = useState('0.001');

// In your rendering function...

<EtherspotBatches>
  <EtherspotBatch>
    <EtherspotTransaction
      to={address}
      value={amount}
    >
      {/* The following returns a list of Blockchain
          addresses that are ready to use */}
      {
        etherspotAddresses.map((etherspotAddressObject) =>
          <div>
            <p>Blockchain Name: {etherspotAddressObject.chainName}</p>
            <p>Blockchain ID:{etherspotAddressObject.chainId}</p>
            <p>Address: {etherspotAddressObject.address}</p>
          </div>
        )
      }
      <input
        type="text"
        value={address}
        onChange={(event) => setAddress(event.target.value)}
      />
      <input
        type="text"
        value={amount}
        onChange={(event) => setAmount(event.target.value)}
      />
      <hr />
      <button onClick={() => estimate()}>Estimate</button>
      <button onClick={() => send()}>Send</button>
    </EtherspotTransaction>
  </EtherspotBatch>
</EtherspotBatches>

You must always estimate before sending

Estimating first performs important transaction cost calculations that are required before sending.

You've just sent your first transaction using TransactionKit! Wasn't that easy? Why not have a look around the TransactionKit documentation to see what else you can do with TransactionKit!

Once sent - you can check the transaction on the Polygon Mumbai blockchain explorer .

Congratulations!

🎉
👉
📖
View or fork the Send Native Asset CodeSandbox
View all our CodeSandbox examples
https://faucet.polygon.technology
here