> For the complete documentation index, see [llms.txt](https://docs.vechain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vechain.org/developer-resources/sdks-and-providers/react-native-wallet-link/wallet-hook.md).

# The useVeWorldWallet Hook

## Overview

The `useVeWorldWallet()` hook is your main interface for managing wallet interactions.\
It provides helper functions for generating keys, connecting, signing, and disconnecting — all while handling encryption internally.

***

## API Summary

| Method                                                                                  | Description                                          |
| --------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `generateKeyPair()`                                                                     | Generates a new NaCl key pair                        |
| `connect(publicKey)`                                                                    | Initiates a secure connection with VeWorld           |
| `disconnect(keyPair, veWorldPublicKey, session, description?)`                          | Disconnects the wallet session                       |
| `signCertificate(keyPair, veWorldPublicKey, session, certificate, description?)`        | Signs a plain-text message or structured payload     |
| `signTypedData(keyPair, veWorldPublicKey, session, typedData, description?)`            | Signs structured EIP-712 style data                  |
| `signAndSendTransaction(keyPair, veWorldPublicKey, session, transaction, description?)` | Signs and sends a transaction to the VeChain network |

***

## Example Usage

```tsx
import { useVeWorldWallet } from '@vechain/react-native-wallet-link';
import { encodeBase64 } from 'tweetnacl-util';

export const WalletComponent = () => {
  const {
    generateKeyPair,
    connect,
    disconnect,
    signCertificate,
    signTypedData,
    signAndSendTransaction
  } = useVeWorldWallet();

  const [keyPair, setKeyPair] = useState<any>(null);

  useEffect(() => {
    const keys = generateKeyPair();
    setKeyPair({
      secretKey: encodeBase64(keys.secretKey),
      publicKey: encodeBase64(keys.publicKey)
    });
  }, []);

  return (
    <>
      <Button title="Connect" onPress={() => connect(keyPair.publicKey)} />
      <Button title="Sign Data" onPress={() => signCertificate(keyPair, veWorldPublicKey, session, myCert)} />
    </>
  );
};
```

***

## Response Handling

All event responses follow a common structure:

```ts
type VeWorldResponse = {
  data: string;
  nonce: string;
  publicKey: string;
};

type VeWorldError = {
  errorCode: string;
  errorMessage: string;
};
```

Always validate before decrypting:

```ts
if ('errorCode' in response) {
  console.error('VeWorld Error:', response.errorMessage);
} else {
  const payload = decryptPayload(...);
}
```

***

## Example Flow Diagram

```
App (React Native)
   ↓ generateKeyPair()
   ↓ connect(publicKey)
→  VeWorld App (user approval)
   ↓ returns encrypted session
→  onVeWorldConnected()
   ↓
[Use session for signing & transactions]
```

***

[← Back: Integration Guide](https://github.com/vechain/vechain-docs/blob/main/developer-resources/sdks-and-providers/react-native-wallet-link/03-integration-guide.md) · [Next → Event Handlers](https://github.com/vechain/vechain-docs/blob/main/developer-resources/sdks-and-providers/react-native-wallet-link/05-event-handlers.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.vechain.org/developer-resources/sdks-and-providers/react-native-wallet-link/wallet-hook.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
