Skip to main content

No project description provided

Project description

Thirdweb Python SDK

The thirdweb SDK for Python. Currently supports Mainnet, Rinkeby, Goerli, Polygon, and Mumbai.

Installation

pip install thirdweb-sdk

Getting Started

To start using this SDK, you just need to pass in a provider configuration.

Instantiating the SDK

Once you have all the necessary dependencies, you can follow the following setup steps to get started with the SDK read-only functions:

from thirdweb import ThirdwebSDK
from web3 import Web3

# Add your own RPC URL here or use a public one
RPC_URL = "https://rpc-mumbai.maticvigil.com"

# Instantiate a new provider to pass into the SDK
provider = Web3(Web3.HTTPProvider(RPC_URL))

# Finally, you can create a new instance of the SDK to use
sdk = ThirdwebSDK(provider)

Working With Contracts

Once you instantiate the SDK, you can use it to access your thirdweb contracts. You can use the SDK's contract getter functions like get_token, get_edition, get_nft_collection, and get_marketplace to get the respective SDK contract instances. To use an NFT Collection contract for example, you can do the following.

# Add your NFT Collection contract address here
NFT_COLLECTION_ADDRESS = "0x.."

# And you can instantiate your contract with just one line
nft_collection = sdk.get_nft_collection(NFT_COLLECTION_ADDRESS)

# Now you can use any of the read-only SDK contract functions
nfts = nft_collection.get_all()
print(nfts)

Signing Transactions

:warning: Never commit private keys to file tracking history, or your account could be compromised. Make sure to add .env to your .gitignore file.

Meanwhile, if you want to use write functions as well and connect a signer, you can use the following setup (if you want to use your private key as displayed below, make sure to run pip install python-dotenv as well):

from thirdweb import ThirdwebSDK
from thirdweb.types.nft import NFTMetadataInput
from eth_account import Account
from dotenv import load_dotenv
from web3 import Web3
import os

# Load environment variables into this file
load_dotenv()

# This PRIVATE KEY is coming from your environment variables. Make sure to never put it in a tracked file or share it with anyone.
PRIVATE_KEY = os.environ.get("PRIVATE_KEY")

# Add your own RPC URL here or use a public one
RPC_URL = "https://rpc-mumbai.maticvigil.com"

# Instantiate a new provider to pass into the SDK
provider = Web3(Web3.HTTPProvider(RPC_URL))

# Optionally, instantiate a new signer to pass into the SDK
signer = Account.from_key(PRIVATE_KEY)

# Finally, you can create a new instance of the SDK to use
sdk = ThirdwebSDK(provider, signer)

# Instantiate a new NFT Collection contract as described above.
NFT_COLLECTION_ADDRESS = "0x.."
nft_collection = sdk.get_nft_collection(NFT_COLLECTION_ADDRESS)

# Now you can use any of the SDK contract functions including write functions
nft_collection.mint(NFTMetadataInput.from_json({ "name": "Cool NFT", "description": "Minted with the Python SDK!" }))

If you wanted to use the SDK with a signer above, make sure to include your PRIVATE_KEY in your .env file, and make sure this file is NOT tracked in any repository (make sure to add it to your .gitignore file). Adding your private key to your .env would look like the following:

PRIVATE_KEY=your-private-key-here

Development Environment

In this section, we'll go over the steps to get started with running the Python SDK repository locally and contributing to the code. If you aren't interested in contributing to the thirdweb Python SDK, you can ignore this section.

Poetry Environment Setup

If you want to work with this repository, make sure to setup Poetry, you're virtual environment, and the code styling tools.

Assuming you've installed and setup poetry, you can setup this repository with:

$ poetry shell
$ poetry install
$ poetry run yarn global add ganache
$ poetry run yarn add hardhat

Alternatively, if your system can run .sh files, you can set everything up by running the following bash script:

$ bash scripts/env/setup.sh

Running Tests

Before running tests, make sure you've already run poetry shell and are in the poetry virutal environment with all dependencies installed.

Once you have checked that this you have all the dependencies, you can run the following:

$ poetry run brownie test --network hardhat

To properly setup testing, you'll also need to add your private key to the .env file as follows (do NOT use a private key of one of your actual wallets):

PRIVATE_KEY=...

Code Style Setup

Make sure you have mypy, pylint, and black installed (all included in the dev dependencies with poetry install.

If you're working in VSCode, there a few steps to get everything working with the poetry .venv:

  1. To setup poetry virtual environment inside your VSCode so it gets recognized as part of your project (import for linters), you can take the following steps from this stack overflow answer. You need to run poetry config virtualenvs.in-project true and then make sure you delete/create a new poetry env.
  2. In .vscode/settings.json, you should have the following:
{
  "python.linting.mypyEnabled": true,
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": false
}
  1. Make sure to set your VSCode Python: Interpreter setting to the Python version inside your poetry virtual environment.

Generate Python ABI Wrappers

Use the abi-gen package to create the Python ABIs. You can install it with the following command:

$ npm install -g @0x/abi-gen

Assuming you have the thirdweb contract ABIs in this directory at /abi, you can run the following command to generate the necessary ABIs.

$ bash scripts/abi/generate.sh

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thirdweb-sdk-2.0.8.tar.gz (161.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thirdweb_sdk-2.0.8-py3-none-any.whl (212.2 kB view details)

Uploaded Python 3

File details

Details for the file thirdweb-sdk-2.0.8.tar.gz.

File metadata

  • Download URL: thirdweb-sdk-2.0.8.tar.gz
  • Upload date:
  • Size: 161.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.2 Darwin/20.4.0

File hashes

Hashes for thirdweb-sdk-2.0.8.tar.gz
Algorithm Hash digest
SHA256 8aad568506ac49fcd49779389aba15b03d759a56e10682cee5c694f2e246c265
MD5 ca4bfe726e32288f97030f7818bc2f6d
BLAKE2b-256 bf2610e3928dc57dff804a764dee82abe6b71ce4e6114ba47fd030fe2a6c921a

See more details on using hashes here.

File details

Details for the file thirdweb_sdk-2.0.8-py3-none-any.whl.

File metadata

  • Download URL: thirdweb_sdk-2.0.8-py3-none-any.whl
  • Upload date:
  • Size: 212.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.2 Darwin/20.4.0

File hashes

Hashes for thirdweb_sdk-2.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7312bd7a6a8b7ab011b11324710aa69ba0da4abe309fe21e00aecc46a30b0a8b
MD5 ccdf9f947d169fadbcee996db1ea6791
BLAKE2b-256 0ccd7ff4b1ad2de3c384ae250a76be96eb188aebdeda72d6d71d0901bb1c6b0b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page