Skip to content

onbloc/dapp-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8c56b06 · Mar 14, 2025

History

3 Commits
Jan 27, 2023
Jan 27, 2023
Mar 14, 2025
Jan 27, 2023
Jan 27, 2023
Jan 27, 2023
Jan 27, 2023
Jan 27, 2023
Jan 27, 2023

Repository files navigation

Adena Connect For React App

Sample App Demo (https://onbloc.github.io/dapp-example)

Sample App Image


Getting Started

  1. Install Node Packages
$ npm install
  1. Start
$ npm start
  1. Build
$ npm build

Usage

Check if Adena wallet exists.

// checks the existence of the adena object in window

const existsWallet = () => {
    if (window.adena) {
      return true;
    }
    return false;
};

Register your website as a trusted domain.

// calls the AddEstablish of the adena object

const addEstablish = (siteName) => {
  return window?.adena?.AddEstablish(siteName);
};

Retrieve information about the connected account.

// calls the GetAccount function of the adena object

const getAccount = () => {
    return window.adena?.GetAccount();
};

Request approval of a transaction that transfers tokens.

// Execute the DoContract function of the adena object to request transaction.

const doContractSendToken = (fromAddress, toAddress, sendAmount) => {
  const sendTokenMessage = {
    type: "/bank.MsgSend",
    value: {
      from_address: fromAddress,
      to_address: toAddress,
      amount: sendAmount
    }
  };

  return window.adena?.DoContract({
    messages: [sendTokenMessage],
    gasFee: 1,
    gasWanted: 3000000
  });
};

Request approval of a transaction that calls a function from a realm.

// Execute the DoContract function of the adena object to request transaction.

const doContractUseRealm = (caller, func, pkgPath, argument) => {

  // Setup Transaction Message
  const sendTokenMessage = {
    type: "/vm.m_call",
    value: {
      caller,
      func,
      send: "",
      pkg_path: pkgPath,
      args: argument.split(',')
    }
  };

  // Request Transaction
  return window.adena?.DoContract({
    messages: [sendTokenMessage],
    gasFee: 1,
    gasWanted: 3000000
  });
};