Build your first web3 app

Build a small web app in vanilla JavaScript that uses the Tatum SDK to fetch and display the ETH balance of any Ethereum address.

This guide shows you how to build a small web app in vanilla JavaScript that uses the Tatum JavaScript SDK to retrieve and display the ETH balance of an Ethereum address. You need an API key from the Tatum Dashboard.

Steps

  1. Create a new Node.js project and install the Tatum SDK package.
  2. Build an HTML page with an input field for the Ethereum address and a button that starts the balance lookup.
  3. Write JavaScript that calls the Tatum SDK's address.getBalance() method for the entered address.
  4. Start the app with the Parcel development server.

Create a new project

The first step is to create a new project by running npm init in the terminal. This will prompt you to enter some basic information about the project, such as the project name and version.

npm init

Install Tatum SDK

To install SDK, simply run the following command in your terminal or command prompt.
This will install the Tatum SDK package and its dependencies:

npm install @tatumio/tatum
yarn add @tatumio/tatum
pnpm install @tatumio/tatum
bun install @tatumio/tatum

Create an index.html file

After installing the Tatum SDK, create an index.html file in your project directory. It contains the input field, the button and a div element for displaying the balance. The script tag loads app.js, which you create in the next step.

<html>
<head>
    <meta charset="utf-8"/>
    <title>My First Tatum DApp</title>
    <script type="module" src="./app.js"></script>
</head>
<body>
    <h1>Get Eth balance with Tatum!</h1>
    <input type="text" id="address" placeholder="Enter wallet address" />
    <button id="get-balance">Get Balance</button>
    <div id="balance"></div>
</body>
</html>

Create an app.js file

Next, create an app.js file in your project directory. It adds a click listener to the button and uses the Tatum SDK to retrieve the balance of the entered Ethereum address. Replace {YOUR_API_KEY} with your API key.

import { TatumSDK, Network } from '@tatumio/tatum'

const button = document.getElementById('get-balance');
const addressInput = document.getElementById('address');
const balanceDiv = document.getElementById('balance');

button.addEventListener('click', async () => {
    const tatum = await TatumSDK.init({ network: Network.ETHEREUM, apiKey: '{YOUR_API_KEY}' });
    const balance = await tatum.address.getBalance({
        addresses: [addressInput.value],
    });
    const balanceData = balance.data.filter(asset => asset.asset === 'ETH')[0];
    balanceDiv.textContent = `${balanceData.balance} ${balanceData.asset}`;
    await tatum.destroy();
});

When you click the button, the code initializes the Tatum SDK for the Ethereum network, calls tatum.address.getBalance with an array that contains the entered address, and displays the ETH balance in the balance div. tatum.destroy() then stops the SDK's background jobs.

🚧

This example puts your API key in code that runs in the browser, where anyone who opens the page can read it. Use it for local testing only; in production, call Tatum from your backend.

📘

Each TatumSDK instance is tied to one blockchain network. All supported networks are listed in src/dto/Network.ts on GitHub.

Update package.json

To start the app from the index.html file, set the source property in your package.json file. If npm init added a main field, remove it: Parcel treats main as a library build target.

{
  "name": "my-first-tatum-dapp",
  "version": "1.0.0",
  "source": "./index.html",
  "license": "MIT",
  "dependencies": {
    "@tatumio/tatum": "^4.0.0"
  }
}

Start server

The last step is to start the server using Parcel. You can run npx parcel in the terminal to start the server, and your app will be available at http://localhost:1234.

npx parcel

You can enter a wallet address and click the "Get Balance" button to retrieve the balance for that Ethereum address. The balance will be displayed below the button.

📘

Parcel bundles and serves your app automatically.

Next steps

You have built a web app that reads the ETH balance of an Ethereum address with the Tatum SDK. To continue:


Did this page help you?