AIOU Chain Docs

AIOU Chain Docs

  • Docs
  • Languages iconEnglish
    • 中文

›AIOU Javascript SDK

Getting started

  • Overview
  • Quickstart

AIOU Design and Concepts

  • Account
  • Economic model

Smart Contract

  • Smart Contract Quick Start
  • AIOU Blockchain API
  • Update Contract
  • Generate Receipt in Smart Contract
  • Create IRC20 Token

Running AIOU node

  • Join AIOU Network
  • Become Servi Node

Reference

  • API
  • System Contract
  • Economic Contract
  • Token Contract
  • Gas Charge Table

AIOU Javascript SDK

  • AIOU
  • Blockchain
  • KeyPair
  • Transaction

AIOU Tech Internals

  • VM
  • Database
  • Network layer

AIOU

This is the main class that create transactions to send to AIOU blockchain and AIOU smart contracts.

constructor

constructor method is a special method for creating and initializing AIOU class.

Parameters

NameTypeDescription
configObjectconfig object for AIOU class, config details as as follows:
gasRatio: transaction gas price
gasLimit: transaction gas limit
expiration: time in seconds that transaction will be expired

Returns

AIOU object instance.

Example

// init aiou sdk
const aiou = new AIOU.AIOU({ // will use default setting if not set
    gasRatio: 1,
    gasLimit: 100000,
    expiration: 90,
});

callABI

call contract abi function

Parameters

NameTypeDescription
contractStringcontract id or contract domain
abiStringcontract abi function name
argsArrayfunction args array

Returns

Transaction Object.

Example

const tx = aiou.callABI(
    "token.aiou",
    "transfer",
    ["aiou", "fromAccount", "toAccount", "10.000", "memo"]
);

newAccount

create new AIOU blockchain account

Parameters

NameTypeDescription
nameStringnew account name
creatorStringcreator account name
ownerkeyStringcreator account ownerKey
activekeyStringcreator account activeKey
initialRAMNumbernew account initialRAM, paid by creator
initialGasPledgeNumbernew account initialGasPledge, paid by creator

Returns

Transaction Object.

Example

// first create KeyPair for new account
const newKP = KeyPair.newKeyPair();
// then create new Account transaction
const newAccountTx = aiou.newAccount(
    "test1",
    "admin",
    newKP.id,
    newKP.id,
    1024,
    10
);

transfer

transfer tokens to designated account, wrapper for callABI

Parameters

NameTypeDescription
tokenStringtoken name
fromStringtransfer-from account
toStringtransfer-to account
amountStringtransfer amount
memoNumbermemo of this transfer

Returns

Transaction Object.

Example

const tx = aiou.transfer("aiou", "fromAccount", "toAccount", "10.000", "memo");

Way to send tx

Here is the way sending tx in aiou, it's compatible using third-party wallet.

aiou.setAccount(account);
aiou.setRPC(rpc);
aiou.signAndSend(tx)
    .on("pending", console.log)
    .on("success", console.log)
    .on("failed", console.log);

Third-party wallets are recommended to hook AIOU, and take over signAndSend() function, thus develops can work both wallet exist or not.

if wallet exists, signAndSend() works in wallet and callback when success or failed, and if not, aiou use account to sign tx and using rpc to send it.

signAndSend

sign a tx and send it.

Parameters

NameTypeDescription
txAIOU.Txtx to be send

Returns

a Callback object

Example

aiou.signAndSend(tx)
    .on("pending", console.log)
    .on("success", console.log)
    .on("failed", console.log);

Callback.on(event, callback)

set handle to event

Parameters

NameTypeDescription
eventStringevent name, include "pending", "success", "failed"
callbackfunctioncallback function

Returns

itself.

Example

aiou.signAndSend(tx)
    .on("pending", console.log)
    .on("success", console.log)
    .on("failed", console.log);

setAccount

set default account to aiou

Parameters

NameTypeDescription
accountAIOU.Accountaccount using by this aiou instance

Returns

null

Example

aiou.setAccount(account);

currentAccount

get current account in this aiou

Parameters

null

Returns

an AIOU.Account.

Example

const account = aiou.currentAccount();

setRPC

transfer tokens to designated account, wrapper for callABI

Parameters

NameTypeDescription
rpcAIOU.RPCrpc using by this AIOU instance

Returns

null.

Example

aiou.setRPC(rpc);

currentRPC

get current rpc

Parameters

null

Returns

an AIOU.RPC instance.

Example

const rpc = aiou.currentRPC();
← Gas Charge TableBlockchain →
  • constructor
    • Parameters
    • Returns
    • Example
  • callABI
    • Parameters
    • Returns
    • Example
  • newAccount
    • Parameters
    • Returns
    • Example
  • transfer
    • Parameters
    • Returns
    • Example
  • signAndSend
    • Parameters
    • Returns
    • Example
  • Callback.on(event, callback)
    • Parameters
    • Returns
    • Example
  • setAccount
    • Parameters
    • Returns
    • Example
  • currentAccount
    • Parameters
    • Returns
    • Example
  • setRPC
    • Parameters
    • Returns
    • Example
  • currentRPC
    • Parameters
    • Returns
    • Example
AIOU Chain Docs
Community
BlogGitHubStar
Facebook Open Source
Copyright © 2021 Your Name or Your Company Name