Last updated
Last updated
The @moonup/ethers
package is a utility package that provides a MoonProvider
class for interacting with Ethereum-based blockchains using the MoonSDK from the @moonup/moon-sdk
package. This provider 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.
Here's a basic example of how to use the MoonProvider
class:
MoonProvider
A provider for interacting with Ethereum-based blockchains using the MoonSDK.
Constructor
options
(Object)
SDK
(MoonSDK): An instance of the MoonSDK.
address
(string): The Ethereum address of the account.
chainId
(number): The ID of the Ethereum chain.
Methods
request(args: RequestArguments)
: Sends a JSON-RPC request.
updateConfig(options: MoonProviderOptions)
: Updates the configuration options.
connect()
: Connects to the MoonSDK.
disconnect()
: Disconnects from the MoonSDK.
sendAsync(args: RequestArguments, callback: (error: Error | null, response: any) => void)
: Sends a JSON-RPC request asynchronously.
enable()
: Enables the provider.
isMoonProvider()
: Returns true
if the provider is a MoonProvider
.
getChainId()
: Returns the ID of the Ethereum chain.
getSigner()
: Returns the MoonSigner
instance.
getNetwork()
: Returns the network information.
getBlockNumber()
: Returns the current block number.
getGasPrice()
: Returns the current gas price.
getBalance(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag> | undefined)
: Returns the balance of an account.
getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag> | undefined)
: Returns the number of transactions sent from an account.
getCode(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag> | undefined)
: Returns the code of a contract.
getStorageAt(addressOrName: string | Promise<string>, position: BigNumberish | Promise<BigNumberish>, blockTag?: BlockTag | Promise<BlockTag> | undefined)
: Returns the value of a storage slot of a contract.
sendTransaction(signedTransaction: string | Promise<string>)
: Sends a transaction.
call(transaction: Deferrable<TransactionRequest>, blockTag?: BlockTag | Promise<BlockTag> | undefined)
: Calls a contract method.
estimateGas(transaction: Deferrable<TransactionRequest>)
: Estimates the gas required for a transaction.
getBlock(blockHashOrBlockTag: BlockTag | Promise<BlockTag>)
: Returns a block.
getBlockWithTransactions(blockHashOrBlockTag: BlockTag | Promise<BlockTag>)
: Returns a block with its transactions.
getTransaction(transactionHash: string)
: Returns a transaction.
getTransactionReceipt(transactionHash: string)
: Returns a transaction receipt.
getLogs(filter: Filter)
: Returns logs that match a filter.
resolveName(name: string | Promise<string>)
: Resolves an ENS name to an address.
lookupAddress(address: string | Promise<string>)
: Resolves an address to an ENS name.
emit(eventName: EventType, ...args: any[])
: Emits an event.
listenerCount(eventName?: EventType | undefined)
: Returns the number of listeners for an event.
listeners(eventName?: EventType | undefined)
: Returns the listeners for an event.
removeAllListeners(eventName?: EventType | undefined)
: Removes all listeners for an event.
waitForTransaction(transactionHash: string, confirmations?: number | undefined, timeout?: number | undefined)
: Waits for a transaction to be mined.
on(eventName: EventType, listener: Listener)
: Adds a listener for an event.
once(eventName: EventType, listener: Listener)
: Adds a one-time listener for an event.
off(eventName: EventType, listener?: Listener | undefined)
: Removes a listener for an event.
Example