Testing with ethers.js
📖 Scenario: You are building a simple smart contract that stores a number. You want to write tests using ethers.js to check if the contract works correctly.
🎯 Goal: Write a test script using ethers.js that deploys the contract, sets a number, and checks if the stored number is correct.
📋 What You'll Learn
Create a variable called
SimpleStorage to get the contract factoryCreate a variable called
simpleStorage to deploy the contractCreate a variable called
tx to store the transaction when setting the numberUse
await tx.wait() to wait for the transaction to be minedUse
const storedNumber = await simpleStorage.retrieve() to get the stored numberUse
console.log(storedNumber.toString()) to print the stored number💡 Why This Matters
🌍 Real World
Testing smart contracts before deploying them to the blockchain helps avoid costly mistakes and bugs.
💼 Career
Blockchain developers use ethers.js and testing frameworks to ensure their contracts work correctly and securely.
Progress0 / 4 steps