This function initializes WalletConnect and start listening to the events.
awaitwcController.initialize();
Listen to events
Listen to connection event:
This event will be triggered when any dApp initiates a connection request.
// Listen to the connection requestwcController.onConnectionRequest(connectionReqCB);// Sample connectionReqCBfunctionconnectionReqCB({ id, params }) {constdAppName=params.proposer.metadata.name;constdAppIcon=params.proposer.metadata.icons[0];// ...show the connect wallet UI}// Accept the connection requestawaitwcController.acceptSessionProposal({ id, params });// Reject the connection requestawaitwcController.rejectSessionProposal({ id });
Listen to dApp function calls:
This event will be triggered when any dApp initiates any function call
// Listen to the function call eventwcController.onFunctionRequest(functionReqCB);// Sample functionReqCBfunctionfunctionReqCB({ topic, params, id }) {constmethod=params.request.method;constargs=params.request.params;constchainId=params.chainId;// The screen to be displayed will depend on the value of method parameter.if (method ==='eth_sign') {constmessage === args[1];// Open the message sign UI with the message } elseif (method ==='personal_sign') {constmessage === args[0];// Open the message sign UI with the message } elseif (method ==='eth_sendTransaction') {const { to,value,data,from,gas } = args[0];consttransaction= { to, value, data, from, gasLimit };// Use the above parameters to populate the transaction screen }}