Skip to content

A JavaScript/TypeScript SDK for interacting with the WorldChain ecosystem. This SDK provides tools and utilities to simplify development with WorldChain, including quoting token swaps on-chain.

Notifications You must be signed in to change notification settings

holdstation/worldchain-sdk

Repository files navigation

Worldchain SDK

🔗 TypeScript-powered library for interacting with Worldchain blockchain with multiple provider options

NPM License: MIT

Features

  • 🛠 Multiple Provider Integration: Choose between ethers.js v5/v6 or viem
  • 🔄 Unified API: Same interface regardless of the underlying provider
  • 📦 Tree-shakable: Import only what you need
  • 🔒 Type-safe: Full TypeScript support with complete typings
  • 🚀 Multicall Support: Batch multiple calls for efficient interactions
  • 🧩 Modular Design: Core functionality is provider-agnostic

Installation

# Core package only
npm install @holdstation/worldchain-sdk

# With ethers.js v5 support
npm install @holdstation/worldchain-ethers-v5 ethers@^5.0.0

# With ethers.js v6 support
npm install @holdstation/worldchain-ethers-v6 ethers@^6.0.0

# With viem support
npm install @holdstation/worldchain-viem viem

Quick Start

Using with ethers.js v5

import { ethers } from 'ethers';
import { Client, Multicall3 } from '@holdstation/worldchain-ethers-v5';
import { TokenProvider } from '@holdstation/worldchain-sdk';

// Initialize provider
const provider = new ethers.providers.JsonRpcProvider('RPC_URL');
const client = new Client(provider);
const multicall = new Multicall3(provider);

// Use the TokenProvider for token operations
const tokenProvider = new TokenProvider({ client, multicall });
const tokenInfo = await tokenProvider.details('0x123...'); // Get token details

Using with viem

import { createPublicClient, http } from 'viem';
import { worldchain } from 'viem/chains';
import { Client, Multicall3 } from '@holdstation/worldchain-viem';
import { TokenProvider } from '@holdstation/worldchain-sdk';

// Initialize provider
const publicClient = createPublicClient({
  chain: worldchain,
  transport: http('RPC_URL')
});

const client = new Client(publicClient);
const multicall = new Multicall3(publicClient);

// Use the TokenProvider
const tokenProvider = new TokenProvider({ client, multicall });
const tokenInfo = await tokenProvider.details('0x123...'); // Get token details

Packages

  • @holdstation/worldchain-sdk: Core interfaces and utilities
  • @holdstation/worldchain-ethers-v5: Integration with ethers.js v5
  • @holdstation/worldchain-ethers-v6: Integration with ethers.js v6
  • @holdstation/worldchain-viem: Integration with viem

API Reference

Client

// Example with AbiCodec
const abi = ['function balanceOf(address) view returns (uint256)'];
const codec = client.codec(abi);
const data = codec.encodeFunctionData('balanceOf', ['0xAddress']);

Multicall3

// Batch multiple calls
const calls = [
  {
    target: tokenAddress,
    callData: codec.encodeFunctionData('balanceOf', [userAddress])
  },
  // More calls...
];

const [blockNumber, results] = await multicall.aggregate(calls);

TokenProvider

// Get token information
const token = await tokenProvider.details(tokenAddress);
console.log(token.name, token.symbol, token.decimals);

// Get token balance
const balance = await tokenProvider.balanceOf(tokenAddress, userAddress);

Advanced Usage

Creating Custom Implementations

You can implement the interfaces from the core package to create custom providers:

import { Client } from '@holdstation/worldchain-sdk';

class CustomClient implements Client {
  // Implement the required methods
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

About

A JavaScript/TypeScript SDK for interacting with the WorldChain ecosystem. This SDK provides tools and utilities to simplify development with WorldChain, including quoting token swaps on-chain.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •