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
Section titled “Installation”Install the required packages using pnpm
. Make sure you have Node.js >= 20 installed.
pnpm add iso-filecoin
If you plan to use React hooks, install iso-filecoin-react
as well:
pnpm add iso-filecoin-react
For wallet functionalities (Ledger, Filecoin App), install iso-filecoin-wallets
:
pnpm add iso-filecoin-wallets
Project Structure
Section titled “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/
.
Directorypackages/
Directoryiso-filecoin/ Core Filecoin library
- …
Directoryiso-filecoin-react/ React hooks and context
- …
Directoryiso-filecoin-wallets/ Wallet adapters
- …
Directoryexamples/ Usage examples and demos
- …
Directorydocs/ This documentation site
- …
- pnpm-workspace.yaml Workspace configuration
- package.json Root package file
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
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
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
fromFIL(1).Token.toAttoFIL(): Token
toAttoFIL().Token.toString(base?: number | undefined): string
Serialize the number to a string using the given base.
toString()})
Playground
Section titled “Playground”Play with all the iso-filecoin
modules in this StackBlitz example:
Check the source code here.
Further Resources
Section titled “Further Resources”- API Reference
- Examples
- GitHub Repository