0
0
Blockchain / Solidityprogramming~10 mins

Reading contract state in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read the contract's stored value.

Blockchain / Solidity
const value = await contract.[1]();
Drag options to blanks, or click blank then click option'
AstoreValue
BreadValue
CfetchValue
DgetValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function that writes data instead of reading.
Calling a function that does not exist in the contract.
2fill in blank
medium

Complete the code to connect to the contract using ethers.js.

Blockchain / Solidity
const contract = new ethers.Contract(contractAddress, abi, [1]);
Drag options to blanks, or click blank then click option'
Aprovider
Bsigner
Cwallet
Daccount
Attempts:
3 left
💡 Hint
Common Mistakes
Using a signer when only reading data.
Passing an undefined variable.
3fill in blank
hard

Fix the error in the code to properly await the contract call.

Blockchain / Solidity
const balance = await contract.[1]();
Drag options to blanks, or click blank then click option'
AgetBalance
Bawait getBalance
Cawait balance
Dbalance
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'await' inside the method name.
Not using 'await' at all causing a Promise instead of value.
4fill in blank
hard

Fill both blanks to create a dictionary of token balances greater than zero.

Blockchain / Solidity
const balances = { [1]: [2] for (const token of tokens) if (await contract.balanceOf(token) > 0) };
Drag options to blanks, or click blank then click option'
Atoken
Bawait contract.balanceOf(token)
Ctoken.balance
Dbalance
Attempts:
3 left
💡 Hint
Common Mistakes
Using a property that does not exist on token.
Not awaiting the balanceOf call.
5fill in blank
hard

Fill all three blanks to filter and map contract events for transfers above 100 tokens.

Blockchain / Solidity
const largeTransfers = events.filter(e => e.args.[1] > [2]).map(e => e.args.[3]);
Drag options to blanks, or click blank then click option'
Avalue
B100
Cto
Dfrom
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'from' instead of 'to' in the map.
Comparing with a string instead of a number.