Compass Docs
Ask or search…
⌃K

@compass/wallet

This package provides an easy to use wallet class for signing messages and sending transactions with a connected wallet. The wallet class requires an address to initialize and provides methods for signing and transactions.

Usage

import Wallet from "@compass/wallet";

API Reference

class Wallet

Main class of the module, representing a wallet instance.
constructor(address: string)
Create a new wallet instance.
  • address (required, string): The address of the wallet.
Returns a new wallet instance.
wallet.signMessage(message: string)
Sign a message with the wallet.
  • message (required, string): Message to sign.
Returns a Promise that resolves with the signed message.
wallet.signTypedData(domain: any, types: any, value: any)
Sign typed data with the wallet. (v4)
  • domain (required, any): The domain of the typed data.
  • types (required, any): The types of the typed data.
  • value (required, any): The value of the typed data.
Returns a Promise that resolves with the signed typed data.
wallet.sendTransaction(transaction: any)
Send a transaction with the wallet.
  • transaction (required, any): Transaction to send.
Returns a Promise that resolves with the transaction receipt.

Examples

To create a new wallet instance:
import Wallet from "@compass/wallet";
​
export default function() {
const address = '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B';
const wallet = new Wallet(address);
return { wallet };
}
To sign a message with the wallet:
import Wallet from "@compass/wallet";
​
export default async function() {
const address = '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B';
const wallet = new Wallet(address);
const message = 'Hello, World!';
const signedMessage = await wallet.signMessage(message);
return { signedMessage };
}
To sign typed data with the wallet:
import Wallet from "@compass/wallet";
​
export default async function() {
const address = '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B';
const wallet = new Wallet(address);
const domain = {/* ... */};
const types = {/* ... */};
const value = {/* ... */};
const signedData = await wallet.signTypedData(domain, types, value);
return { signedData };
}
To send a transaction with the wallet:
import Wallet from "@compass/wallet";
​
export default async function() {
const address = '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B';
const wallet = new Wallet(address);
const transaction = {/* ... */};
const transactionReceipt = await wallet.sendTransaction(transaction);
return { transactionReceipt };
}
Last modified 7mo ago