The ThirdwebSDK
is the entry point to all functionality of the Python SDK.
You initialize the SDK on your desired chain and use the instance to access the different methods and properties of the SDK.
Usage
The SDK can be initialized in either read-only mode or read-write mode.
- Read-only mode: Define the chain you want to use.
- Read-write mode: Define the chain you want to use, and provide a
private key.
If you are using one of our default chains
, provide the name of the chain as a string
.
For non-default chains, see configuring chains or custom chains.
View default chains
- Ethereum:
"ethereum"
- Goerli:
"goerli"
- Rinkeby:
"rinkeby"
- Polygon:
"polygon"
- Mumbai:
"mumbai"
- Arbitrum One:
"arbitrum"
- Fantom Opera:
"fantom"
- Localhost:
"localhost"
Using this method, you can only read data from the blockchain.
Initialize the thirdweb SDK.
from thirdweb import ThirdwebSDK
sdk = ThirdwebSDK("mumbai", options=SDKOptions(secret_key=SECRET_KEY))
Configuration
provider
The web3 provider instance to use for getting on-chain data. Must be of type str
.
signer (optional)
A LocalAccount
object representing the signer to use for sending transactions
options (optional)
optional SDK configuration options. Must be an object of type SDKOption
class SDKOptions(object):
"""
Optional settings to configure the SDK
:param secret_key: secret key from your thirdweb api key
:param read_only_settings: optional read-only RPC settings
:param gas_settings: gas settings
"""
secret_key: Optional[str] = None
read_only_settings: Optional[ReadOnlySettings] = None
gas_settings: GasSettings = GasSettings()
class ReadOnlySettings(object):
"""
The read-only RPC settings for the SDK.
:param rpc_url: URL of the RPC
:param chain_id: optional chain ID to use for the RPC
"""
rpc_url: str = ""
chain_id: Optional[ChainId] = None
class GasSettings(object):
"""
The gas settings for the SDK.
:param max_price_in_gwei: maximum gas price in gwei, defaults to 300
:param speed: gas speed to use, defaults to "fastest"
"""
max_price_in_gwei: int = 300
speed: GasSpeed = GasSpeed.FASTEST
class GasSpeed(Enum):
STANDARD = "standard"
FAST = "fast"
FASTEST = "fastest"
storage (optional)
The IPFS storage instance, a LocalAccount
object, to use for storing data
Custom EVM Chains
Alternatively, if you want to use your own custom RPC URL to connect to any EVM chain, you can pass in the RPC URL directly as follows:
This will initialize the SDK as read-only.
from thirdweb import ThirdwebSDK
RPC_URL = "https://rpc-mainnet.matic.network"
sdk = ThirdwebSDK(RPC_URL)
gas_settings
The gas settings to use when sending transactions.
max_price_in_gwei
: Maximum gas fee to pay for a transaction. Defaults to 300
.speed
: The priority level to set for a transaction.
Either "STANDARD", "FAST", or "FASTEST". Defaults to FASTEST
.
from thirdweb import ThirdwebSDK
from thirdweb.types.sdk import SDKOptions, GasSettings, GasSpeed
options = SDKOptions(gas_settings = GasSettings(speed = GasSpeed.STANDARD))
sdk = ThirdwebSDK(options)
get_contract
Returns a custom contract SDK instance
address = "0x..."
contract = sdk.get_contract(address)
Configuration
address
The address of the custom contract. Must be of type str
Return Value
A CustomContract
object representing the custom contract SDK instance
class CustomContract(BaseContract[Any]):
def __init__(
self,
provider: Web3,
address: str,
abi: str,
storage: IpfsStorage,
signer: Optional[LocalAccount] = None,
options: SDKOptions = SDKOptions(),
):
get_contract_from_abi
Returns a custom contract SDK instance given the contract ABI
address = "0x..."
abi = "my_abi_here"
contract = sdk.get_contract_from_abi(address, abi)
Configuration
address
The address of the custom contract. Must be of type str
.
abi
The abi of the custom contract. Must be of type str
.
Return Value
A CustomContract
object representing the custom contract SDK instance
class CustomContract(BaseContract[Any]):
def __init__(
self,
provider: Web3,
address: str,
abi: str,
storage: IpfsStorage,
signer: Optional[LocalAccount] = None,
options: SDKOptions = SDKOptions(),
):
update_provider
Update the provider instance used by the SDK.
provider = "goerli"
sdk.update_provider(provider)
Configuration
provider
The web3 provider instance to use for getting on-chain data. Must be of type str
and be one of the default chains.
update_signer
Update the signer instance used by the SDK.
sdk.update_signer(signer)
Configuration
signer
The new signer to use for sending transactions. Must be of type LocalAccount
.
Prebuilt Contracts
Deploy any of our prebuilt contracts using the Python SDK:
NFT Collection
get_nft_collection
Returns an NFT Collection contract SDK instance
nft_collection_contract = sdk.get_nft_collection(address)
address
The address of the NFT Collection contract
Return Value
The NFT Collection contract SDK instance.
Edition
get_edition
Returns an Edition contract SDK instance
edition_contract = sdk.get_edition(address)
address
The address of the Edition contract
Return Value
The Edition contract SDK instance.
Token
get_token
Returns a Token contract SDK instance
token_contract = sdk.get_token(address)
address
The address of the Token contract
Return Value
The Token contract SDK instance.
Marketplace
get_marketplace
Returns a Marketplace contract SDK instance
marketplace_contract = sdk.get_marketplace(address)
address
The address of the Marketplace contract
Return Value
The Marketplace contract SDK instance.
NFT Drop
get_nft_drop
Returns an NFT Drop contract SDK instance
nft_drop_contract = sdk.get_nft_drop(address)
address
The address of the NFT Drop contract
Return Value
The NFT Drop contract SDK instance.
Edition Drop
get_edition_drop
Returns an Edition Drop contract SDK instance
edition_drop_contract = sdk.get_edition_drop(address)
address
The address of the Edition Drop contract
Return Value
The Edition Drop contract SDK instance.
Multiwrap
get_edition
Returns an Multiwrap contract SDK instance
multiwrap_contract = sdk.get_multiwrap(address)
address
The address of the Multiwrap contract
Return Value
The Multiwrap contract SDK instance.