Pockie
  • Pockie Wallet: Easy Crypto Management
  • 🐣Get started with Pockie
    • Trade on Pockie
      • Trade
      • Resume a Paused Trade
    • Trade on Other DApps
  • 💻For developers
    • Pockie Provider API
    • JSON-RPC API
    • Wallet Interoperability
  • 🙋Need Help?
    • FAQs
    • Fee Policy
    • Inquiry and Feedback
    • 한국어 가이드 (Guide in Korean)
Powered by GitBook
On this page
  • Methods
  • wallet_getPermissions
  • wallet_requestPermissions
  • wallet_switchEthereumChain
  • wallet_watchAsset
  • Methods Not Supported
  1. For developers

JSON-RPC API

PreviousPockie Provider APINextWallet Interoperability

Last updated 1 year ago

Pockie wraps the JSON-RPC API using the window.pockie.request(args) provider method.

For detailed information on standard Ethereum RPC methods, refer to the . Every RPC method request can potentially return an error. Therefore, error handling is mandatory each time window.pockie.request(args) is called.

Example using the eth_chainId RPC method:

window.pockie.request({ method: 'eth_chainId' })
    .then((chainId) => {
        console.log('Response:', chainId);
    }).catch((error) => {
        if (error.code === 4001) {
            // EIP-1193 userRejectedRequest error
            console.log('Please connect to MetaMask.');
        } else {
            console.error(error);
        }
    });

Use window.pockie.request(args) as per the guidance in the .

Methods

wallet_getPermissions

Retrieves the current wallet's permission information from the requester.

window.pockie.request({ method: 'wallet_getPermissions' })
    .then((result) => {
        console.log('Response:', result);
    });

This gives information about the permissions linked to DApps in the wallet. If the requester has no permissions, the result array will be empty.

wallet_requestPermissions

Requests permissions from the user. Currently, only eth_accounts requires permission requests. This request triggers a Pockie popup. Permission requests should only be made in response to a direct user action, like a button click.

window.pockie
    .request({
        method: 'wallet_requestPermissions',
        params: [{ eth_accounts: {} }],
    })
    .then((permissions) => {
        const accountsPermission = permissions.find(
            (permission) => permission.parentCapability === 'eth_accounts'
        );
        if (accountsPermission) {
            console.log('eth_accounts permission successfully requested!');
        }
    })
    .catch((error) => {
        if (error.code === 4001) {
            // EIP-1193 userRejectedRequest error
            console.log('Permissions needed to continue.');
        } else {
            console.error(error);
        }
    });

wallet_switchEthereumChain

Prompts the user to switch to the chain with the specified chain ID. This method should only be invoked in response to a direct user action. Pockie will reject requests if:

  • The chain ID is incorrect.

  • Pockie does not support chains with the specified chain ID.

This method is defined by EIP-3326.

await pockie.request({
    method: 'wallet_switchEthereumChain',
    params: [{ chainId: '0x5' }],
});

wallet_watchAsset

Requests the user to track a specified token in Pockie.

This allows DApp developers to request the user to track tokens in their wallet at runtime. This method is specified by EIP-747.

pockie
    .request({
        method: 'wallet_watchAsset',
        params: {
            type: 'ERC20',
            options: {
                address: '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
                symbol: 'FOO',
                decimals: 18,
                image: 'https://foo.io/token-image.svg',
            },
        },
    })
    .then((success) => {
        if (success) {
            console.log('FOO successfully added to wallet!');
        } else {
            throw new Error('Something went wrong.');
        }
    })
    .catch(console.error);

Methods Not Supported

  • wallet_addEthereumChain

  • wallet_registerOnboarding

  • wallet_scanQRCode

The above RPC Methods are currently not supported. For more details about Ethereum JSON-RPC, refer to the documentation.

💻
Ethereum Wiki
Ethereum Wiki
MetaMask API