Skip to main content

Securely Storing Your Private Key

If you need to perform actions directly from your wallet in a server-side or scripting environment, instantiate the SDK using your wallet's private key.

Your wallet's private key grants full control of your wallet, for this reason, having your private key written in plain text or environment variables is a security risk; we recommend using a secret management service to store it securely.

There are many services available to store secret values:

Using Google Cloud Secret Manager

This section shows you how to use Google Cloud Secret Manager, as an example.

From the Google Cloud Console, enable the Secret Manager API in your project, and create a new secret containing your wallet's private key as the value. Follow this guide to create a service account with the Secret Manager Secret Accessor role and export the key as a JSON file.

danger

Ensure you secure the values in the .json file securely; such as using environment variables.

Create and retrieve your private key from a secret value by following this guide.

Use the accessSecretVersion function from the guide to instantiate the SDK with your private key on the server-side.

import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { Polygon } from "@thirdweb-dev/chains"; // configure this to your network

const sdk = ThirdwebSDK.fromPrivateKey(
accessSecretVersion(), // Your wallet private key
Polygon,
);