In this guide, we will create ERC20 tokens that can be used as a currency with the thirdweb Python SDK.
The first thing we need to do is head over to the dashboard and deploy a new Token contract.
- Click Deploy New contract
- Click Deploy Now on the Token contract
- Configure your metadata, and deploy the contract to the Mumbai (MATIC) test network.
You can easily mint tokens on the thirdweb dashboard by clicking on the Mint button.
But in this guide, we'll mint tokens using Python!
Go ahead and create a new Python file. Let's call it
currency.py and open it in your favorite code editor.
Use the following code in your terminal to install the thirdweb SDK in the project!
pip install thirdweb-sdk
Now we can import the SDK, along with the other libraries we're going to use.
from thirdweb import ThirdwebSDK
To sign transactions from your wallet, we need to instantiate the SDK using our wallet's private key.
:::info How to export your private key
Learn how to export your private key from your wallet.
Ensure you store and access your private key securely.
- Never commit any file that may contain your private key to your source control.
Now we can initialize our SDK:
# 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>" # Set the network you want to operate on, or add your own RPC URL here NETWORK = "mumbai" # Finally, you can create a new instance of the SDK to use sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, NETWORK)
Now let's connect to our token smart contract in our Python code.
To do that, grab your contract address from the dashboard, and use it to get the contract instance.
TOKEN_CONTRACT_ADDRESS = "0x..." # Replace with your contract address token = sdk.get_token(TOKEN_CONTRACT_ADDRESS)
And finally, mint some tokens!
To run the code:
That's it! You've successfully created your own ERC20 token and minted supply using Python!
Check out what else you can do with the token contract on the thirdweb portal.