> For the complete documentation index, see [llms.txt](https://mintmaster.gitbook.io/whitepaper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mintmaster.gitbook.io/whitepaper/flash-wallet/dapps-integration.md).

# Dapps Integration

### Links <a href="#getting-started" id="getting-started"></a>

Demo\
<https://flash-wallet-demo.vercel.app/>

Source Code\
<https://github.com/mintmasterapp/flash-wallet-demo>

Wallet Connect\
<https://docs.walletconnect.com/>

### Install

```
npm install --save @walletconnect/client 
OR
yarn add @walletconnect/client
```

### Initiate Connection <a href="#initiate-connection" id="initiate-connection"></a>

```
import WalletConnect from "@walletconnect/client";

// Create a connector
const connector = new WalletConnect({
  bridge: "https://bridge.walletconnect.org", // Required
});

// Check if connection is already established
if (!connector.connected) {
  // create new session
  connector.createSession();
}

// Subscribe to connection events
connector.on("connect", (error, payload) => {
  if (error) {
    throw error;
  }

  // Get provided accounts and chainId
  const { accounts, chainId } = payload.params[0];
});

connector.on("session_update", (error, payload) => {
  if (error) {
    throw error;
  }

  // Get updated accounts and chainId
  const { accounts, chainId } = payload.params[0];
});

connector.on("disconnect", (error, payload) => {
  if (error) {
    throw error;
  }

  // Delete connector
});
```

### Send Transaction

```
 const request = {
      id: 1110,
      jsonrpc: '2.0',
      method: 'hedera_sendTransaction',
      params: [
        {
          from: account  // solidityAddress,
          data: transByte // format: hex,
        },
      ],
  };

// Send Request
connector
  .sendCustomRequest(request)
  .then((result) => {
    // Returns request result
    console.log(result);
  })
  .catch((error) => {
    // Error returned when rejected
    console.error(error);
  });

```

### Create Transaction Example

#### Transaction

```
export async function senHbar(
  sender: string,
  receiver: string,
  amount: string,
) {
  const senderAccountId = AccountId.fromSolidityAddress(sender).toString();
  const newAccountTransaction = new TransferTransaction()
    .addHbarTransfer(senderAccountId, new Hbar(-amount))
    .addHbarTransfer(receiver, new Hbar(amount))
    .setTransactionMemo('Hello buddy sign and enjoy!');
  const bytes = await makeTransBytes(newAccountTransaction, senderAccountId);
  return bytes;
}
```

Generate Byte

```
export const makeTransBytes = async (trans: any, accountId: string) => {
  const transId = TransactionId.generate(accountId);
  trans.setTransactionId(transId);
  trans.setNodeAccountIds([new AccountId(3)]);
  await trans.freeze();
  return Buffer.from(trans.toBytes()).toString('hex');
};
```

### Supported Hedera Network

Flash Wallet supported all hedera networks e.g  `MAINNET`, `TESTNET,` and `PREVIEWNET`.\
After the connection is approved by the flash wallet. Flash Wallet responds `accountId` (`solidityAddress)` and `chainId`.\
\
For `MAINNET` `chainId` is `1.`\
For `TESTNET` `chainId` is `2.`\
For `PREVIEWNET` `chainId` is `3`.


---

# 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://mintmaster.gitbook.io/whitepaper/flash-wallet/dapps-integration.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.
