EIP-1193 Provider
Core SDK — EIP-1193 Provider
CROSSx SDK provides a standard EIP-1193 compatible Ethereum provider. This allows seamless integration with popular Web3 libraries such as ethers.js, viem, and web3.js.
What is EIP-1193?
EIP-1193 defines a standard JavaScript API for Ethereum providers. Any library that accepts an EIP-1193 provider (like MetaMask's window.ethereum) can also work with the CROSSx provider — no code changes needed.
Getting the provider
const provider = sdk.getProvider('eip155:612044')The chainId parameter must be in CAIP-2 format (e.g. eip155:612044).
Supported RPC methods
The CROSSx provider supports the following JSON-RPC methods:
| Method | Description |
|---|---|
eth_accounts | Returns connected wallet addresses |
eth_chainId | Returns the chain ID (hex) |
eth_blockNumber | Returns the latest block number |
eth_getBalance | Returns account balance |
eth_getTransactionCount | Returns account nonce |
eth_call | Executes a read-only contract call |
eth_estimateGas | Estimates gas for a transaction |
eth_gasPrice | Returns current gas price |
eth_getTransactionReceipt | Returns transaction receipt |
personal_sign | Signs a message (opens confirmation modal) |
eth_sign | Signs a message (opens confirmation modal) |
eth_signTypedData | Signs EIP-712 typed data (opens confirmation modal) |
eth_signTypedData_v3 | Signs EIP-712 typed data v3 (opens confirmation modal) |
eth_signTypedData_v4 | Signs EIP-712 typed data v4 (opens confirmation modal) |
eth_sendTransaction | Signs and sends a transaction (opens confirmation modal) |
wallet_switchEthereumChain | Switches the active chain |
wallet_addEthereumChain | Acknowledged (no-op) |
net_version | Returns the network version string |
::: warning Read-only methods execute immediately. Signing and sending methods always display a user confirmation modal. :::
Integration with ethers.js v6
import { BrowserProvider } from 'ethers'
const provider = sdk.getProvider('eip155:612044')
const ethersProvider = new BrowserProvider(provider)
// Read-only operations
const blockNumber = await ethersProvider.getBlockNumber()
const balance = await ethersProvider.getBalance('0xYourAddress')
// Get signer for write operations
const signer = await ethersProvider.getSigner()
const address = await signer.getAddress()
// Sign message
const signature = await signer.signMessage('Hello CROSSx')
// Send transaction
const tx = await signer.sendTransaction({
to: '0xRecipient...',
value: ethers.parseEther('0.1'),
})
const receipt = await tx.wait()
console.log('TX mined:', receipt.hash)Integration with ethers.js v5
import { ethers } from 'ethers'
const provider = sdk.getProvider('eip155:612044')
const ethersProvider = new ethers.providers.Web3Provider(provider)
const signer = ethersProvider.getSigner()
const address = await signer.getAddress()
const balance = await ethersProvider.getBalance(address)
// Send transaction
const tx = await signer.sendTransaction({
to: '0xRecipient...',
value: ethers.utils.parseEther('0.1'),
})
await tx.wait()Integration with viem
import { createPublicClient, createWalletClient, custom, parseEther } from 'viem'
const provider = sdk.getProvider('eip155:612044')
// Public client (read-only)
const publicClient = createPublicClient({
transport: custom(provider),
})
const blockNumber = await publicClient.getBlockNumber()
const balance = await publicClient.getBalance({
address: '0xYourAddress',
})
// Wallet client (read + write)
const walletClient = createWalletClient({
transport: custom(provider),
})
const [address] = await walletClient.getAddresses()
// Sign message
const signature = await walletClient.signMessage({
account: address,
message: 'Hello CROSSx',
})
// Send transaction
const hash = await walletClient.sendTransaction({
account: address,
to: '0xRecipient...',
value: parseEther('0.1'),
})Integration with web3.js
import Web3 from 'web3'
const provider = sdk.getProvider('eip155:612044')
const web3 = new Web3(provider)
const accounts = await web3.eth.getAccounts()
const balance = await web3.eth.getBalance(accounts[0])
// Send transaction
const receipt = await web3.eth.sendTransaction({
from: accounts[0],
to: '0xRecipient...',
value: web3.utils.toWei('0.1', 'ether'),
})Contract interaction
Read contract (ethers.js)
const provider = sdk.getProvider('eip155:612044')
const ethersProvider = new BrowserProvider(provider)
const erc20 = new ethers.Contract('0xTokenAddress', [
'function name() view returns (string)',
'function symbol() view returns (string)',
'function balanceOf(address) view returns (uint256)',
], ethersProvider)
const name = await erc20.name()
const balance = await erc20.balanceOf('0xYourAddress')Write contract (ethers.js)
const signer = await ethersProvider.getSigner()
const erc20 = new ethers.Contract('0xTokenAddress', [
'function transfer(address to, uint256 amount) returns (bool)',
], signer)
const tx = await erc20.transfer('0xRecipient', ethers.parseUnits('100', 18))
const receipt = await tx.wait()Contract interaction (viem)
import { createPublicClient, createWalletClient, custom, parseUnits } from 'viem'
import { erc20Abi } from 'viem'
const provider = sdk.getProvider('eip155:612044')
const publicClient = createPublicClient({ transport: custom(provider) })
const walletClient = createWalletClient({ transport: custom(provider) })
// Read
const balance = await publicClient.readContract({
address: '0xTokenAddress',
abi: erc20Abi,
functionName: 'balanceOf',
args: ['0xYourAddress'],
})
// Write
const [account] = await walletClient.getAddresses()
const hash = await walletClient.writeContract({
account,
address: '0xTokenAddress',
abi: erc20Abi,
functionName: 'transfer',
args: ['0xRecipient', parseUnits('100', 18)],
})Event listening
The CROSSx provider emits standard EIP-1193 events:
const provider = sdk.getProvider('eip155:612044')
provider.on('accountsChanged', (accounts: string[]) => {
console.log('Accounts changed:', accounts)
})
provider.on('chainChanged', (chainId: string) => {
console.log('Chain changed:', chainId)
})
provider.on('disconnect', () => {
console.log('Disconnected')
})Using with multiple chains
const crossProvider = sdk.getProvider('eip155:612044')
const ethProvider = sdk.getProvider('eip155:1')
const polygonProvider = sdk.getProvider('eip155:137')
// Each provider routes RPC calls to the correct chain
const crossBalance = await new BrowserProvider(crossProvider).getBalance(address)
const ethBalance = await new BrowserProvider(ethProvider).getBalance(address)Raw RPC request
For methods not covered by library abstractions, use the provider's request method directly:
const provider = sdk.getProvider('eip155:612044')
// Any JSON-RPC method
const result = await provider.request({
method: 'eth_getBlockByNumber',
params: ['latest', false],
})Updated 15 days ago