5/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. ```solidity // SPDX-License-Identifier: MIT pragma 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! ```solidity // SPDX-License-Identifier: MIT pragma 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.
A hands-on walkthrough to Deploying and Minting Your First NFT on a Testnet with Foundry - Bridge the gap from local development to testnet by deploying an ERC721 contract to Sepolia using Foundry scripts, Makefiles, and FFI. Mint your first NFT, understand token URIs/IPFS metadata, and view it in MetaMask.
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)
Web3 engineer, educator, and Cyfrin co-founder. Patrick's smart contract development and security courses have helped hundreds of thousands of engineers kickstarting their careers into web3.
Guest lecturers:
Last updated on June 10, 2025
Duration: 36min
Duration: 3h 06min
Duration: 5h 02min
Duration: 6h 02min
Duration: 2h 47min
Duration: 1h 23min
Duration: 4h 28min
Duration: 1h 19min
Duration: 1h 10min
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)
Web3 engineer, educator, and Cyfrin co-founder. Patrick's smart contract development and security courses have helped hundreds of thousands of engineers kickstarting their careers into web3.
Guest lecturers:
Last updated on June 10, 2025