ThirdwebSDK
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
# You can create a new instance of the SDK to use by just passing in a network name
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
# Set your RPC_URL
RPC_URL = "https://rpc-mainnet.matic.network"
# And now you can instantiate the SDK with it
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 to300
.speed
: The priority level to set for a transaction. Either "STANDARD", "FAST", or "FASTEST". Defaults toFASTEST
.
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: