-
Notifications
You must be signed in to change notification settings - Fork 34
API Documentation
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.
{
network: "t",
rpcUrl: "test.rpc.url"
}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
Sending a message is two-step process (sign message, send message). First, create SignedMessage using signMessage method then send a signed message using sendMessage method. Additionaly it is possible to estimate gas parameters with calculateGasForMessage method.
calculateGasForMessage
calculateGasForMessage(message: MessageRequest): Promise<MessageGasEstimate>interface MessageRequest {
to: string;
value: string;
gaslimit?: number; // leave empty
gasfeecap?: string; // leave empty
gaspremium?: string; // leave empty
}Returns MessageGasEstimate with estimated values for gas parameters for the provided message, see below.
interface MessageGasEstimate {
gaslimit: number;
gasfeecap: string;
gaspremium: string;
}signMessage
signMessage(message: MessageRequest): Promise<SignedMessage>If gas parameters are left out then they will be filled with estimates (see estimateMessageGas function).
interface MessageRequest {
to: string;
value: string;
gaslimit?: number;
gasfeecap?: string;
gaspremium?: string;
}Returns SignedMessage with all message details and generated signature, see below.
interface SignedMessage {
message: Message;
signature: {
data: string;
type: number;
};
}
interface Message {
to: string;
from: string;
nonce: number;
value: string;
gasprice: string;
gaslimit: number;
method: number;
params?: [];
}signMessageRaw
signMessageRaw(message: string): Promise<string>sendMessage
sendMessage(signedMessage: SignedMessage): Promise<MessageStatus>export interface SignedMessage {
message: Message;
signature: {
data: string;
type: number;
};
}getMessages
getMessages(): Promise<MessageStatus[]>Returns all messages saved inside the snap state (all messages sent through Filecoin snap) as MessageStatus.
interface MessageStatus {
message: Message;
cid: string;
}It holds information about message parameters as Message and a unique code identifier for the message or CID.
interface Message {
to: string;
from: string;
nonce: number;
value: string;
gasprice: string;
gaslimit: number;
method: number;
params?: [];
}// snap is already installed
const api = await metamaskFilecoinSnap.getFilecoinSnapApi();
const toAddress = "t1wnanhvadbski2fru4l4kry3x2hqq4jobzzic6dq"
const amountAttoFIL = "100000"
const gasEstimate = await api.calculateGasForMessage({
to: toAddress,
value: amountAttoFIL,
});
const partialMessage: PartialMessage = {
to: toAddress,
value: amountAttoFIL,
gaslimit: gasEstimate.gaslimit,
gasfeecap: gasEstimate.gasfeecap,
gaspremium: gasEstimate.gaspremium,
}
const signedMessage: SignedMessage = await api.signMessage(partialMessage);
const messageCid = await api.sendMessage(signedMessage);
console.log(`Message sent with cid: ${messageCid["/"]}`);