1/5
## Writing a Deploy Script In our script, we will create a file called `deploy_basic_nft.py`. ```python def moccasin_main(): pass ``` We should be very familiar with this at this point. Let's do a little `def deploy_basic_nft()`. ```python def deploy_basic_nft(): pass ``` We are actually going to do `deploy_basic_nft` and in here we're going to say ```python from src import basic_nft ``` So we call it. Yep. Then we'll say `contract` equals `basic_nft.deploy()`. ```python def deploy_basic_nft(): contract = basic_nft.deploy() print(f"Deployed BasicNFT contract to: {contract.address}") ``` Then we'll do `contract.mint` and this is where we can pass in a URI. I'm going to say `pug_uri` equals ```python PUG_URI = "QmWt16U9B3JryY9HBY36r6tUUtdmDnmGLdeEendAAggmrx3tMel" ``` and I'm going to paste this in here. ```python PUG_URI = "QmWt16U9B3JryY9HBY36r6tUUtdmDnmGLdeEendAAggmrx3tMel" def deploy_basic_nft(): contract = basic_nft.deploy() print(f"Deployed BasicNFT contract to: {contract.address}") contract.mint(PUG_URI) ``` So I already have this uploaded to my IPFS. So for now just follow along with me. I'll show you how to upload and work with and add your own custom IPFS stuff in just a second, and why we're using this weird IPFS thing in the first place. But for now if you want to just copy this from the script here, paste it in, boom. This will resemble the NFT associated with that pug. And we're going to pass in this pug URI that we've set here. ```python PUG_URI = "QmWt16U9B3JryY9HBY36r6tUUtdmDnmGLdeEendAAggmrx3tMel" def deploy_basic_nft(): contract = basic_nft.deploy() print(f"Deployed BasicNFT contract to: {contract.address}") contract.mint(PUG_URI) print("Contract deployed at", contract.address) ``` And now, since this mint function right this mint function should have minted us a new token, and we should start with counter of 0 or token ID 0. We should be able to do `token_metadata` equals `contract.tokenURI(0)`. ```python PUG_URI = "QmWt16U9B3JryY9HBY36r6tUUtdmDnmGLdeEendAAggmrx3tMel" def deploy_basic_nft(): contract = basic_nft.deploy() print(f"Deployed BasicNFT contract to: {contract.address}") contract.mint(PUG_URI) print("Contract deployed at", contract.address) token_metadata = contract.tokenURI(0) print(f"Token metadata: {token_metadata}") ``` And we could print `token_metadata`. ```bash mox run deploy_basic_nft ``` This is actually `token_uri`. ```python PUG_URI = "QmWt16U9B3JryY9HBY36r6tUUtdmDnmGLdeEendAAggmrx3tMel" def deploy_basic_nft(): contract = basic_nft.deploy() print(f"Deployed BasicNFT contract to: {contract.address}") contract.mint(PUG_URI) print("Contract deployed at", contract.address) token_uri = contract.tokenURI(0) print(token_uri) ``` Now if I run `mox run deploy_basic_nft` we should see this. ```bash mox run deploy_basic_nft ``` So, if I pull this up now and I just run `mox run deploy_basic_nft`. This is the token URI itself and that's exactly what we want. So this is actually `token_uri`.
A practical guide to deploying a Solidity smart contract using a Python script. The lesson covers setting up the environment, importing the contract, minting a token with a custom URI, and printing the token URI for verification.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
How to build a DeFi stablecoin and customized NFT
How to deploy your smart contract on ZKsync with Moccasin
Advanced testing techniques like stateful and stateless Python fuzzing
How to write algorithmic trading scripts in Python
Hashing signatures, proxies, delegate calls, upgradable contracts, random numbers, and more!
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on February 4, 2025
Duration: 2h 21min
Duration: 1h 58min
Duration: 2h 55min
Duration: 1h 55min
Duration: 46min
Course Overview
About the course
How to build a DeFi stablecoin and customized NFT
How to deploy your smart contract on ZKsync with Moccasin
Advanced testing techniques like stateful and stateless Python fuzzing
How to write algorithmic trading scripts in Python
Hashing signatures, proxies, delegate calls, upgradable contracts, random numbers, and more!
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on February 4, 2025