1.5.4 • Published 3 months ago

filsnap v1.5.4

Weekly downloads
-
License
(Apache-2.0 AND M...
Repository
github
Last release
3 months ago

filsnap

NPM Version License: MIT License Snap

Connect to Filecoin dapps using Metamask. Manage Filecoin accounts, send FIL to Native and FEVM accounts and enable FEVM transaction insights.

Usage

You can install and use filsnap using the Metamask provider.

import { getProvider } from 'filsnap-adapter'

const provider = await getProvider()

// Install filsnap
try {
  const result = await provider.request({
    method: 'wallet_requestSnaps',
    params: {
      'npm:filsnap': {
        version: '^0.4.0', // Optional, defaults to latest
      },
    },
  })

  console.log(result)
  /**
{
  'npm:filsnap': {
    version: '1.0.0',
    id: 'npm:filsnap',
    enabled: true,
    blocked: false,
  },
}
   */
} catch (error) {
  console.log(error)
}
import { getProvider } from 'filsnap-adapter'

const provider = await getProvider()
// Get filsnap metadata
const result = await provider.request({ method: 'wallet_getSnaps' })

console.log(result)
/**
{
  'npm:filsnap': {
    version: '1.0.0',
    id: 'npm:filsnap',
    enabled: true,
    blocked: false,
  },
}
 */
import { getRequestProvider } from 'filsnap-adapter'

const provider = await getRequestProvider()
// Get filsnap metadata
const result = await provider.request({
  method: 'wallet_invokeSnap',
  params: { snapId: 'npm:filsnap', method: 'fil_getBalance' },
})

console.log(result)
/**
{
  result: '100699819802794525019',
  error: null
}
 */

We recommend using filsnap-adapter to interact with filsnap for a simpler interface. Check the full API documentation here.

RPC Methods

  • fil_getConfig - Get the configuration of the snap.
  • fil_setConfig - Set the configuration of the snap.
  • fil_configure - Configure the snap.
  • fil_getAccount - Get the account of the connected account.
  • fil_signMessage - Sign a message with the connected account.
  • fil_sign- Sign arbitrary data with the connected account.
  • fil_getBalance - Get the balance of the connected account.
  • fil_getGasForMessage - Get the gas for a message.
  • fil_sendMessage - Send a message.
  • fil_exportPrivateKey - Export the private key of the connected account.
  • fil_signMessageRaw - Sign a raw message (string) with the connected account.
  • fil_getAddress - Get the address of the connected account.
  • fil_getPublicKey - Get the public key of the connected account.
  • fil_getAccountInfo - Get the account info of the connected account.

Check the full RPC methods documentation here.

Architecture

sequenceDiagram
    participant Dapp
    box rgb(76, 86, 106) Metamask Extension
    participant Metamask
    participant filsnap
    end
    Dapp-)Metamask: connect('npm:filsnap', '0.4.0')
    Note over Dapp,Metamask: `wallet_requestSnaps`
    Metamask--> Metamask: Install filsnap
    Metamask--)filsnap: Connect Dapp to filsnap
    activate filsnap
    filsnap--)Metamask: Connected
    Metamask-)Dapp: filsnap metadata
    Dapp-)filsnap: configure({network: 'mainnet'})
    Note over Dapp,Metamask: `wallet_invokeSnap` method `fil_configure`
    filsnap-)Dapp: filsnap configuration
    Dapp-)filsnap: getBalance()
    Note over Dapp,Metamask: `wallet_invokeSnap` method `fil_getBalance`
    filsnap-)Dapp: 100 FIL (balance)
    deactivate filsnap

Current limitations

  • Multiple accounts are not supported yet. Only the first account is used.
    • One workaround currently supported is to use the derivation path from the configuration to get the account you want to use.

Recommendations for future work

  • Add support for multiple accounts.
  • Sync with Metamask team to work through the limitations.

Development

// run snapper before publishing
pnpm exec snapper --path . --ignoreDetectors ESLinting 

Contributing

Read contributing guidelines here.

Open in GitHub Codespaces

License

Dual-licensed: MIT, Apache Software License v2, by way of the Permissive License Stack.

1.5.4

3 months ago

1.5.3

3 months ago

1.5.1

4 months ago

1.4.4

5 months ago

1.4.3

5 months ago

1.4.2

5 months ago

1.4.1

5 months ago

1.4.0

5 months ago

1.3.0

6 months ago

1.2.0

8 months ago

1.1.0

10 months ago

1.0.3

12 months ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

0.5.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.4.1

2 years ago

0.3.2

2 years ago

0.4.0

2 years ago

0.1.3

2 years ago

0.0.1

2 years ago