Custom Transport
A function to create a Custom Transport for a Client
The custom Transport accepts an EIP-1193 request function as a parameter. This transport is useful for integrating with injected wallets, wallets that provide an EIP-1193 provider (eg. WalletConnect or Coinbase SDK), or even providing your own custom request function.
Import
import { } from 'viem'Usage
You can use any EIP-1193 compatible Ethereum Provider with the custom Transport:
import { , } from 'viem'
import { } from 'viem/chains'
const = ({
: ,
: (.!)
})Or you can define your own:
import { , } from 'viem'
import { } from 'viem/chains'
import { } from './rpc'
const = ({
: ,
: ({
async ({ , }) {
const = await .request(, )
return
}
})
})Parameters
provider
- Type:
custom
An EIP-1193 request function function.
import { } from './rpc'
const = ({
async ({ , }) {
const = await .request(, )
return
}
})key (optional)
- Type:
string - Default:
"custom"
A key for the Transport.
const = (
.!,
{
: 'windowProvider',
}
)name (optional)
- Type:
string - Default:
"Ethereum Provider"
A name for the Transport
const = (
.!,
{
: 'Window Ethereum Provider',
}
)retryCount (optional)
- Type:
number - Default:
3
The max number of times to retry when a request fails.
const = (.!, {
: 5,
})retryDelay (optional)
- Type:
number - Default:
150
The base delay (in ms) between retries. By default, the Transport will use exponential backoff (~~(1 << count) * retryDelay), which means the time between retries is not constant.
const = (.!, {
: 100,
})Gotchas
- If you are pairing the
customTransport with a Public Client, ensure that your provider supports Public Actions.