1/5
_Follow along the course with this video._ --- ### Basic NFT Interactions Alright, with our tests passing we're going to want a way to interact with our contract programmatically. We could use `cast` commands, but let's write an interactions script instead. Create the file `script/Interactions.s.sol`. You know the drill for our boilerplate by now. ```js // SPDX-License-Identifier: MIT pragme solidity ^0.8.18; import {Script} from "forge-std/Script.sol"; contract MintBasicNft is Script{ function run() external {} } ``` We know we'll always want to be interacting with the latest deployment, so let's install the `foundry-devops` library to help with this. ```bash forge install Cyfrin/foundry-devops --no-commit ``` Now, we can import `DevOpsTools` and use this to acquire our most recent deployment. We'll use this address as a parameter for the `mint` function we'll call. > ❗ **NOTE** > I've copied over my `PUG tokenUri` for use in our `mint` function, remember to copy your own over too! ```js // SPDX-License-Identifier: MIT pragme solidity ^0.8.18; import {Script} from "forge-std/Script.sol"; import {BasicNft} from "../src/BasicNft.sol"; import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol"; contract MintBasicNft is Script{ string public constant TOKENURI = "ipfs://bafybeig37ioir76s7mg5oobetncojcm3c3hxasyd4rvid4jqhy4gkaheg4/?filename=0-PUG.json"; function run() external { address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment("BasicNft", block.chainid); mintNftOnContract(mostRecentlyDeployed); } function mintNftOnContract(address contractAddress) public { vm.startBroadcast(); BasicNft(contractAddress).mintNft(TOKENURI) vm.stopBroadcast(); } } ``` > ❗ **PROTIP** > Remember, if you don't recall which parameters are required for a function like `get_most_recent_deployment` you can `ctrl + left-click` (`cmd + click`) to be brought to the function definition. ### Wrap Up That's all there is to our interactions script, albeit we're only interacting with a single function, great work nonetheless! In the next lesson we'll look at deploying our contract to a testnet and using our script to test interacting with it on-chain.
Teaches how to interact with Solidity smart contracts, particularly for minting NFTs. It includes setting up the necessary environment and scripts, and deploying NFTs using tools like Foundry and IPFS.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at Avara
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on November 29, 2024
Solidity Developer
Advanced FoundryDuration: 36min
Duration: 3h 06min
Duration: 5h 02min
Duration: 2h 47min
Duration: 1h 23min
Duration: 4h 28min
Duration: 1h 19min
Duration: 58min
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at Avara
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on November 29, 2024
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar