Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

API Documentation

mace edited this page Jul 30, 2020 · 17 revisions

Filecoin Snap API

configure
configure(configuration: Partial<SnapConfig>): Promise<void>;

Configures snap for the specific network. It is possible to send custom configuration or select one from a set of predefined configurations by defining specific network.

There are two predefined configurations for testnet "t" and for mainet "f". If selecting a predefined configuration only network property is required.

export interface SnapConfig {
  derivationPath: string;
  token: string;
  network: FilecoinNetwork;
  rpcUrl: string;
  unit: UnitConfiguration;
}

It is also possible to choose a predefined configuration and only change some specific properties. In the example SnapConfig below we selected predefined configuration for testnet network and only changed URL for RPC endpoint (rpcUrl), all other properties will be the same as in predefined configuration for testnet network.


getPublicKey
getPublicKey(): Promise<string>

Returns the public key for the generated account.


getAddress
getAddress(): Promise<string>

Returns address for the generated account.


getBalance
getBalance(): Promise<string>

Return balance for the generated account.


exportPrivateKey
exportPrivateKey(): Promise<string>

Return private key for the generated account.

This method will invoke Metamask prompt to confirm action


Messages

Sending a message is two-step process (sign message, send message). First, create SignedMessage using signMessage method then send signed message using sendMessage method.

signMessage
signMessage(message: PartialMessage): Promise<SignedMessage>
export interface PartialMessage {
  to: string;
  value: string;
  gaslimit?: number;
  gasprice?: string;
}

signMessageRaw
signMessageRaw(message: string): Promise<string>

sendMessage
sendMessage(signedMessage: SignedMessage): Promise<BlockInfo>
export interface SignedMessage {
  message: Message;
  signature: {
    data: string;
    type: number;
  };
}

getMessages
getMessages(): Promise<MessageStatus[]>
export interface MessageStatus {
  message: Message;
  serialized: string;
  block: {
    cid: string;
  };
}
export interface Message {
  to: string;
  from: string;
  nonce: number;
  value: string;
  gasprice: string;
  gaslimit: number;
  method: number;
  params?: [];
}

Clone this wiki locally