Mint Master
  • Introduction
    • Welcome
  • NFT Collections
    • Spaceburds
      • Rarity
      • Utility
      • Incentives
      • Attributes and animated assets
    • Devil Cats
      • Rarity
      • Utility
      • Incentives
      • Attributes and animated assets
  • Roadmap
    • V1
  • Social Causes
    • Animal Fosters
  • Merchandise
  • Team
  • Flash Wallet
    • Introduction
    • Dapps Integration
  • Creator
    • Coming Soon...
  • WarZone
    • Coming soon...
  • Apis
    • Coming Soon...
  • Collaboration
    • Coming Soon...
Powered by GitBook
On this page
  • Links
  • Install
  • Initiate Connection
  • Send Transaction
  • Create Transaction Example
  • Supported Hedera Network
  1. Flash Wallet

Dapps Integration

Flash wallet using WalletConnect open protocol to communicate securely to dapps.

PreviousIntroductionNextComing Soon...

Last updated 3 years ago

Links

Demo

Source Code

Wallet Connect

Install

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

Initiate Connection

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.

https://flash-wallet-demo.vercel.app/
https://github.com/mintmasterapp/flash-wallet-demo
https://docs.walletconnect.com/