Using the EIP-1193 Provider
portal.provider is compliant with the EIP-1193 specification and can be used with libraries like ethers.js and web3.js. This guide will walk you through using portal.provider with ethers.js.
Here's a code snippet that sends a transaction with ethers.js
backed by portal.provider
.
Let's break it down.
First, portal.updateChain
is used to bind portal.provider
to a specific EVM chain. It takes the chain's CAIP-2 reference, for example 11155111
for Sepolia, as argument.
portal.provider
is then supplied to ethers.js BrowserProvider
. The returned object is an ethers.js Provider
and supports read-only requests to the chain. To be able to send a transaction we need a Signer
which ethersProvider.getSigner
returns.
The next bit of code is ethers.js
specific and uses ethersSigner.sendTransaction
to send 0.001 ETH to the address specified. The code also waits for the transaction to be mined.
That's all! We've successfully used portal.provider
and ethers.js
to send a transaction!
Last updated
Was this helpful?