Development
Development Libraries
AIOZ JS

AIOZJS

Introduction

AIOZJS is a powerful JavaScript-based client solution ranging from Web apps/explorers over browser extensions to server-side clients to the AIOZ Network blockchain.

Webpack Configs

With WebPack 5, you have to be explicit about the usage of Node.js types and modules that were simply replaced with re-implementations for browsers in Webpack 4.

module.exports = [
  {
    // ...
    plugins: [
      ...,
      new webpack.ProvidePlugin({
        Buffer: ["buffer", "Buffer"],
      }),
    ],
    // ...
    resolve: {
      fallback: {
        buffer: false,
        crypto: false,
        events: false,
        path: false,
        stream: false,
        string_decoder: false,
      },
    },
  },
];

Send your first transaction from JavaScript

import { DirectEthSecp256k1HdWallet } from "@aiozjs/proto-signing";
import {
    assertIsBroadcastTxSuccess,
    SigningStargateClient,
    calculateFee
} from "@aiozjs/stargate";
 
const mnemonic = "federal injury annual melt near scan daughter before nut catalog spend decade";
const wallet = await DirectEthSecp256k1HdWallet.fromMnemonic(mnemonic);
const [firstAccount] = await wallet.getAccounts();
 
const rpcEndpoint = "https://rpc.my_aioz_rpc_node";
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet);
 
const recipient = "0x70207819eC28FB8cc692A4327C80282006E6476A";
const amount = {
  denom: "attoaioz",
  amount: "1000000000000000000"
};
const fee = calculateFee(200000, "1000000000attoaioz");
const result = await client.sendTokens(
    firstAccount.address,
    recipient,
    [amount],
    fee,
    "My first tx"
);
assertIsBroadcastTxSuccess(result);

Send your custom message types:

import { DirectEthSecp256k1HdWallet } from "@aiozjs/proto-signing";
import {
    assertIsBroadcastTxSuccess,
    SigningStargateClient,
    calculateFee
} from "@aiozjs/stargate";
import { hexToAddress } from "@aiozjs/amino";
import { MsgDelegate } from "aiozjs-types/cosmos/staking/v1beta1/tx";
 
const mnemonic = "federal injury annual melt near scan daughter before nut catalog spend decade";
const wallet = await DirectEthSecp256k1HdWallet.fromMnemonic(mnemonic);
const [firstAccount] = await wallet.getAccounts();
 
const rpcEndpoint = "https://rpc.my_aioz_rpc_node";
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet);
 
const validator = "0x46Bc4091378bd359273D19A38Dac03dfdA119411";
const amount = {
  denom: "attoaioz",
  amount: "1000000000000000000"
};
const msg = {
  typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
  value: MsgDelegate.fromPartial({
    delegatorAddress: firstAccount.address,
    validatorAddress: hexToAddress(validator, client.prefix + 'valoper'),
    amount: amount
  })
};
const fee = calculateFee(200000, "1000000000attoaioz");
const result = await client.signAndBroadcast(
    firstAccount.address,
    [msg],
    fee,
    "Your first delegate tx"
);
assertIsBroadcastTxSuccess(result);

Connect to Web3 and Metamask

import Web3 from "web3";
import { Web3Wallet } from "@aiozjs/eip712";
 
const wallet = new Web3Wallet(new Web3(window.ethereum));
const [firstAccount] = await wallet.getAccounts();

Connect to Keplr

const chainId = "<chain_id>";
await window.keplr.enable(chainId);
 
const wallet = window.keplr.getOfflineSigner(chainId);
const [firstAccount] = await wallet.getAccounts();