# @glif/filecoin-wallet-provider

> a javascript package to send filecoin to addresses

Latest version **4.0.0** (published 2025-04-25) · (Apache-2.0 OR MIT) license · 0 weekly downloads

## Install

```sh
npm install @glif/filecoin-wallet-provider
pnpm add @glif/filecoin-wallet-provider
yarn add @glif/filecoin-wallet-provider
bun add @glif/filecoin-wallet-provider
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-04-25 |
| First published | 2020-10-05 |
| Weekly downloads | 0 |
| License | (Apache-2.0 OR MIT) |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 645 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Infinite Scroll <squad@infinitescroll.org> (https://infinitescroll.org) |
| Maintainers | schwartzz8990, bret, glifbot |

## Links

- npm: https://www.npmjs.com/package/@glif/filecoin-wallet-provider
- Repository: https://github.com/glifio/modules/tree/primary/packages/filecoin-wallet-provider
- npm.io page: https://npm.io/package/@glif/filecoin-wallet-provider

## Dependencies (11)

- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [bignumber.js](https://npm.io/package/bignumber.js.md) 9.0.1
- [@glif/filecoin-number](https://npm.io/package/@glif/filecoin-number.md) ^4.0.0
- [@glif/filecoin-address](https://npm.io/package/@glif/filecoin-address.md) ^4.0.0
- [@glif/filecoin-message](https://npm.io/package/@glif/filecoin-message.md) ^4.0.0
- [@ledgerhq/hw-transport](https://npm.io/package/@ledgerhq/hw-transport.md) ^6.31.4
- [@zondax/ledger-filecoin](https://npm.io/package/@zondax/ledger-filecoin.md) ^2.0.4
- [@chainsafe/filsnap-types](https://npm.io/package/@chainsafe/filsnap-types.md) ^2.1.2
- [@glif/filecoin-rpc-client](https://npm.io/package/@glif/filecoin-rpc-client.md) ^4.0.0
- [@ledgerhq/hw-transport-webhid](https://npm.io/package/@ledgerhq/hw-transport-webhid.md) ^6.30.0
- [@zondax/filecoin-signing-tools](https://npm.io/package/@zondax/filecoin-signing-tools.md) ^0.18.6

## Recent versions

- 4.0.0 (latest) — 2025-04-25
- 3.0.15 — 2024-09-10
- 3.0.12 — 2024-08-22
- 3.0.8 — 2024-06-26
- 3.0.7 — 2024-06-25
- 3.0.6 — 2024-06-13
- 3.0.5 — 2024-05-09
- 3.0.4 — 2024-02-29
- 3.0.3 — 2024-02-21
- 3.0.2 — 2024-02-06
- 3.0.1 — 2024-02-06
- 3.0.0 — 2024-01-15
- 2.0.74 — 2023-12-06
- 2.0.72 — 2023-11-29
- 2.0.71 — 2023-11-24
- … 112 more at https://npm.io/package/@glif/filecoin-wallet-provider/versions

## README

# Filecoin wallet provider

## :warning: UNMAINTAINED PACKAGE :warning:

This package is no longer maintained. We highly recommend looking for alternative solutions, such as:

- [iso-filecoin](https://www.npmjs.com/package/iso-filecoin) for general Filecoin wallet / address support
- [filsnap-adapter](https://www.npmjs.com/package/filsnap-adapter) for Metamask Filsnap support
- [@zondax/ledger-filecoin](https://www.npmjs.com/package/@zondax/ledger-filecoin) for Ledger support
- [Wagmi](https://wagmi.sh) for Ethereum wallet support

--- 

This wallet provider module is inspired as a combination between [MetaMask's keyring controller](https://github.com/MetaMask/KeyringController) and [web3.js](https://github.com/ethereum/web3.js/). It's experimental so it's likely that it will change, drastically. Below is a description of our design decisions, how it's working, and development plan over the coming weeks/months.

## Usage

```js
import Filecoin, {
  LocalNodeProvider,
} from '@glif/filecoin-wallet-provider'

const config = {
  apiAddress: process.env.API_ADDRESS // defaults to 'http://127.0.0.1:1234/rpc/v0',
  token: process.env.LOTUS_JWT_TOKEN, // required
}

const filecoin = new Filecoin(new LocalNodeProvider(config), config)
```

### Methods:

##### getBalance

Returns a promise that resolves to a javascript [bignumber.js](https://github.com/MikeMcl/bignumber.js/) object with the accounts balance:

```js
const config = {
  apiAddress: process.env.API_ADDRESS // defaults to 'http://127.0.0.1:1234/rpc/v0',
  token: process.env.LOTUS_JWT_TOKEN, // required
}
const filecoin = new Filecoin(new LocalNodeProvider(config), config)

const balance = await filecoin.getBalance(
  't1jdlfl73voaiblrvn2yfivvn5ifucwwv5f26nfza',
)
console.log(balance.toString())
// 1000000000000
```

#### getNonce

```js
const config = {
  apiAddress: process.env.API_ADDRESS // defaults to 'http://127.0.0.1:1234/rpc/v0',
  token: process.env.LOTUS_JWT_TOKEN, // required
}
const filecoin = new Filecoin(new LocalNodeProvider(config), config)

