Consider this simplified Ethereum transaction sending code using web3.js. What will be printed to the console?
const Web3 = require('web3'); const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_PROJECT_ID'); async function sendTx() { const accounts = await web3.eth.getAccounts(); console.log(accounts.length); } sendTx();
Think about what getAccounts() returns when connected to a public node without unlocked accounts.
When connected to a public node like Infura, getAccounts() returns an empty array because the node does not manage any accounts locally. So, accounts.length is 0.
Given this code snippet calculating Bitcoin transaction fee, what is the output?
const txSizeBytes = 250; const feeRateSatsPerByte = 20; const fee = txSizeBytes * feeRateSatsPerByte; console.log(fee);
Multiply transaction size by fee rate per byte.
The fee is calculated by multiplying the transaction size (250 bytes) by the fee rate (20 satoshis per byte), resulting in 5000 satoshis.
Look at this code snippet that tries to send an Ethereum transaction. Why does it throw an error?
const Web3 = require('web3'); const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_PROJECT_ID'); async function sendTx() { const tx = { from: '0xYourAddress', to: '0xRecipientAddress', value: web3.utils.toWei('1', 'ether'), gas: 21000 }; const receipt = await web3.eth.sendTransaction(tx); console.log(receipt); } sendTx();
Think about what is needed to sign and send a transaction using a public node.
When using a public node like Infura, the account is not unlocked and private keys are not managed. You must sign the transaction locally before sending. Without signing, sendTransaction throws an error.
Choose the code snippet that correctly creates and signs a transaction using ethers.js.
Check the correct method name for signing a transaction in ethers.js.
The correct method to sign a transaction in ethers.js is signTransaction. The value must be converted to wei using parseEther. Option C uses the correct method and value format.
Given this simplified Bitcoin transaction creation code, how many outputs will the transaction have?
const bitcoin = require('bitcoinjs-lib'); const keyPair = bitcoin.ECPair.makeRandom(); const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey }); const txb = new bitcoin.TransactionBuilder(); txb.addInput('some-txid', 0); txb.addOutput('recipient-address', 50000); txb.addOutput(address, 45000); const tx = txb.build(); console.log(tx.outs.length);
Count how many times addOutput is called.
The transaction builder adds two outputs: one to the recipient and one as change back to the sender's address. So, the transaction has 2 outputs.