Docs

Transactions

Transactions are the primary way to read and write to the blockchain.

Creating a transaction

import { prepareTransaction, parseEther } from "thirdweb";
const transaction = prepareTransaction({
// the account that will be the receiver
to: "0x456...",
// the value is the amount of ether you want to send with the transaction
value: parseEther("1"),
});

Reading contract state

You can read contract state directly using the readContract function.

import { readContract } from "thirdweb";
const balance = await readContract({
// ^? const balance: bigint
contract: contract,
method: "function balanceOf(address) view returns (uint256)",
params: ["0x123..."],
});

Writing contract state

There are 4 ways to prepare a contract call, all of these return the same transaction object.

Acting on a prepared transaction

Transactions have a variety of actions that can be called on them, in all cases this is done by calling the action on the transaction object itself.