# @thirdweb-dev/sdk

> The main thirdweb SDK.

Latest version **4.0.99** (published 2024-06-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @thirdweb-dev/sdk
pnpm add @thirdweb-dev/sdk
yarn add @thirdweb-dev/sdk
bun add @thirdweb-dev/sdk
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; large bundle.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.99 |
| Published | 2024-06-18 |
| First published | 2022-02-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 19 |
| Unpacked size | 10.4 MB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 639 |
| Author | thirdweb eng |
| Maintainers | thirdweb-bot, furqantw, yash90, jakeloo, joaquim-verges, jnsdls |

## Links

- npm: https://www.npmjs.com/package/@thirdweb-dev/sdk
- Repository: https://github.com/thirdweb-dev/js.git#main
- Homepage: https://github.com/thirdweb-dev/js/tree/main#readme
- Issues: https://github.com/thirdweb-dev/js/issues
- npm.io page: https://npm.io/package/@thirdweb-dev/sdk

## Dependencies (19)

- [zod](https://npm.io/package/zod.md) ^3.22.4
- [bs58](https://npm.io/package/bs58.md) ^5.0.0
- [uuid](https://npm.io/package/uuid.md) ^9.0.1
- [yaml](https://npm.io/package/yaml.md) ^2.4.1
- [bn.js](https://npm.io/package/bn.js.md) 5.2.1
- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [abitype](https://npm.io/package/abitype.md) 1.0.0
- [thirdweb](https://npm.io/package/thirdweb.md) 5.29.6
- [tweetnacl](https://npm.io/package/tweetnacl.md) ^1.0.3
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^5.0.1
- [tiny-invariant](https://npm.io/package/tiny-invariant.md) ^1.3.3
- [fast-deep-equal](https://npm.io/package/fast-deep-equal.md) ^3.1.3
- [@eth-optimism/sdk](https://npm.io/package/@eth-optimism/sdk.md) 3.3.2
- [@thirdweb-dev/chains](https://npm.io/package/@thirdweb-dev/chains.md) 0.1.120
- [@thirdweb-dev/crypto](https://npm.io/package/@thirdweb-dev/crypto.md) 0.2.6
- [@thirdweb-dev/storage](https://npm.io/package/@thirdweb-dev/storage.md) 2.0.15
- [@thirdweb-dev/merkletree](https://npm.io/package/@thirdweb-dev/merkletree.md) 0.2.6
- [@thirdweb-dev/contracts-js](https://npm.io/package/@thirdweb-dev/contracts-js.md) 1.3.23
- [@thirdweb-dev/generated-abis](https://npm.io/package/@thirdweb-dev/generated-abis.md) 0.0.2

## Recent versions

- 4.0.99 (latest) — 2024-06-18
- 4.0.0-next-7abd58d84-20240917032316 (next) — 2024-09-17
- 4.0.100-nightly-d974db533a5a2e241df7743b201d730c90cda0d7-20240627000603 (nightly) — 2024-06-27
- 0.0.0-dev-def1279ee72fa305354f0951884d936249ebf65a-20240618182413 (dev) — 2024-06-18
- 4.0.37-alpha-4a03d61dd0a5216a1217ff078ab762920d25d6d0-20240402021246 (alpha) — 2024-04-02
- 4.0.48-beta-e0fc73388320fc7bb178beddd489aef9853a280c-20240320050555 (beta) — 2024-03-20
- 2.5.2 (v2) — 2022-10-29
- 2.5.0 (legacy) — 2022-10-22
- 3.0.0-pr19-9e6a4dc (pr19) — 2022-09-03
- 4.0.100-nightly-7be7b6ff84b83ee587d369f4e8da5a2d9f80b8c2-20240626221701 — 2024-06-26
- 4.0.100-nightly-3979ff0238ae9b3a0a216e6c2d562eb7206a9fe8-20240626085813 — 2024-06-26
- 4.0.100-nightly-e7434891354f351d2a399daebdddae9cf1fc817b-20240623000619 — 2024-06-23
- 4.0.100-nightly-fe775166d40fdd50faaa8d6da3fcd624f9a450ed-20240622000610 — 2024-06-22
- 4.0.100-nightly-d320777eea5404f596aa39b2b49b5165d3e1959a-20240621000551 — 2024-06-21
- 4.0.100-nightly-fab5cd43bed972b0a3f70f0f39a790349672ba72-20240620192731 — 2024-06-20
- … 3954 more at https://npm.io/package/@thirdweb-dev/sdk/versions

## README

<p align="center">
<br />
<a href="https://thirdweb.com"><img src="https://github.com/thirdweb-dev/js/blob/main/legacy_packages/sdk/logo.svg?raw=true" width="200" alt=""/></a>
<br />
</p>
<h1 align="center">thirdweb TypeScript SDK</h1>
<p align="center">
<a href="https://www.npmjs.com/package/@thirdweb-dev/sdk"><img src="https://img.shields.io/npm/v/@thirdweb-dev/sdk?color=red&label=npm&logo=npm" alt="npm version"/></a>
<a href="https://github.com/thirdweb-dev/js/actions/workflows/build-test-lint.yml"><img alt="Build Status" src="https://github.com/thirdweb-dev/js/actions/workflows/build-test-lint.yml/badge.svg"/></a>
<a href="https://discord.gg/thirdweb"><img alt="Join our Discord!" src="https://img.shields.io/discord/834227967404146718.svg?color=7289da&label=discord&logo=discord&style=flat"/></a>

</p>
<p align="center"><strong>Best in class Web3 SDK for Browser, Node and Mobile apps</strong></p>
<br />

## Installation

Install the latest version of the SDK with `npm`:

```shell
npm install @thirdweb-dev/sdk ethers@5
```

or with `yarn`:

```shell
yarn add @thirdweb-dev/sdk ethers@5
```

## Quick start

### 1. Deploy & customize your contracts

- Using your [thirdweb dashboard](https://thirdweb.com/dashboard) (recommended)
- Using the [SDK directly](https://portal.thirdweb.com/typescript/sdk.contractdeployer)
- Using the [thirdweb CLI](https://portal.thirdweb.com/deploy)

### 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.

```javascript title="my_script.js"
// my_script.js
import { ThirdwebSDK } from "@thirdweb-dev/sdk";

// instantiate the SDK in read-only mode (our example is running on `polygon` here)
// all major chains and testnets are supported (e.g. `mainnet`, 'optimism`, 'arbitrum', 'polygon', `goerli`, 'mumbai', etc.)
const sdk = new ThirdwebSDK("polygon");

// access your deployed contracts
const contract = await sdk.getContract("0x...");

// Read data using direct calls to your contract
const myData = await contract.call("myFunction");

// Or Using the extensions API matching to your contract extensions
const allNFTs = await contract.erc721.getAll();
const tokenSupply = await contract.erc20.totalSupply();
```

You can execute this code as a node script by executing:

```shell
node my_script.js
```

Note that you can also access any deployed contract using its ABI, using `sdk.getContractFromAbi(address, abi)` and get the same functionality. For contracts deployed via thirdweb, we handle the ABI for you.

### 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:

```javascript title="my_script.js"
// my_script.js
import { ThirdwebSDK } from "@thirdweb-dev/sdk";

// Learn more about securely accessing your private key: https://portal.thirdweb.com/web3-sdk/set-up-the-sdk/securing-your-private-key
const privateKey = "<your-private-key-here>";
// instantiate the SDK based on your private key, with the desired chain to connect to
const sdk = ThirdwebSDK.fromPrivateKey(privateKey, "polygon");

// deploy existing contracts, or your own using the thirdweb CLI
const deployedAddress = sdk.deployer.deployNFTCollection({
  name: "My NFT Collection",
  primary_sale_recipient: "0x...",
});

// access your deployed contracts
const contract = await sdk.getContract(deployedAddress);

// Execute any of your functions on your contracts from the connected wallet
await contract.call("myFunction", arg1, arg2);

// Or execute transactions using the extensions API
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
});
```

You can execute this code as a node script by executing:

```shell
node my_script.js
```

#### 3.2 Frontend usage

For frontend applications, head over to our [React Github repo](https://github.com/thirdweb-dev/js/tree/main/legacy_packages/react) 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](https://github.com/thirdweb-example).

## API Reference & code examples

- [Step by step guides and recipes](https://portal.thirdweb.com)
- [Full Api Reference and code examples](https://docs.thirdweb.com/typescript)

## Build from source

To build the project:

```shell
yarn install
yarn build
```

After building, to run the tests (requires a local hardhat node running):

```shell
yarn test:all
```

OR

If you have make and docker installed you can simply run

```shell
make test
```

## Get in touch

- [Discord](https://discord.gg/thirdweb)
- [Twitter](https://twitter.com/thirdweb_/)

---
_Source: https://npm.io/package/@thirdweb-dev/sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
