Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@keystonehq/polkadotsnap) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Polkadot Snap
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
- Enable
Polkadot Snap
in your dapp.
const result: boolean = await ethereum.request({
method: 'wallet_enable',
params: [
{
wallet_snap: {'npm:@keystonehq/polkadotsnap': {}},
},
],
});
- 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'
}
}
}]
});
- Get a Polkadot Account.
const result: string = await ethereum.request({
method: 'wallet_invokeSnap',
params: [
"npm:@keystonehq/polkadotsnap",
{
method: 'polkadot_getAccount'
},
],
});
- Sign Transaction.
const result: { txId: string, txHex: string } = await ethereum.request({
method: 'wallet_invokeSnap',
params: [
snapId,
{
method: 'polkadot_signPayloadJson',
params: {
payload: u8aToHex(actualPayload)
}
},
],
})
- 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.