Challenge - 5 Problems
Hardhat Deployment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a basic Hardhat deployment script
What will be the output printed to the console when running this Hardhat deployment script?
Blockchain / Solidity
async function main() { const [deployer] = await ethers.getSigners(); console.log('Deploying contracts with the account:', deployer.address); const Token = await ethers.getContractFactory('Token'); const token = await Token.deploy('MyToken', 'MTK', 18, 1000); await token.deployed(); console.log('Token deployed to:', token.address); } main().catch((error) => { console.error(error); process.exitCode = 1; });
Attempts:
2 left
💡 Hint
Remember that ethers.getSigners() returns an array of accounts and deployer.address is a valid address string.
✗ Incorrect
The script logs the deployer's address and the deployed contract address after deployment. Options B, C, and D are incorrect because the deployer address and contract address are defined, the syntax is correct, and the contract factory is found.
🧠 Conceptual
intermediate1:30remaining
Understanding deployment script parameters
In a Hardhat deployment script, what is the purpose of the line `const Token = await ethers.getContractFactory('Token');`?
Attempts:
2 left
💡 Hint
Think about what a contract factory does in ethers.js.
✗ Incorrect
The getContractFactory method compiles the contract and returns a factory object that can be used to deploy new instances. It does not deploy immediately or fetch existing addresses.
🔧 Debug
advanced2:00remaining
Identify the error in this deployment script
What error will this Hardhat deployment script produce when run?
Blockchain / Solidity
async function main() { const Token = await ethers.getContractFactory('Token') const token = Token.deploy('MyToken', 'MTK', 18, 1000) await token.deployed() console.log('Token deployed to:', token.address) } main().catch(console.error);
Attempts:
2 left
💡 Hint
Check if the deploy function is awaited properly.
✗ Incorrect
The deploy() method returns a promise, so it must be awaited. Without await, token is a promise, and token.deployed() is undefined, causing a TypeError.
📝 Syntax
advanced1:30remaining
Correct syntax for deploying with constructor arguments
Which option correctly deploys a contract named 'Crowdsale' with constructor arguments `rate` and `wallet`?
Attempts:
2 left
💡 Hint
Remember how to pass multiple arguments to a contract constructor in deploy().
✗ Incorrect
Option D correctly awaits getContractFactory and deploys with separate arguments. Options C and D incorrectly pass arguments as an array. Option D misses await and will cause errors.
🚀 Application
expert2:30remaining
Determine the number of deployed contracts
Given this Hardhat deployment script, how many contracts will be deployed to the blockchain after running it?
Blockchain / Solidity
async function main() { const [deployer] = await ethers.getSigners(); const Token = await ethers.getContractFactory('Token'); const token = await Token.deploy('MyToken', 'MTK', 18, 1000); await token.deployed(); const Crowdsale = await ethers.getContractFactory('Crowdsale'); const crowdsale = await Crowdsale.deploy(1, deployer.address, token.address); await crowdsale.deployed(); console.log('Deployment complete'); } main().catch(console.error);
Attempts:
2 left
💡 Hint
Count each deploy() call that is awaited and completed.
✗ Incorrect
The script deploys two contracts: Token and Crowdsale. Both deploy calls are awaited and completed, so two contracts are deployed.