Responding To Discover Requests
Overview
It is likely that clients will want to find out the capabilities of your provider before they start interacting with it. Therefore, it is good practice to handle discover request from clients, responding with your provider's supported networks & methods.
Responding to a discover request
Once our provider object has been initialized, we can simply listen to events and respond:
- Javascript
- TypeScript
// initialized provider
provider.onDiscover(({ params }) => {
return {
host: 'https://awesome-wallet.com',
name: 'Awesome Wallet',
networks: [
{
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
genesisId: 'testnet-v1.0',
methods: [
'disable',
'enable',
'post_transactions',
'sign_and_post_transactions',
'sign_transactions',
],
},
{
genesisHash: 'IXnoWtviVVJW5LGivNFc0Dq14V3kqaXuK2u5OQrdVZo=',
genesisId: 'voitest-v1',
methods: [
'disable',
'enable',
'post_transactions',
'sign_and_post_transactions',
'sign_transactions',
],
},
],
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e',
};
});
import type { IAVMWebProviderCallbackOptions } from '@agoralabs-sh/avm-web-provider';
// initialized provider
provider.onDiscover(({ params }: IAVMWebProviderCallbackOptions) => {
return {
host: 'https://awesome-wallet.com',
name: 'Awesome Wallet',
networks: [
{
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
genesisId: 'testnet-v1.0',
methods: [
'disable',
'enable',
'post_transactions',
'sign_and_post_transactions',
'sign_transactions',
],
},
{
genesisHash: 'IXnoWtviVVJW5LGivNFc0Dq14V3kqaXuK2u5OQrdVZo=',
genesisId: 'voitest-v1',
methods: [
'disable',
'enable',
'post_transactions',
'sign_and_post_transactions',
'sign_transactions',
],
},
],
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e',
};
});