Bridge Kit uses adapters to abstract away the complexity of different blockchain architectures. Adapters handle all blockchain-specific bridging operations for a particular network.
The following table shows ways to set up adapters and when to use each one.
Setup method | Description | Use case |
---|---|---|
Standard | Standard setup that creates an adapter from a private wallet key. Uses default built-in public RPC endpoints and factory functions. | Testing environments where you want to get started quickly without configuring RPCs. |
Custom RPC | Private key setup that lets you configure an RPC endpoint. | Production environments that need reliable RPCs. |
Browser wallet | Uses an injected wallet provider, such as MetaMask or Phantom, to create an adapter in the browser. | Browser environments using wallet providers. |
Bridge Kit works with these adapter libraries:
viem
v2: for EVM-compatible chainsethers
: v6 for EVM-compatible chainssolana
: for the Solana blockchainPick one Ethereum adapter (either Viem or Ethers). Add the Solana adapter only if you want transfer to or from Solana.
This is the easiest way to start. You create one adapter from your wallet's private key to transfer tokens between EVM-compatible blockchains. You can also add the Solana adapter to transfer tokens to or from Solana.
This setup uses public RPC endpoints and factory functions. For production, you should configure a custom RPC. Public connections have rate limits and might be slow.
Select the tab to see code examples for your adapter choice.
This code block initializes the Viem adapter to transfer tokens between EVM-compatible chains:
import { createAdapterFromPrivateKey } from "@circle-fin/adapter-viem-v2";
const adapter = createAdapterFromPrivateKey({
privateKey: process.env.PRIVATE_KEY as string,
});
This code block initializes the Ethers adapter to transfer tokens between EVM-compatible chains:
import { createAdapterFromPrivateKey } from "@circle-fin/adapter-ethers-v6";
const adapter = createAdapterFromPrivateKey({
privateKey: process.env.PRIVATE_KEY as string,
});
This code block initializes the Solana adapter to bridge on Solana:
import { createAdapterFromPrivateKey } from "@circle-fin/adapter-solana";
// Solana accepts Base58, Base64, or JSON array format private keys
const adapter = createAdapterFromPrivateKey({
privateKey: process.env.PRIVATE_KEY as string,
});
You can replace the public RPC from the standard setup with your own connection. For production, you should use a paid service like Alchemy or QuickNode. These services are more reliable than free connections.
The following code shows how to set up your own RPC. Pick your adapter to see the code.
To use your own connection, replace the default one and add your custom RPC endpoint. This example uses an Alchemy connection:
import { createAdapterFromPrivateKey } from "@circle-fin/adapter-viem-v2";
import { createPublicClient, http } from "viem";
// Create an adapter
const adapter = createAdapterFromPrivateKey({
privateKey: process.env.PRIVATE_KEY as string,
// Replace the default connection
getPublicClient: ({ chain }) =>
createPublicClient({
chain,
// Use an Alchemy connection
transport: http(
`https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
{
retryCount: 3,
timeout: 10000,
},
),
}),
});
To use your own connection, replace the default one and add your custom RPC endpoint. This example uses an Alchemy connection:
import { createAdapterFromPrivateKey } from "@circle-fin/adapter-ethers-v6";
import { JsonRpcProvider } from "ethers";
// Create an adapter
const adapter = createAdapterFromPrivateKey({
privateKey: process.env.PRIVATE_KEY as string,
// Replace the default connection
getProvider: ({ chain }) =>
// Use an Alchemy connection
new JsonRpcProvider(
`https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
),
});
To use your own connection, create a custom connection to your RPC endpoint. Point to that connection when making a Solana adapter. This example creates a custom connection using Alchemy:
import { createAdapterFromPrivateKey } from "@circle-fin/adapter-solana";
import { Connection } from "@solana/web3.js";
// Create a connection to an Alchemy endpoint
const customConnection = new Connection(
`https://solana-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`,
{
commitment: "confirmed",
wsEndpoint: `wss://solana-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`,
},
);
// Create a Solana adapter
const adapter = createAdapterFromPrivateKey({
privateKey: process.env.SOLANA_PRIVATE_KEY as string,
connection: customConnection,
});
You can create an adapter from browser wallet apps like MetaMask or Phantom.
The following code creates an adapter from a MetaMask wallet. Pick your adapter to see the code.
import { createAdapterFromProvider } from "@circle-fin/adapter-viem-v2";
import { MetaMaskInpageProvider } from "@metamask/providers";
import { EIP1193Provider } from "viem";
declare global {
interface Window {
ethereum?: MetaMaskInpageProvider;
}
}
const adapter = createAdapterFromProvider({
provider: window.ethereum as EIP1193Provider,
});
import { createAdapterFromProvider } from "@circle-fin/adapter-ethers-v6";
import { MetaMaskInpageProvider } from "@metamask/providers";
import { EIP1193Provider } from "ethers";
declare global {
interface Window {
ethereum?: MetaMaskInpageProvider;
}
}
const adapter = createAdapterFromProvider({
provider: window.ethereum as EIP1193Provider,
});
import {
createAdapterFromProvider,
CreateAdapterFromProviderParams,
} from "@circle-fin/adapter-solana";
declare global {
interface Window {
solana?: CreateAdapterFromProviderParams["provider"];
}
}
if (window.solana) {
const adapter = createAdapterFromProvider({
provider: window.solana,
});
}