Skip to content
Skillv1.0.0

alchemy-hello-world

Create a minimal Alchemy Web3 example: get ETH balance, fetch NFTs, read token balances. Use when starting blockchain development, testing Alchemy setup, or learning basic blockchain query patterns. T

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (skills/.curated/alchemy-hello-world/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill alchemy-hello-world. Copyright stays with the author (MIT).

Alchemy Hello World

Overview

Minimal working examples with the real Alchemy SDK: get ETH balance, fetch NFTs for a wallet, read ERC-20 token balances, and subscribe to pending transactions.

Prerequisites

  • Completed alchemy-install-auth setup
  • alchemy-sdk installed (npm install alchemy-sdk)
  • Valid API key configured

Instructions

Step 1: Get ETH Balance

// src/hello-world/get-balance.ts
import { Alchemy, Network, Utils } from 'alchemy-sdk';

const alchemy = new Alchemy({
  apiKey: process.env.ALCHEMY_API_KEY,
  network: Network.ETH_MAINNET,
});

async function getBalance(address: string) {
  const balanceWei = await alchemy.core.getBalance(address);
  const balanceEth = Utils.formatEther(balanceWei);
  console.log(`Balance of ${address}: ${balanceEth} ETH`);
  return balanceEth;
}

// Query Vitalik's address
getBalance('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045').catch(console.error);

Step 2: Fetch NFTs for a Wallet

// src/hello-world/get-nfts.ts
import { Alchemy, Network } from 'alchemy-sdk';

const alchemy = new Alchemy({
  apiKey: process.env.ALCHEMY_API_KEY,
  network: Network.ETH_MAINNET,
});

async function getNftsForOwner(owner: string) {
  const nfts = await alchemy.nft.getNftsForOwner(owner);
  console.log(`Total NFTs: ${nfts.totalCount}`);

  for (const nft of nfts.ownedNfts.slice(0, 5)) {
    console.log(`  ${nft.contract.name} — ${nft.name || nft.tokenId}`);
    console.log(`    Contract: ${nft.contract.address}`);
    console.log(`    Token ID: ${nft.tokenId}`);
    if (nft.image?.cachedUrl) {
      console.log(`    Image: ${nft.image.cachedUrl}`);
    }
  }

  return nfts;
}

getNftsForOwner('vitalik.eth').catch(console.error);

Step 3: Get ERC-20 Token Balances

// src/hello-world/get-tokens.ts
import { Alchemy, Network } from 'alchemy-sdk';

const alchemy = new Alchemy({
  apiKey: process.env.ALCHEMY_API_KEY,
  network: Network.ETH_MAINNET,
});

async function getTokenBalances(address: string) {
  const balances = await alchemy.core.getTokenBalances(address);

  console.log(`Token balances for ${address}:`);
  for (const token of balances.tokenBalances.slice(0, 10)) {
    if (token.tokenBalance && token.tokenBalance !== '0x0') {
      // Get token metadata for human-readable names
      const metadata = await alchemy.core.getTokenMetadata(token.contractAddress);
      const balance = parseInt(token.tokenBalance, 16) / Math.pow(10, metadata.decimals || 18);
      console.log(`  ${metadata.symbol}: ${balance.toFixed(4)}`);
    }
  }
}

getTokenBalances('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045').catch(console.error);

Step 4: Get Latest Block Info

// src/hello-world/get-block.ts
import { Alchemy, Network } from 'alchemy-sdk';

const alchemy = new Alchemy({
  apiKey: process.env.ALCHEMY_API_KEY,
  network: Network.ETH_MAINNET,
});

async function getLatestBlock() {
  const blockNumber = await alchemy.core.getBlockNumber();
  const block = await alchemy.core.getBlock(blockNumber);

  console.log(`Block #${blockNumber}`);
  console.log(`  Hash: ${block.hash}`);
  console.log(`  Timestamp: ${new Date(block.timestamp * 1000).toISOString()}`);
  console.log(`  Transactions: ${block.transactions.length}`);
  console.log(`  Gas Used: ${block.gasUsed.toString()}`);
}

getLatestBlock().catch(console.error);

Output

  • ETH balance query with Wei → ETH conversion
  • NFT enumeration with metadata and images
  • ERC-20 token balances with symbol resolution
  • Block data with timestamp and gas usage

Examples

Create a local .env entry through your secret-management workflow, run the balance and latest-block examples against a public address, and verify that the output contains only public chain data and no API key. Use a test address you control when adapting the NFT or token examples, and make one request at a time while learning the SDK. A successful run returns a block number or a well-formed empty asset list; it does not establish wallet ownership or asset value. If the address, network, or key is invalid, stop at the reported error, correct the configuration, and retry without copying the secret into source or terminal transcripts.

Error Handling

Error Cause Solution
Invalid address Malformed Ethereum address Use checksummed 0x-prefixed address
429 Too Many Requests Rate limit exceeded Add delay between calls or upgrade plan
ENS name not found ENS not resolving Verify ENS name exists on mainnet
Timeout Slow node response Increase timeout in SDK config

Resources

Next Steps

Proceed to alchemy-local-dev-loop for development workflow setup.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-alchemy-hello-world/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-alchemy-hello-world.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-alchemy-hello-world",
  "kind": "skill",
  "name": "alchemy-hello-world",
  "description": "Create a minimal Alchemy Web3 example: get ETH balance, fetch NFTs, read token balances. Use when starting blockchain development, testing Alchemy setup, or learning basic blockchain query patterns. Trigger: \"alchemy hello world\", \"alchemy example\", \"alchemy quick start\", \"get ETH balance\", \"fetch NFTs alchemy\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general_chat",
      "data_analysis"
    ],
    "tags": [
      "skill-md",
      "saas",
      "blockchain",
      "web3",
      "alchemy",
      "nft",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Create a minimal Alchemy Web3 example: get ETH balance, fetch NFTs, read token balances. Use when starting blockchain development, testing Alchemy setup, or learning basic blockchain query patterns. Trigger: \"alchemy hello world\", \"alchemy example\", \"alchemy quick start\", \"get ETH balance\", \"fetch NFTs alchemy\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "skills/.curated/alchemy-hello-world/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/skills/.curated/alchemy-hello-world/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/skills/.curated/alchemy-hello-world/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Write,",
      "Edit,",
      "Bash(npm:*)"
    ],
    "license": "MIT"
  },
  "instructions": "# Alchemy Hello World\n\n## Overview\n\nMinimal working examples with the real Alchemy SDK: get ETH balance, fetch NFTs for a wallet, read ERC-20 token balances, and subscribe to pending transactions.\n\n## Prerequisites\n\n- Completed `alchemy-install-auth` setup\n- `alchemy-sdk` installed (`npm install alchemy-sdk`)\n- Valid API key configured\n\n## Instructions\n\n### Step 1: Get ETH Balance\n\n```typescript\n// src/hello-world/get-balance.ts\nimport { Alchemy, Network, Utils } from 'alchemy-sdk';\n\nconst alchemy = new Alchemy({\n  apiKey: process.env.ALCHEMY_API_KEY,\n  network: Network.ETH_MAINNET,\n});\n\nasync",
  "cost": {
    "context_tokens": 1224
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-alchemy-hello-world/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.