Connect

The provider comes with a connect action that establishes a new connection to WalletConnect.

// Some where within your codebase...

const { actions, session, accounts } = useProvider();

const response = await actions.connect()

Inputs (Optional)

You can optionally pass in the chain , pairing.topic , or openModal directives.

{
  chain: string;
  pairing?: { topic: string };
  openModal?: boolean;
}

Return Type

The method will resolve with the active session if a connection is established by the user.

Promise<{
    data: SessionTypes.Struct || null
    error: Error || null
}>

Example usage:

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

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

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

  const handleConnect = async () => {
    const response = await actions.connect();
    if (response.error) throw response.error;
    // You have been connected using wallet connect.
    // Now you can start interacting with the XRP Ledger.
    // ...
  };

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

Last updated