The @moonup/ethers
package is a utility package that provides a MoonProvider
class and a MoonSigner
class for interacting with Ethereum-based blockchains using the MoonSDK from the @moonup/moon-sdk
package. The MoonProvider
class implements the Provider
and IEthereumProvider
interfaces from the ethers
library, while the MoonSigner
class implements the Signer
and TypedDataSigner
interfaces from the ethers
library.
To use the @moonup/ethers
package, you need to install it and import the MoonProvider
and MoonSigner
classes.
{% tabs %} {% tab title="npm" %}
npm install @moonup/ethers
{% endtab %}
{% tab title="yarn" %}
yarn add @moonup/ethers
{% endtab %}
{% tab title="pnpm" %}
pnpm add @moonup/ethers
{% endtab %} {% endtabs %}
To import the MoonProvider
and MoonSigner
classes, you can use the following code:
import { MoonProvider, MoonSigner } from '@moonup/ethers';
The MoonProvider
class is a provider for interacting with Ethereum-based blockchains using the MoonSDK. It can be used to sign messages, transactions, and typed data using the MoonSDK, and it implements the Provider
and IEthereumProvider
interfaces from the ethers
library.
To create a new instance of the MoonProvider
class, you need to provide a configuration object that contains the following properties:
SDK
(MoonSDK): An instance of the MoonSDK.address
(string): The Ethereum address of the account.chainId
(number): The ID of the Ethereum chain.
Here's an example of how to create a new instance of the MoonProvider
class:
import { MoonSDK } from '@moonup/moon-sdk';
import { MoonProvider } from '@moonup/ethers';
const SDK = new MoonSDK({ /* your configuration */ });
const address = '0xYourEthereumAddress';
const chainId = 1; // mainnet
const provider = new MoonProvider({ SDK, address, chainId });
Documentation here:
The MoonSigner
class is a signer for signing messages, transactions, and typed data using the MoonSDK. It implements the Signer
and TypedDataSigner
interfaces from the ethers
library.
To create a new instance of the MoonSigner
class, you need to provide a configuration object that contains the following properties:
SDK
(MoonSDK): An instance of the MoonSDK.address
(string): The Ethereum address of the account.chainId
(number): The ID of the Ethereum chain.
Here's an example of how to create a new instance of the MoonSigner
class:
import { MoonSDK } from '@moonup/moon-sdk';
import { MoonSigner } from '@moonup/ethers';
const SDK = new MoonSDK({ /* your configuration */ });
const address = '0xYourEthereumAddress';
const chainId = 1; // mainnet
const signer = new MoonSigner({ SDK, address, chainId });
Documentation here:
- The
MoonProvider
class can be connected to aMoonSigner
instance using thegetSigner
method. - The
MoonSigner
class can be connected to aMoonProvider
instance using theconnect
method. - The
MoonProvider
class and theMoonSigner
class can be used with otherethers
classes and functions, such asContract
,Wallet
, andutils
. - The
MoonProvider
class and theMoonSigner
class are compatible with the Ethereum JSON-RPC API, which means that they can be used with other Ethereum clients and tools that support JSON-RPC. - The
MoonProvider
class and theMoonSigner
class are designed to be used with the MoonSDK, which is a software development kit for building decentralized applications on the Moonbeam and Moonriver networks. However, they can also be used with other Ethereum-based blockchains that support the Ethereum JSON-RPC API.