@keystonehq/polkadotsnap

0.0.1 • Public • Published

Polkadot Snap

npm version

Polkadot Snap is the application allowing users to directly manage Polkadot within the MetaMask interface. Since Snaps is pre-release software, the alpha version of Polkadot Snap is currently live on Metamask Flask only, a canary distribution for developers that provides access to upcoming features.

*Note: MetaMask Flask is an experimental playground for developers and is not to be confused with the normal MetaMask wallet app.

MetaMask Snaps Introduction

Snaps is a system that allows developers to safely build and expand the capabilities of MetaMask. It is a program that is run in an isolated environment with a limited set of capabilities, that can customize and modify MetaMask's wallet experience for end users. For example, a snap can add new APIs to MetaMask thus adding support for different blockchains or modify existing functionalities using internal APIs.

Additional information can be found here.

Usage

  1. Enable Polkadot Snap in your dapp.
const result: boolean = await ethereum.request({
    method: 'wallet_enable',
    params: [
        {
            wallet_snap: {'npm:@keystonehq/polkadotsnap': {}},
        },
    ],
});
  1. Config the polkadot snap. Currently polkadot | 'kusama' | 'westend' is supported.
const result: string = await ethereum.request({
    method: 'wallet_invokeSnap',
    params: ['npm:@keystonehq/polkadotsnap', {
        method: 'polkadot_configure',
        params: {
            configuration: {
                network: 'polkadot'
            }
        }
    }]
});
  1. Get a Polkadot Account.
const result: string = await ethereum.request({
    method: 'wallet_invokeSnap',
    params: [
        "npm:@keystonehq/polkadotsnap",
        {
            method: 'polkadot_getAccount'
        },
    ],
});
  1. Sign Transaction.
const result: { txId: string, txHex: string } = await ethereum.request({
    method: 'wallet_invokeSnap',
    params: [
        snapId,
        {
            method: 'polkadot_signPayloadJson',
            params: {
                payload: u8aToHex(actualPayload)
            }
        },
    ],
})
  1. Sign Raw Message.
const result: { txId: string, txHex: string } = await ethereum.request({
    method: 'wallet_invokeSnap',
    params: [
        snapId,
        {
            method: 'polkadot_signPayloadRaw',
            params: {
                payload: hexString
            }
        },
    ],
})

Building

Build the snap and test it locally with the following command:

yarn build

Live Example

If you would like to integrate Polkadot Snap into your dapp, you can use the following codes here.

Readme

Keywords

Package Sidebar

Install

npm i @keystonehq/polkadotsnap

Weekly Downloads

2

Version

0.0.1

License

ISC

Unpacked Size

912 kB

Total Files

4

Last publish

Collaborators

  • yu_keyst
  • amalia20220301
  • liyanlance
  • keystoneorg
  • soralit