Working with different Web3 providers

By default, a viem provider is used for EVM-compatible JSON-RPC interaction. However, you can use Holyheld SDK with other providers like Ethers.js and Web3.js

Wagmi

import { getPublicClient, getWalletClient } from '@wagmi/core';

const chainId; // token chain id

(async () => {
  const publicClient = getPublicClient({ chainId });
  const walletClient = await getWalletClient({ chainId });
})();

Ethers.js

import { providers } from 'ethers';
import { createPublicClient, createWalletClient, custom, http } from 'viem';

const chain; // chain entity from viem

const provider = new providers.Web3Provider(window.ethereum);

const publicClient = createPublicClient({
  chain,
  transport: http(),
});

const walletClient = createWalletClient({
  chain,
  transport: custom(provider.provider),
  account: '0x...', // wallet address
});

Web3.js

import Web3 from 'web3';
import { createPublicClient, createWalletClient, custom, http } from 'viem';

const chain; // chain entity from viem

const provider = new Web3(window.ethereum).currentProvider;

const publicClient = createPublicClient({
  chain,
  transport: http(),
});

const walletClient = createWalletClient({
  chain,
  transport: custom(provider),
  account: '0x...', // wallet address
});