metamask-snap-polkadot icon indicating copy to clipboard operation
metamask-snap-polkadot copied to clipboard

Missing a calling example for call pallet method

Open BurnWW opened this issue 1 year ago • 1 comments

The installation and execution went extremely well for me, however, I am uncertain about invoking a custom pallet’s method. Could you please offer an instance of how to properly call a custom pallet?,Thank you very much.

BurnWW avatar Apr 26 '24 00:04 BurnWW

Hi @BurnWW You can use configuration for kusama, polkadot and westend by only passing networkName. All snap rpc method will work in this way. https://github.com/ChainSafe/metamask-snap-polkadot/blob/master/packages/snap/src/configuration/predefined.ts

Optionally you can override it with any custom network, not all rpc methods will work with all rpc providers in this custom configuration.

Westend example

await window.ethereum.request({
    method: "wallet_invokeSnap",
    params: {
        snapId: snapId,
        request: {
            method: "configure",
            params: {
                configuration: {
                    networkName: "westend"
                    }
                }
            }
        }
    }
})

Example Acala

await window.ethereum.request({
    method: "wallet_invokeSnap",
    params: {
        snapId: snapId,
        request: {
            method: "configure",
            params: {
                configuration: {
                    networkName: "acala",
                    wsRpcUrl: "https://rpc.evm.acala.network",
                    addressPrefix: 10,
                    unit: {
                        image: "",
                        symbol: "ACA",
                        decimals: 12
                    }
                }
            }
        }
    }
})

irubido avatar Apr 29 '24 13:04 irubido