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", {
clientId: "YOUR_CLIENT_ID", // Use client id if using on the client side, get it from dashboard settings
secretKey: "YOUR_SECRET_KEY", // Use secret key if using on the server, get it from dashboard settings
});

Configuration

Client ID or Secret Key(required)

To use the Typescript SDK, you need to obtain either the clientId or secretKey from an API key which you can obtain from the Dashboard. You can instatiate the SDK in two ways:

  • Client-side: Use the SDK in the browser or mobile app. In this instance, you would use the clientId prop.
  • Server-side: Use the SDK in a server environment. In this instance, you would use the secretKey prop.

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",
{
clientId: "YOUR_CLIENT_ID", // Use client id if using on the client side, get it from dashboard settings
secretKey: "YOUR_SECRET_KEY", // Use secret key if using on the server, get it from dashboard settings
},
);

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.
);