Skip to main content
You are here: Credenza EVM Provider

Usage

Basic Setup

To start using Credenza EVM provider, you need to import and configure the provider. Below is the basic setup code:

import { CredenzaProvider } from '@credenza3/evm-provider'

const provider = new CredenzaProvider({
  rpcUrl: '',
  accessToken: 'your-credenza-access-token',
  env: 'staging', // 'prod' | 'staging'
})

Using with ethers.js

You can integrate Credenza EVM provider with ethers.js as shown below:

import { ethers } from '@credenza3/evm-provider'

const ethersProvider = new ethers.BrowserProvider(provider)
const signer = await ethersProvider.getSigner()

const address = await signer.getAddress()

const tx = await signer.sendTransaction({
  to: '0x...',
  value: ethers.parseEther('0.1'),
})

API Reference

Constructor

The CredenzaProvider constructor requires the following parameters:

  new CredenzaProvider(params: {
    rpcUrl: string
    accessToken?: string
    env: string
  })
  • rpcUrl - RPC URL of the blockchain network

  • accessToken - Credenza3 authentication token

  • env - Environment ('prod' | 'staging')

Methods

setAccessToken(accessToken: string)

Updates the access token.

provider.setAccessToken('new-access-token')

setRpcUrl(rpcUrl: string): Promise

Switches to a different blockchain network.

await provider.setRpcUrl('https://eth.llamarpc.com')

getRpcUrl(): string

Returns the current RPC URL.

const rpcUrl = provider.getRpcUrl()

listAccounts(): Promise

Returns the list of accounts.

const accounts = await provider.listAccounts()

getRpcProvider(): Promise

Returns the underlying ethers JsonRpcProvider.

const rpcProvider = await provider.getRpcProvider()

request(args: { method: string; params?: unknown[] }): Promise

Implements EIP-1193 request method.

const accounts = await provider.request({ method: 'eth_accounts' })

const signature = await provider.request({
  method: 'personal_sign',
  params: [message, address],
})

const txHash = await provider.request({
  method: 'eth_sendTransaction',
  params: [{ to: '0x...', value: '0x...' }],
})

Supported RPC Methods

Credenza EVM provider supports the following RPC methods:

  • Account Methods:

    • eth_requestAccounts / eth_accounts

    • personal_sign / eth_sign

    • eth_signTypedData / eth_signTypedData_v4

  • Transaction Methods:

    • eth_signTransaction

    • eth_sendTransaction / eth_sendRawTransaction

  • Standard Methods:

    • All other standard Ethereum JSON-RPC methods are forwarded to the RPC provider.

Example

Here's an example of using CredenzaProvider with ethers.js:

import { CredenzaProvider, ethers } from '@credenza3/evm-provider'

const provider = new CredenzaProvider({
  rpcUrl: 'https://eth.llamarpc.com',
  accessToken: 'your-token',
  env: 'prod',
})

const ethersProvider = new ethers.BrowserProvider(provider)
const signer = await ethersProvider.getSigner()

const tx = await signer.sendTransaction({
  to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
  value: ethers.parseEther('0.01'),
})

await tx.wait()