Created
August 4, 2022 16:48
-
-
Save thatguyintech/aaa9380a5de998f6ee2fddee8b59e753 to your computer and use it in GitHub Desktop.
get started with the alchemy sdk quickly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install --save-dev alchemy-sdk | |
import { Network, Alchemy } from 'alchemy-sdk'; | |
// Optional Config object, defaults to demo api key and eth mainnet. | |
const settings = { | |
apiKey: 'demo', // Replace with your Alchemy API Key! | |
network: Network.ETH_MAINNET, // Replace with your network. | |
}; | |
const alchemy = new Alchemy(settings); | |
// Access standard Ethers.js JSON-RPC node request | |
alchemy.core.getBlockNumber().then(console.log); | |
// Access Alchemy Enhanced API requests | |
alchemy.core.getTokenBalances("0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE").then(console.log); | |
// Access the Alchemy NFT API | |
alchemy.nft.getNftsForOwner('vitalik.eth').then(console.log); | |
// Access WebSockets and Alchemy-specific WS methods | |
alchemy.ws.on( | |
{ | |
method: 'alchemy_pendingTransactions' | |
}, | |
res => console.log(res) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment