Filecoin.js

Filecoin.js

  • Documentation
  • API Reference
  • GitHub

›Setup Wallet Providers

Getting started

  • Introduction
  • Adding Filecoin.js
  • Guides example
  • WS vs HTTP

Setup Wallet Providers

  • Setup lotus provider
  • Setup mnemonic provider
  • Setup metamask provider

Using a provider

  • Send message
  • Sign message
  • Verify message
  • Check if message is mined

Extra

  • Payment channels
  • State methods
  • Multisig Wallets

Contributing

  • How to contribute
  • Development workflow

Setup Metamask provider

In order to use Metamask to sign messages you need to use the Filecoin Metamask Snap.

To use this first you need to install the Metamask snaps beta release. To simplify the actual snap install we built a helper which does the work for you:

    const metamaskHelper = new FilecoinJs.MetamaskSnapHelper({ url: __LOTUS_RPC_ENDPOINT__, token: __LOTUS_AUTH_TOKEN__ });
    const err = await metamaskHelper.installFilecoinSnap();

Setup and usage

<script type="text/javascript" src="https://unpkg.com/filecoin.js"></script>
<script type="text/javascript">
(async () => {
    let metamaskAddress;
    const connector = new FilecoinJs.HttpJsonRpcConnector({ url: __LOTUS_RPC_ENDPOINT__, token: __LOTUS_AUTH_TOKEN__ });
    const lotusClient = new FilecoinJs.LotusClient(httpConnector);
    const metamaskHelper = new FilecoinJs.MetamaskSnapHelper({ url: __LOTUS_RPC_ENDPOINT__, token: __LOTUS_AUTH_TOKEN__ });
    const err = await metamaskHelper.installFilecoinSnap();

    const metamaskWalletProvider = new FilecoinJs.MetamaskWalletProvider(lotusClient, metamaskHelper.filecoinApi)

    let metamaskAddress
    try {
        metamaskAddress = await metamaskWalletProvider.getDefaultAddress();
    } catch (e) {
        console.log('metamask error',e);
    }

    console.log(metamaskAddress);

})().then().catch();
</script>
← Setup mnemonic providerSend message →
  • Setup and usage
Docs
Getting StartedAPI Reference
Community
Slack
More
BlogGitHubStar
Copyright © 2022 Filecoin