evm-provider.js
implements a web3 provider which can interact with the Reef chain EVM.
It can also be used as a Substrate provider to query or to interact with the Reef chain using the same calls as in the Polkadot.js.
To create a Provider
instance, use the following code:
import { options } from "@reef-defi/api";
import { Provider } from "@reef-defi/evm-provider";
import { WsProvider } from "@polkadot/api";
const provider = new Provider(
options({
provider: new WsProvider("ws://localhost:9944")
})
);
with this object you can interact with the Substrate chain.
Most of the api of evm-provider.js
is compatible with ethers.js
. If you are not familiar with ethers.js, you can start by looking at its documentation.
The Provider provides some api for interacting with nodes and is an instance of ethers.js
AbstractProvider.
new Provider( apiOptions )
apiOptions has the same parameters as when creating an instance of apiPromise for polkadot.js
The Wallet class inherits Signer and can sign transactions and messages using a private key. When using the wallet for the first time, make sure to always claim the EVM account for the wallet you are using:
wallet.claimDefaultAccount()
before performing any EVM calls otherwise it may lead to InsufficientBalance
errors.
new Wallet( privateKey , provider? , keyringPair? )
privateKey
is the private key of evm's account.provider
is an instance of Provider. keyringPair
is a key pair for polkadot. If the keyringPair
is empty, a key pair will be generated from the
privateKey
.
import { Wallet } from "@reef-defi/evm-provider";
const wallet = new Wallet("0xaa397267eaee48b2262a973fdcab384a758f39a3ad8708025cfb675bb9effc20", provider)
For examples see scripts in hardhat-reef-examples repo.
Install dependencies with yarn
.