ChainSafe / metamask-snap-polkadot

Metamask plugin for interacting with Polkadot dapps and other Substrate based chains.
Apache License 2.0
84 stars 61 forks source link

Missing a calling example for call pallet method #230

Closed BurnWW closed 4 months ago

BurnWW commented 5 months ago

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.

irubido commented 5 months ago

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
                    }
                }
            }
        }
    }
})