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