Backend & Scripting Applications
Back-end applications are suitable for when you need to perform actions from your wallet or simply need to read data, rather than connecting to your user's wallets.
You can build back-end applications or scripts by using any of our SDKs:
- Javascript
- Python
- Go
npm install @thirdweb-dev/sdk ethers
pip install thirdweb-sdk
go get github.com/thirdweb-dev/go-sdk
There are multiple different ways you can instantiate the SDK and use it, that vary depending on what you need to do.
From a Private key
This instantiates the SDK with write-permissions directly from a wallet's private key.
If you expose your private key, anyone can access your wallet's funds. Please proceed carefully.
Ensure you store and access your private key securely.
- Check if you need to use a private key for your application.
- Never directly expose your private key in your source code.
- Never commit any file that may contain your private key to your source control.
- Never use a private key for a frontend (website/dapp) application.
If you are unsure how to securely store and access your private key, please do not proceed.
- Javascript
- Python
- Go
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = ThirdwebSDK.fromPrivateKey(
// Learn more about securely accessing your private key: https://portal.thirdweb.com/web3-sdk/set-up-the-sdk/securing-your-private-key
"<your-private-key-here>",
"mumbai", // configure this to your network
);
from thirdweb import ThirdwebSDK
from thirdweb.types.nft import NFTMetadataInput
import os
# Learn more about securely accessing your private key: https://portal.thirdweb.com/web3-sdk/set-up-the-sdk/securing-your-private-key
PRIVATE_KEY = "<your-private-key-here>"
# Now you can create a new instance of the SDK with your private key
sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, "mumbai")
package main
import (
"fmt"
"encoding/json"
"github.com/thirdweb-dev/go-sdk/thirdweb"
)
func main() {
// Learn more about securely accessing your private key: https://portal.thirdweb.com/web3-sdk/set-up-the-sdk/securing-your-private-key
privateKey := "..."
// Instantiate the SDK with your privateKey
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
if err != nil {
panic(err)
}
}
From a Signer / Provider
You can use a signer such as one from an Ethers Web3Provider to instantiate the SDK.
- Javascript
- Python
- Go
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
// Instantiate the ThirdwebSDK using the signer
// the signer variable comes from a signer you have previously created,
// or from our React SDK's useSigner hook.
const sdk = ThirdwebSDK.fromSigner(signer, "mumbai");
from thirdweb import ThirdwebSDK
# Now you can create a new instance of the SDK with the signer.
# Here, the signer variable comes from a signer you have previously created.
sdk = ThirdwebSDK("mumbai", signer)
// NOTE: Go does not support instantiating the SDK from a signer.
package main
import (
"fmt"
"encoding/json"
"github.com/thirdweb-dev/go-sdk/thirdweb"
)
func main() {
// Get your private key securely (preferably from an environment variable)
privateKey := "..."
// Instantiate the SDK with your privateKey
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
if err != nil {
panic(err)
}
}
Read-only Connection
- Javascript
- Python
- Go
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
// Create a READ-ONLY instance of the ThirdwebSDK on the Mumbai network
const sdk = new ThirdwebSDK("mumbai"); // configure this to your network
from thirdweb import ThirdwebSDK
# You can create new READ-ONLY instance of the SDK to use by just passing in a network name
sdk = ThirdwebSDK("mumbai")
package main
import (
"fmt"
"github.com/thirdweb-dev/go-sdk/thirdweb"
)
func main() {
// Creates a new READ-ONLY instance of the SDK to get read-only data for your contracts, you can pass:
// - a chain name (mainnet, goerli, polygon, mumbai, avalanche, fantom)
// - a custom RPC URL
sdk, err := thirdweb.NewThirdwebSDK("mumbai", nil)
if err != nil {
panic(err)
}
// Now we can interact with the SDK, like displaying the connected chain ID
chainId, err := sdk.GetChainID()
if err != nil {
panic(err)
}
fmt.Println("New SDK instance create on chain", chainId)
}