# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-priv.tria.so/reference/onboarding-and-wallet-sdk/tria-sdk-web-internal/walletconnect-controller.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
