ThirdwebSDK.fromWallet
Instantiate the ThirdwebSDK
in read-write mode using a Wallet
object.
The @thirdweb-dev/wallets
package provides a set
of wallets for you to use to instantiate the SDK.
It includes support for secret manager services such as AWS Key Management Service and AWS Secrets Manager.
This is the recommended method to instantiate the SDK in a production environment.
Usage
First, install the @thirdweb-dev/wallets
package:
- npm
- Yarn
- pnpm
npm install @thirdweb-dev/wallets
yarn add @thirdweb-dev/wallets
pnpm add @thirdweb-dev/wallets
Then, you can use the ThirdwebSDK.fromWallet
method to instantiate the SDK.
Below is an example of how to instantiate the SDK with the AWS Key Management Service.
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { AwsKmsWallet } from "@thirdweb-dev/wallets/evm/wallets/aws-kms";
const wallet = new AwsKmsWallet({
region: "us-east-1",
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN,
keyId: process.env.AWS_KEY_ID,
});
const sdk = ThirdwebSDK.fromWallet(wallet, "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.
chain
The chain you want to use. See configuring chain
on the ThirdwebSDK
for more information.
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const wallet = {
// ... Your wallet implementation
};
const sdk = ThirdwebSDK.fromWallet(
wallet,
"ethereum", // Can be a string, a Chain object from @thirdweb-dev/chains, or a custom chain.
{
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
},
);
Using AwsKmsWallet
Use AWS Key Management Service to instantiate the SDK.
The value stored in your secret value should be your wallet’s private key.
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { AwsKmsWallet } from "@thirdweb-dev/wallets/evm/wallets/aws-kms";
const wallet = new AwsKmsWallet({
region: "us-east-1", // Region where your secret is stored
accessKeyId: process.env.AWS_ACCESS_KEY_ID, // Add environment variables to store your AWS credentials
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, // Add environment variables to store your AWS credentials
sessionToken: process.env.AWS_SESSION_TOKEN, // Add environment variables to store your AWS credentials
keyId: process.env.AWS_KEY_ID, // Add environment variables to store your AWS credentials
});
const sdk = ThirdwebSDK.fromWallet(wallet, "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
});
Using AwsSecretsManagerWallet
Use AWS Secrets Manager to instantiate the SDK.
The value stored in your secret value should be your wallet’s private key.
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { AwsSecretsManagerWallet } from "@thirdweb-dev/wallets/evm/wallets/aws-secrets-manager";
const wallet = new AwsSecretsManagerWallet({
secretId: "{{secret-id}}", // ID of the secret value
secretKeyName: "{{secret-key-name}}", // Name of the secret value
awsConfig: {
region: "us-east-1", // Region where your secret is stored
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID, // Add environment variables to store your AWS credentials
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, // Add environment variables to store your AWS credentials
},
},
});
const sdk = ThirdwebSDK.fromWallet(wallet, "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
});