Contract

class Contract(data)

exported from models/contract

Smart contract interface. You usually instantiante this class by using one of the static methods. Most of the instance methods return the contract so they can be chained. When an ABI is loaded, its functions will be added to the instance and can be called directly. ABI functions return FunctionCall objects that can be queried or called.

import { Contract } from '@herajs/client';
const contract = Contract.fromAbi(abi).setAddress(address);
aergo.queryContract(contract.someAbiFunction()).then(result => {
    console.log(result);
})
Arguments:
  • data (Partial<models/contract.Contract>) –
Contract.address

type: models/address.Address

Contract.code

type: Buffer

Contract.functions

type: any

Contract.asPayload(args)

Return contract code as payload for transaction

Arguments:
  • args (Array<models/contract.PrimitiveType>) –
Returns:

Buffer – a byte buffer

Contract.atAddress(address)

Create contract instance and set address

Arguments:
  • address (models/address.Address) –
Returns:

models/contract.Contract – contract instance

Contract.decodeCode(bs58checkCode)
Arguments:
  • bs58checkCode (string) –
Returns:

Buffer

Contract.encodeCode(byteArray)
Arguments:
  • byteArray (Buffer) –
Returns:

string

Contract.fromAbi(abi)

Create contract instance from ABI

Arguments:
  • abi (any) – parsed JSON ABI
Returns:

models/contract.Contract – contract instance

Contract.fromCode(bs58checkCode)

Create contract instance from code

Arguments:
  • bs58checkCode (any) – base58-check encoded code
Returns:

models/contract.Contract – contract instance

Contract.loadAbi(abi)

Load contract ABI

Arguments:
  • abi (any) – parsed JSON ABI
Returns:

models/contract.Contract – contract instance

Contract.queryState(keys, compressed, root)

Create query object to query contract state.

Arguments:
  • keys (string|models/contract.BufferLike|string[]|models/contract.BufferLike[]) – list of keys, either strings or Buffer-like byte arrays
  • compressed (boolean) – return compressed proof (default: false)
  • root (Uint8Array) – root hash
Returns:

models/contract.StateQuery

Contract.setAddress(address)

Set address of contract instance

Arguments:
  • address (models/address.Address|string) –
Returns:

models/contract.Contract – contract instance

class FunctionCall(contractInstance, definition, args)

exported from models/contract

Data structure for contract function calls. You should not need to build these yourself, they are returned from contract instance functions and can be passed to the client.

Arguments:
  • contractInstance (any) –
  • definition (any) –
  • args (any) –
FunctionCall.args

type: Array<models/contract.PrimitiveType>

FunctionCall.contractInstance

type: models/contract.Contract

FunctionCall.definition

type: Function.AsObject

FunctionCall.asQueryInfo()

Generate query info that can be passed to the API. You usually do not need to call this function yourself, AergoClient.queryContract() takes care of that.

import { Contract } from '@herajs/client';
const contract = Contract.fromAbi(abi).atAddress(address);
const functionCall = contract.someAbiFunction();
aergo.queryContract(functionCall).then(result => {
    console.log(result);
})
Returns:<TODO> – queryInfo data
FunctionCall.asTransaction(extraArgs)

Generate transaction object that can be passed to aergoClient.accounts.sendTrasaction()

import { Contract } from '@herajs/client';
const contract = Contract.fromAbi(abi).atAddress(address);
const functionCall = contract.someAbiFunction();
aergo.accounts.sendTransaction(functionCall.asTransaction({
    from: myAddress
})).then(result => {
    console.log(result);
})
Arguments:
  • extraArgs (any) –
Returns:

any – transaction data

FunctionCall.toGrpc()
Returns:Query
class StateQuery(contractInstance, storageKeys, compressed, root)

exported from models/contract

Query contract state directlty without using ABI methods.

import { Contract } from '@herajs/client';
const contract = Contract.fromAbi(abi).atAddress(address);
const query = contract.queryState('stateVariableName');
aergo.queryContractState(query).then(result => {
    console.log(result);
})
Arguments:
  • contractInstance (models/contract.Contract) –
  • storageKeys (string[]|models/contract.BufferLike[]) –
  • compressed (boolean) –
  • root (Uint8Array) –
StateQuery.compressed

type: boolean

StateQuery.contractInstance

type: models/contract.Contract

StateQuery.root

type: Uint8Array|undefined

StateQuery.storageKeys

type: string[]|models/contract.BufferLike[]

StateQuery.toGrpc()
Returns:StateQuery