This guide assumes you've gone through the getting started steps and have an Alchemy account!
mkdir web3-examplecd web3-example
You can use any web3 library of your choosing, however there are tons of benefits to using Alchemy Web3!
npm install @alch/alchemy-web3
You should ultimately replace demo
with your Alchemy HTTP API key.
async function main() {const { createAlchemyWeb3 } = require("@alch/alchemy-web3");const web3 = createAlchemyWeb3("https://eth-mainnet.alchemyapi.io/v2/demo");const blockNumber = await web3.eth.getBlockNumber();console.log("The latest block number is " + blockNumber);}main();
Unfamiliar with the async stuff? Check out this Medium post.
node index.js
The latest block number is 11043912
Woo! Congrats! You just wrote your first web3 script using Alchemy π
Not sure what to do next? Try deploying your first smart contract and get your hands dirty with some solidity programming with our Hello World Smart Contract Guide, or test your dashboard knowledge with the Dashboard Demo App!