> For the complete documentation index, see [llms.txt](https://docs-priv.tria.so/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-priv.tria.so/reference/onboarding-and-wallet-sdk/tria-sdk-web-internal/walletconnect-controller.md).

# WalletConnect Controller

### Create an instance

```typescript
const wcController = new WCController({
        baseUrl,
        walletType,
        selectedChainName,
        environment = "mainnet",
        sessionSignatures,
        currentAccount,
        customAuthMethod,
        accessToken,
        sentryDns,
        aa,
        selectedWallet,
}: TriaArgs);

export type TriaArgs = {
  baseUrl: string;
  sentryDns?: string;
  walletType?: WalletType;
  selectedChainName?: ChainName;
  environment?: ENV;
  currentAccount?: IRelayPKP;
  sessionSignatures?: string;
  customAuthMethod?: LitCustomAuthMethod;
  accessToken?: string;
  aa?: AaDetails;
  selectedWallet?: "EOA" | "AA";
};
```

### Initialize

This function initializes WalletConnect and start listening to the events.

```typescript
await wcController.initialize();
```

### Listen to events

#### Listen to connection event:

This event will be triggered when any dApp initiates a connection request.

```typescript
// 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

```typescript
// 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
    }
}
```

To execute the function calls,

<pre class="language-typescript"><code class="lang-typescript"><strong>const response = await wcController.executeFunction({ id, method, params: args, chainIdNamespace: chainId });
</strong></code></pre>
