0
0
Blockchain / Solidityprogramming~10 mins

Web3.js vs ethers.js in Blockchain / Solidity - Interactive Practice

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

Complete the code to create a new instance of Web3 using a provider.

Blockchain / Solidity
const Web3 = require('web3');
const web3 = new Web3([1]);
Drag options to blanks, or click blank then click option'
Awindow.ethereum
Bethers.providers.JsonRpcProvider
Cnew ethers.providers.Web3Provider()
Dweb3.eth
Attempts:
3 left
💡 Hint
Common Mistakes
Using ethers.js provider instead of Web3.js provider.
2fill in blank
medium

Complete the code to create a new ethers.js provider connected to a JSON RPC URL.

Blockchain / Solidity
const { ethers } = require('ethers');
const provider = new ethers.providers.[1]('https://mainnet.infura.io/v3/YOUR-PROJECT-ID');
Drag options to blanks, or click blank then click option'
AWeb3Provider
BAlchemyProvider
CJsonRpcProvider
DInfuraProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Using Web3Provider which expects a web3 provider object.
3fill in blank
hard

Fix the error in the code to get the balance of an address using ethers.js.

Blockchain / Solidity
const balance = await provider.getBalance([1]);
Drag options to blanks, or click blank then click option'
A12345
B'0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
Cprovider.address
Dethers.utils.getAddress()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a number or invalid object instead of a string address.
4fill in blank
hard

Fill both blanks to create a contract instance using ethers.js with ABI and address.

Blockchain / Solidity
const contract = new ethers.Contract([1], [2], provider);
Drag options to blanks, or click blank then click option'
A'0x1234567890abcdef1234567890abcdef12345678'
Babi
Caddress
Dprovider
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping address and ABI positions.
5fill in blank
hard

Fill all three blanks to send a transaction using Web3.js with from address, to address, and value.

Blockchain / Solidity
web3.eth.sendTransaction({ from: [1], to: [2], value: [3] });
Drag options to blanks, or click blank then click option'
A'0xYourAddressHere'
B'0xRecipientAddressHere'
C'1000000000000000000'
D'someValue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers instead of strings for addresses or value.