Skip to content

Instantly share code, notes, and snippets.

@thatguyintech
Created August 4, 2022 16:48
Show Gist options
  • Save thatguyintech/aaa9380a5de998f6ee2fddee8b59e753 to your computer and use it in GitHub Desktop.
Save thatguyintech/aaa9380a5de998f6ee2fddee8b59e753 to your computer and use it in GitHub Desktop.
get started with the alchemy sdk quickly
// 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