๐Ÿ”…How to Integrate My dApp with PolkaGate snap

For Developers Only

To connect with the injected Snap, start by adding the @polkagate/extension-dapp package to your dApp. Use web3Enable('your-app-name') to fetch the injected extensions, including PolkaGate Snap. If you only want to enable the Snap and not other extensions, call web3Enable('snapOnly'). After that, you can access your Snap account(s) using web3Accounts(). Below is a simple code example illustrating these processes:

import { web3Accounts, web3Enable } from '@polkagate/extension-dapp';

web3Enable('your-dapp-name').then((extensions) => {
  console.log('All injected extensions:', extensions);
});

web3Accounts().then((accounts) => {
  const account = accounts.find((acc) => acc.meta.source === 'polkagate-snap');
  console.info('Snap account:', account);
});

This integration allows your dApp to interact seamlessly with the PolkaGate snap through the injected information within the window. These are familiar calls if you've worked with other existing Polkadot ecosystem extensions. The rest remains the same.

Last updated