# Generate

The provider comes with a `generate` action that creates a connection URI and deeplink for custom wallet buttons and actions.&#x20;

```typescript
// Some where within your codebase...

const { actions } = useProvider();

const response = await actions.generate()
```

#### Input (Optional)

This action does not require any inputs (similar to the \`connect\` action), but allows for a \`walletId\` parameter which will automatically generate a custom URI and deeplink for a targeted wallet.&#x20;

{% hint style="info" %}
The `walletId` passed into the generate action has to match one of the wallet provided in the provider conifuration `walletDetails`. If not, the action will fallback to default wc syntax for the generated uri and deeplink (ie: wc://)
{% endhint %}

```typescript
{
    walletId?: string;    
    chain?: string;
    walletId?: string;
    pairing?: { topic: string };
    openModal?: boolean;
}
```

#### Return Type

The method will resolve if a connection is re-established by the user.

```typescript
Promise<{
    uri: string;
    deeplink: string;
}>
```

#### Example usage:

```jsx
// File: ./src/app/component.tsx
'use client';

import * as React from 'react';
import { useProvider } from './page';

import core from '@joey-wallet/wc-client/core';

const wallets = core.constants.wallets;

export default function Component() {
  const { actions, session, accounts } = useProvider();

const handleGenerate = () => {
  const generate = await actions.generate({
    walletId: wallets.joey.projectId,
  });

  // Get raw uri from generate function and manufacture deeplink for mobile
  const uri = generate.data?.uri;
  const deeplink = generate.data?.deeplink;

  if (isMobile) {
    const openDeeplink = (link: string) => (window.location.href = link);
    if (deeplink) openDeeplink(deeplink);
  } else {
    openModal && triggerModal(true);
  }

  return new Promise((resolve, reject) => {
    // Listen for connect event to capture session and URI
    const onConnect = () => {
      resolve(true);
      // Clean up listener
      provider.off('connect', onConnect);
    };

    // Handle provider errors
    const onError = () => {
      triggerModal(false); // Close modal on error
      reject(new Error(`Failed to connect`));
      provider.off('error', onError);
    };

    // Register event listeners
    provider.on('connect', onConnect);
    provider.on('error', onError);
  });
};

  return (
    <div>
      <button type="button" onClick={handleGenerate}>
        Generate
      </button>
      {session && (
        <div>
           <span>Successfully connected!</span>
              {accounts && accounts.map((account,index) => (
		<div key={index}>{account}</div>
	      )
            )}
        </div>
      )}
    </div>
  );
}
```


---

# 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.joeywallet.xyz/integration/actions/generate.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.