const nonce = await filecoin.getNonce(
  't1jdlfl73voaiblrvn2yfivvn5ifucwwv5f26nfza',
)
console.log(nonce)
// returns a number representing the nonce
```

##### sendMessage

Takes a signed message, and resolves a promise whne the transaction is completed (note in the future this should resolve to the SignedMessage `cid`).

```js
const config = {
  apiAddress: process.env.API_ADDRESS // defaults to 'http://127.0.0.1:1234/rpc/v0',
  token: process.env.LOTUS_JWT_TOKEN, // required
}
const filecoin = new Filecoin(new LocalNodeProvider(config), config)

// note, see section below on signedMessages
await filecoin.sendMessage(signedMessage)
```

#### Wallet methods exposed from the Provider class (more info below on Provider class)

```js
const config = {
  apiAddress: process.env.API_ADDRESS // defaults to 'http://127.0.0.1:1234/rpc/v0',
  token: process.env.LOTUS_JWT_TOKEN, // required
}
const filecoin = new Filecoin(new LocalNodeProvider(config), config)

await filecoin.wallet.sign(message) // returns a signed message
await filecoin.wallet.getAccounts() // ['t1jdlfl73voaiblrvn2yfivvn5ifucwwv5f26nfza', 't1hvuzpfdycc6z6mjgbiyaiojikd6wk2vwy7muuei']
await filecoin.wallet.newAccount() // 't1jdlfl73voaiblrvn2yfivvn5ifucwwv5f26nfza'
```

### Provider class

The Filecoin class takes a required "provider" object that implements 3 methods. It should be easy to create a Provider class for Ledger, Trust, wasm based signing libs...etc.

The below examples show how the Provider class should function using the `LocalNodeProvider` as an example.

##### newAccount

Returns a promise that resolves to the Filecoin address of a new account

```js
const provider = new LocalNodeProvider({
  apiAddress: 'http://127.0.0.1:1234/rpc/v0',
  token: 'your_lotus_jwt_',
})

const newAccount = await provider.newAccount()
console.log(newAccount)
// 't1jdlfl73voaiblrvn2yfivvn5ifucwwv5f26nfza'
```

##### getAccounts

Returns a promise that resolves to an array of Filecoin addresses

```js
const provider = new LocalNodeProvider({
  apiAddress: 'http://127.0.0.1:1234/rpc/v0',
  token: 'your_lotus_jwt_',
})

const accounts = await provider.getAccounts()
console.log(accounts)
// ['t1jdlfl73voaiblrvn2yfivvn5ifucwwv5f26nfza', 't1hvuzpfdycc6z6mjgbiyaiojikd6wk2vwy7muuei']
```

##### sign

Returns a promise that resolves to a Filecoin [signedMessage]()

```js
const provider = new LocalNodeProvider({
  apiAddress: 'http://127.0.0.1:1234/rpc/v0',
  token: 'your_lotus_jwt_',
})

// message is a proper Filecoin message, see section below on messages for more details

const signedMsg = await provider.sign(path, message)
console.log(signedMsg)
/*
{
  "jsonrpc":"2.0",
  "result":
    {
      "Message": {
        "To":"t1hvuzpfdycc6z6mjgbiyaiojikd6wk2vwy7muuei",
        "From":"t1t5gdjfb6jojpivbl5uek6vf6svlct7dph5q2jwa",
        "Nonce":0,
        "Value":"1000",
        "GasPrice":"3",
        "GasLimit":"1000",
        "Method":0,
        "Params":""
      },
      "Signature": {
        "Type":"secp256k1",
        "Data":"CGZgFHeA5g38txFq6ojwh63wlFGKhNl/ZUZPgTGfNB1IStobmY4VucPa/KteaxJjhFlfm/DBCjTqzhzFK+tKuwE="
      }
    },
  "id":1
}
*/
```

### Design decisions & future

At a high level, a simple wallet relies on 2 types of functions:
(1) methods that require access to private keys
(2) methods that do not require access to private keys

For example, `signMessage` and `getAccounts` are two methods that would require access to a private key, whereas `getBalance`, `getNonce`, and `sendSignedMessage` do not rely on having access to private keys (these are all made up method names).

This naturally lends itself to an architecture that should allow developers to "plug-and-play" their own modules that handle "private key methods", and not have to worry about re-implementing their own "non-private key methods". In other words, a developer should be able to do something like this:

```js
const Filecoin = require('@glif/filecoin-wallet-provider')

const filecoin = new Filecoin()

await filecoin.addWalletProvider(new LedgerWallet())
await filecoin.addWalletProvider(new SimpleJSWallet())

const accounts = await filecoin.listAccounts()
// ['t1jdlfl73voaiblrvn2yfivvn5ifucwwv5f26nfza', 't1hvuzpfdycc6z6mjgbiyaiojikd6wk2vwy7muuei']
// Returns accounts from both wallet types
```

Ideally, each Wallet Class in the above example will follow a simple interface and exposes a few functions, similar to MetaMask's [Keyring Class Protocol](t1hvuzpfdycc6z6mjgbiyaiojikd6wk2vwy7muuei). We could match this interface with the `Wallet` methods in the [Lotus jsonrpc](https://github.com/filecoin-project/lotus/blob/master/api/api_full.go) (with the exception of `balance` and `list` because those do not need access to underlying private keys).

---
_Source: https://npm.io/package/@glif/filecoin-wallet-provider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
