Filecoin.js
A JavaScript (and TypeScript) library for interacting with the Filecoin's Lotus node, with support for external signers.
Install / Use
/learn @filecoin-shipyard/Filecoin.jsREADME
filecoin.js
Status
Unfortunately this project has not seen any meaningful activities since November 2020 and is deemed unmaintained. If you are a user of this project and would like to become a maintainer, please reach out to @smagdali.
~~This repository is currently being updated and will be further updated to support the coming Filecoin VM. Learn more at fvm.filecoin.io~~
A JavaScript (and TypeScript) library for interacting with the Filecoin's Lotus node, with support for external signers.
Documentation
Visit the Filecoin JS Docs.
Installing
Node:
npm install --save filecoin.js
Browser:
<script type="text/javascript" src="https://unpkg.com/filecoin.js"></script>
<!-- window.FilecoinJs object contains the library exports -->
Using
Node JavaScript/TypeScript:
import { HttpJsonRpcConnector, MnemonicWalletProvider } from 'filecoin.js';
(async () => {
const connector = new HttpJsonRpcConnector({ url: __LOTUS_RPC_ENDPOINT__, token: __LOTUS_AUTH_TOKEN__ });
const hdWalletMnemonic = 'equip ... young';
const hdWalletPassword = '...';
const hdDerivationPath = `m/44'/461'/0'/0/0`;
const walletProvider = new MnemonicWalletProvider(
connector,
hdWalletMnemonic,
hdWalletPassword,
hdDerivationPath
);
const myAddress = await walletProvider.getDefaultAccount();
console.log(myAddress);
// f1zx43cf6qb6rd...
})().then().catch();
Browser:
<script type="text/javascript" src="https://unpkg.com/filecoin.js"></script>
<script type="text/javascript">
(async () => {
const connector = new FilecoinJs.HttpJsonRpcConnector({ url: __LOTUS_RPC_ENDPOINT__, token: __LOTUS_AUTH_TOKEN__ });
const hdWalletMnemonic = 'equip ... young';
const hdWalletPassword = async () => await window.prompt(),;
const hdDerivationPath = `m/44'/461'/0'/0/0`;
const walletProvider = new FilecoinJs.MnemonicWalletProvider(
connector,
hdWalletMnemonic,
hdWalletPassword,
hdDerivationPath
);
const myAddress = await walletProvider.getDefaultAccount();
console.log(myAddress);
// f1zx43cf6qb6rd...
})().then().catch();
</script>
Examples
Sending some FIL to someAddress:
const message = await walletProvider.createMessage({
From: myAddress,
To: someAddress,
Value: new BigNumber(42),
});
const msgCid = await walletProvider.sendSignedMessage(
await walletProvider.signMessage(message)
);
Check out the tests or examples folders for more usage examples.
Documentation
As with the rest of the library, the documentation is WIP. As it evolves the documentation site will be updated.
Contributing
Feel free to join in. All welcome. Open an issue!
License
Dual-licensed under MIT + Apache 2.0
Related Skills
openhue
347.2kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
347.2kElevenLabs text-to-speech with mac-style say UX.
weather
347.2kGet current weather and forecasts via wttr.in or Open-Meteo
Better-Prompt
Publishable Prompt Engineering skill package that compiles a user request into a ready-to-use high-quality Prompt, with support for diagnosis, module injection, debugging, and evaluation.
