Getting Started

You can get started by creating a new project or adding thirdweb to an existing project.

Existing Projects

Install the thirdweb package in your project

npx thirdweb install

New Projects

Create a new project using the thirdweb CLI

npx thirdweb create app

You can create Node.js, Express and other types of projects using the CLI.

Initialize the SDK

The SDK can be instantiated as read only by passing a chain or read/write by passing a chain and a wallet.

Read only SDK

This can be used for reading data from the blockchain and does not require a wallet.

import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("sepolia", {
secretKey: "YOUR_SECRET_KEY",
});

Read/Write SDK

This can be used for reading and writing data to the blockchain and requires a connected wallet.

Can be instantiated from different wallet types:

Wallet typeFunctionNotes
Wallet (recommended)ThirdwebSDK.fromWallet()This function is async, needs to be awaited
ethers.js SignerThirdwebSDK.fromSigner()Use this when combining the SDK with other libraries
Private KeyThirdwebSDK.fromPrivateKey()This should only be used on the server side. Never commit or expose your private key on the client

Here's a typical example of instantiating the SDK from a private key:

import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = ThirdwebSDK.fromPrivateKey(
process.env.PRIVATE_KEY,
"polygon",
{
secretKey: "YOUR_SECRET_KEY",
},
);

Examples templates: Node.js • Express

Using the SDK

With the SDK instantiated, you can now deploy smart contracts, interact with them, and much more.

To connect to your contract, use the SDK's getContract method and the call method to read/write data.

Functions are called automatically from the wallet you instantiated the SDK with.

// Connect to your smart contract using the contract address
const contract = await sdk.getContract("0x...");
// Call a function on your smart contract using the function name
const name = await contract.call("myFunctionName", [arg1, arg2]);
// Or Using the extensions API matching your contract extensions
const allNFTs = await contract.erc721.getAll();
const tokenSupply = await contract.erc20.totalSupply();
// deploy contracts from the connected wallet
const deployedAddress = sdk.deployer.deployNFTCollection({
name: "My NFT Collection",
primary_sale_recipient: "0x...",
});
// execute transactions on behalf of the connected wallet
await contract.erc721.mint({
name: "Cool NFT",
description: "Minted NFT from code!",
image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
});