thirdweb TypeScript SDK
Best in class Web3 SDK for Browser, Node and Mobile apps
Installation
Install the latest version of the SDK with npm
:
npm install @thirdweb-dev/sdk ethers
or with yarn
:
yarn add @thirdweb-dev/sdk ethers
Quick start
1. Deploy & customize your contracts
- Using your thirdweb dashboard (recommended)
- Using the SDK directly (for advanced use cases)
2. Reading data from your contracts
The quickest way to get started is to use the SDK as read only (no transactions).
This will allow you to query data from any contract with no additional setup.
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("polygon");
const nftDrop = sdk.getNFTDrop("0x...");
const marketplace = sdk.getMarketplace("0x...");
const claimedNFTs = await nftDrop.getAllClaimed();
const listings = await marketplace.getActiveListings();
You can execute this code as a node script by executing:
node my_script.js
3. Executing transactions on your contracts
In order to execute transactions on your contract, the SDK needs to know which wallet is executing those transactions.
This can be done two ways:
- Using your own private key (typically used in the backend or scripts)
- By connecting to a user wallet (typically used in the frontend)
3.1 Backend / Scripting usage
Here's how to provide your own private key to the SDK to perform transactions with your account from scripts or from a node.js backend:
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const privateKey = process.env.PRIVATE_KEY;
const sdk = ThirdwebSDK.fromPrivateKey(privateKey, "polygon");
const deployedAddress = sdk.deployer.deployNFTCollection({
name: "My NFT Collection",
primary_sale_recipient: "0x...",
});
const nftCollection = sdk.getNFTCollection(deployedAddress);
const walletAddress = "0x...";
await nftCollection.mintTo(walletAddress, {
name: "Cool NFT",
description: "Minted NFT from code!",
image: fs.readFileSync("path/to/image.png"),
});
You can execute this code as a node script by executing:
node my_script.js
3.2 Frontend usage
For frontend applications, head over to our React Github repo which shows you how to connect to a user's wallet like Metamask, and automatically instantiate the thirdweb SDK for you.
Easiest way to get started on the frontend is using one of our templates in the thirdweb examples repo.
API Reference & code examples
Build from source
To build the project:
yarn install
yarn build
After building, to run the tests (requires a local hardhat node running):
yarn test:all
OR
If you have make and docker installed you can simply run
make test
Get in touch