MoonSigner

Summary

The @moonup/ethers package is a utility package that provides a MoonSigner class for signing messages, transactions, and typed data using the MoonSDK from the @moonup/moon-sdk package. This signer implements the Signer and TypedDataSigner interfaces from the ethers library.

Usage Examples

Here's a basic example of how to use the MoonSigner class:

import { MoonSDK } from '@moonup/moon-sdk';
import { MoonSigner } from '@moonup/ethers';
import { ethers } from 'ethers';

const SDK = new MoonSDK({ /* your configuration */ });
const address = '0xYourEthereumAddress';
const chainId = 1; // mainnet

const signer = new MoonSigner({ SDK, address, chainId });

// Now you can use the signer with ethers
const message = 'Hello, world!';
const signature = await signer.signMessage(message);
console.log(`Signature: ${signature}`);

API Reference

MoonSigner

A signer for signing messages, transactions, and typed data using the MoonSDK.

Constructor

  • config (Object)

    • SDK (MoonSDK): An instance of the MoonSDK.

    • address (string): The Ethereum address of the account.

    • chainId (number): The ID of the Ethereum chain.

  • provider (Provider): An optional provider.

Methods

  • _signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, any>): Signs a typed data object. This method is not implemented and throws an error.

  • updateConfig(config: MoonSignerConfig): Updates the configuration options.

  • connect(provider: Provider): Connects the signer to a provider.

  • signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, string>): Signs a typed data object.

  • getAddress(): Returns the Ethereum address of the account.

  • signMessage(message: BytesLike): Signs a message.

  • broadcastTransaction(signedTransaction: string): Broadcasts a signed transaction.

  • sendTransaction(transaction: TransactionRequest): Signs and broadcasts a transaction.

  • transactionRequestToInputBody(tx: TransactionRequest): Converts a TransactionRequest object to an InputBody object.

  • moonTransactionResponseToTransactions(tx: MoonTransaction): Converts a MoonTransaction object to an array of TransactionData objects.

  • signTransaction(transaction: TransactionRequest): Signs a transaction.

  • getTypedDataDomain(name: string, version: string, chainId: number, verifyingContract: string): Returns a TypedDataDomain object.

  • getTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, string>): Returns a Typed object.

Example

Last updated