Skip to content

Contract

@aeternity/aepp-sdk/es/ae/contract

Contract module - routines to interact with the æternity contract

High level documentation of the contracts are available at https://github.com/aeternity/protocol/tree/master/contracts and

Example

import Contract from '@aeternity/aepp-sdk/es/ae/contract' (Using tree-shaking)

Example

import { Contract } from '@aeternity/aepp-sdk' (Using bundle)

exports.ContractAPI([options]) ⇒ Object

Contract Stamp

Provide contract implementation Ae clients.

Kind: Exported function
Returns: Object - Contract instance
rtype: Stamp

Param Type Default Description
[options] Object {} Initializer object

Example

import Transaction from '@aeternity/aepp-sdk/es/tx/tx
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory
import ChainNode from '@aeternity/aepp-sdk/es/chain/node
import ContractCompilerAPI from '@aeternity/aepp-sdk/es/contract/compiler
// or using bundle
import {
  Transaction,
  MemoryAccount,
  ChainNode,
  ContractCompilerAPI
} from '@aeternity/aepp-sdk

const ContractWithAE = await Contract
   .compose(Transaction, MemoryAccount, ChainNode) // AE implementation
   .compose(ContractCompilerAPI) // ContractBase implementation
const client = await ContractWithAe({ url, internalUrl, compilerUrl, keypair, ... })

handleCallError(result) ⇒ Promise.<void>

Handle contract call error

Kind: Exported function
Category: async
Throws:

  • Error Decoded error
Param Type Description
result Object call result object

contractEncodeCall(source, name, args, [options]) ⇒ Promise.<String>

Encode call data for contract call

Kind: Exported function
Category: async

Param Type Default Description
source String Contract source code
name String Name of function to call
args Array Argument's for call
[options] Object {} Options
[options.filesystem] Object {} Contract external namespaces map
[options.backend] Object 'fate' Compiler backend

contractDecodeData(source, fn, callValue, callResult, [options]) ⇒ Promise.<String>

Decode contract call result data

Kind: Exported function
Returns: Promise.<String> - Result object
Category: async

Param Type Default Description
source String source code
fn String function name
callValue String result call data
callResult String result status
[options] Object {} Options
[options.filesystem] Object {} Contract external namespaces map

Example

const decodedData = await client.contractDecodeData(SourceCode ,'functionName', 'cb_asdasdasd...', 'ok|revert')lt

contractCallStatic(source, address, name, args, [options]) ⇒ Promise.<Object>

Static contract call(using dry-run)

Kind: Exported function
Returns: Promise.<Object> - Result object
Category: async

Param Type Default Description
source String Contract source code
address String Contract address
name String Name of function to call
args Array | String Argument's or callData for call/deploy transaction
[options] Object {} Options
[options.top] String Block hash on which you want to call contract
[options.bytecode] String Block hash on which you want to call contract
[options.options] Object Transaction options (fee, ttl, gas, amount, deposit)
[options.options.filesystem] Object Contract external namespaces map

Example

const callResult = await client.contractCallStatic(source, address, fnName, args = [], { top, options = {} })
{
  result: TX_DATA,
  decode: (type) => Decode call result
}

contractCall(source, address, name, argsOrCallData, [options]) ⏏

Call contract function

Kind: Exported function
Category: async

Param Type Default Description
source String Contract source code
address String Contract address
name String Name of function to call
argsOrCallData Array | String Argument's array or callData for call function
[options] Object {} Transaction options (fee, ttl, gas, amount, deposit)
[options.filesystem] Object {} Contract external namespaces map* @return {Promise} Result object

Example

const callResult = await client.contractCall(source, address, fnName, args = [], options)
{
  hash: TX_HASH,
  result: TX_DATA,
  decode: (type) => Decode call result
}

contractDeploy(code, source, initState, [options]) ⇒ Promise.<Object>

Deploy contract to the node

Kind: Exported function
Returns: Promise.<Object> - Result object
Category: async

Param Type Default Description
code String Compiled contract
source String Contract source code
initState Array | String Arguments of contract constructor(init) function. Can be array of arguments or callData string
[options] Object {} Transaction options (fee, ttl, gas, amount, deposit)
[options.filesystem] Object {} Contract external namespaces map* @return {Promise} Result object

Example

const deployed = await client.contractDeploy(bytecode, source, init = [], options)
{
  owner: OWNER_PUB_KEY,
  transaction: TX_HASH,
  address: CONTRACT_ADDRESS,
  createdAt: Date,
  result: DEPLOY_TX_DATA,
  call: (fnName, args = [], options) => Call contract function,
  callStatic: (fnName, args = [], options) => Static all contract function
}

contractCompile(source, [options]) ⇒ Promise.<Object>

Compile contract source code

Kind: Exported function
Returns: Promise.<Object> - Result object
Category: async

Param Type Default Description
source String Contract sourece code
[options] Object {} Transaction options (fee, ttl, gas, amount, deposit)
[options.filesystem] Object {} Contract external namespaces map* @return {Promise} Result object
[options.backend] Object 'aevm' Contract backend version (aevm

Example

const compiled = await client.contractCompile(SOURCE_CODE)
{
  bytecode: CONTRACT_BYTE_CODE,
  deploy: (init = [], options = {}) => Deploy Contract,
  encodeCall: (fnName, args = []) => Prepare callData
}