Skip to main content

ThirdwebSDK.fromPrivateKey

Instantiate the ThirdwebSDK in read-write mode using a wallets private key.

All transactions made with this instance of the SDK will be signed using the private key.

Usage

Provide the private key as a string and the chain you want to use.

import { ThirdwebSDK } from "@thirdweb-dev/sdk";

const sdk = ThirdwebSDK.fromPrivateKey(process.env.PRIVATE_KEY, "ethereum");

Configuration

privateKey

The private key of the wallet you want to use to initiate transactions with.

Sensitive Value

The private key grants custody over the funds associated with your account.

Losing or leaking your private key will result in the loss of your funds.

Please proceed carefully, and consider using a secret manager instead.

import { ThirdwebSDK } from "@thirdweb-dev/sdk";

const sdk = ThirdwebSDK.fromPrivateKey(
"your-private-key-here", // DANGER: This is a sensitive value that should be stored securely.
"ethereum",
);

chain

The chain you want to use. See configuring chain on the ThirdwebSDK for more information.

import { ThirdwebSDK } from "@thirdweb-dev/sdk";

const sdk = ThirdwebSDK.fromPrivateKey(
process.env.PRIVATE_KEY, // DANGER: This is a sensitive value that should be stored securely.
"ethereum", // Can be a string, a Chain object from @thirdweb-dev/chains, or a custom chain.
);