Skip to content

Getting Started

iso-filecoin is a Filecoin Standard Library that provides a set of lightweight, performant and type-safe Javascript modules.

It provides core utilities, abstractions and types for primitives such as: RPC, Signature, Address, Token, Chain, Wallet and more.

Used by the Metamask Filecoin Wallet and Ledger Live Filecoin app.

Installation

Install the required packages using pnpm. Make sure you have Node.js >= 20 installed.

Terminal window
pnpm add iso-filecoin

If you plan to use React hooks, install iso-filecoin-react as well:

Terminal window
pnpm add iso-filecoin-react

For wallet functionalities (Ledger, Filecoin App), install iso-filecoin-wallets:

Terminal window
pnpm add iso-filecoin-wallets

Project Structure

This project uses a monorepo structure managed by pnpm workspaces. Core libraries reside in the packages/ directory, examples in examples/, and this documentation site in docs/.

.
├── packages/
│ ├── iso-filecoin/ # Core Filecoin library
│ ├── iso-filecoin-react/ # React hooks and context
│ └── iso-filecoin-wallets/ # Wallet adapters
├── examples/ # Usage examples and demos
├── docs/ # This documentation site
├── pnpm-workspace.yaml # Workspace configuration
└── package.json # Root package file

Usage

Here’s a basic example of how to use iso-filecoin to generate a wallet and address:

import * as
import Wallet
Wallet
from 'iso-filecoin/wallet'
const
const mnemonic: string
mnemonic
=
import Wallet
Wallet
.
function generateMnemonic(): string

Generate mnemonic

generateMnemonic
()
const
const account: {
type: import("/opt/buildhome/repo/packages/iso-filecoin/dist/src/signature").SignatureType;
address: import("/opt/buildhome/repo/packages/iso-filecoin/dist/src/types").IAddress;
publicKey: Uint8Array;
path: string;
privateKey: Uint8Array;
}
account
=
import Wallet
Wallet
.
function accountFromMnemonic(mnemonic: string, type: import("/opt/buildhome/repo/packages/iso-filecoin/dist/src/signature").SignatureType, path: string, password?: string, network?: import("/opt/buildhome/repo/packages/iso-filecoin/dist/src/types").Network): {
type: import("/opt/buildhome/repo/packages/iso-filecoin/dist/src/signature").SignatureType;
address: import("/opt/buildhome/repo/packages/iso-filecoin/dist/src/types").IAddress;
publicKey: Uint8Array;
path: string;
privateKey: Uint8Array;
}

Get HD account from mnemonic

@parammnemonic

@paramtype

@parampath

@parampassword

@paramnetwork

accountFromMnemonic
(
const mnemonic: string
mnemonic
,
'SECP256K1',
"m/44'/461'/0'/0/0"
)
const
const address: string
address
=
const account: {
type: import("/opt/buildhome/repo/packages/iso-filecoin/dist/src/signature").SignatureType;
address: import("/opt/buildhome/repo/packages/iso-filecoin/dist/src/types").IAddress;
publicKey: Uint8Array;
path: string;
privateKey: Uint8Array;
}
account
.
address: IAddress
address
.
IAddress.toString: () => string
toString
()
// 'f1...'

Here’s how to create a message:

import {
class Message

Filecoin Message class

Message
} from 'iso-filecoin/message'
import {
class Token

Class to work with different Filecoin denominations.

Token
} from 'iso-filecoin/token'
const
const msg: Message
msg
= new
new Message(msg: PartialMessageObj): Message

@parammsg

Message
({
from: string
from
: 'f1...',
to: string
to
: 'f4...',
value: string
value
:
class Token

Class to work with different Filecoin denominations.

Token
.
Token.fromFIL(val: Value): Token

@paramval

fromFIL
(1).
Token.toAttoFIL(): Token
toAttoFIL
().
Token.toString(base?: number | undefined): string

Serialize the number to a string using the given base.

@parambase

toString
()
})

Playground

Play with all the iso-filecoin modules in this StackBlitz example:

Check the source code here.

Further Resources