AIXChain Blockchain Document
  • INTRODUCTION
    • Getting started with smart contract development
    • Build a Decentralized Library
  • AIXC AND ARC TOKEN
    • ARC
      • ARX Transfer
      • Query ARX balance
    • ARC-10
      • Issue ARC-10 token
      • Participate ARC-10
      • ARC-10 Transfer
      • Query ARC-10 balance
      • ARC-10 Transfer in Smart Contracts
    • ARC-20
      • Protocol Interface
      • Contract Example
      • Issuing ARC-20 tokens tutorial
    • ARC-721
      • Protocol Interface
      • Contract Example
  • ACCOUNT MODEL
  • BUILD NODE
    • How to setup a Super node to produce Blocks
      • Recommended configuration & Environment
      • Example cloud services
      • Deployment guide
    • Super Representative
      • How to become a SR
      • Super Representatives Election
      • How to change witness name
  • HTTP API
    • Introduction
    • API Signature and Broadcast Flow
    • API List
      • Full Node API Overview
      • Address Utilities
        • GenerateAddress
        • CreateAddress
        • ValidateAddress
      • Accounts
        • CreateAccount
        • GetAccount
        • UpdateAccount
        • AccountPermissionUpdate
        • GetAccountBalance
      • Account Resources
        • GetAccountResource
        • GetAccountNet
        • FreezeBalance
        • UnfreezeBalance
        • GetDelegatedResource
        • GetDelegatedResourceAccountIndex
      • Query the Network
        • GetBlockByNum
        • GetBlockById
        • GetBlockByLatestNum
        • GetBlockByLimitNext
        • GetNowBlock
        • GetTransactionById
        • GetTransactionInfoById
        • GetTransactionInfoByBlockNum
        • ListNodes
        • GetNodeInfo
        • GetChainParameters
        • GetBlockBalance
      • ARC10 Token
        • GetAssetIssueByAccount
        • GetAssetIssueById
        • GetAssetIssueList
        • GetPaginatedAssetIssueList
        • TransferAsset
        • CreateAssetIssue
        • UnfreezeAsset
        • UpdateAsset
      • Transactions
        • GetContract
        • GetTransactionSign
        • BroadcastTransaction
        • BroadcastHex
        • EasyTransfer
        • EasyTransferByPrivate
        • CreateTransaction
      • Voting & SRs
        • ListWitnesses
        • CreateWitness
        • UpdateWitness
        • GetBrokerage
        • UpdateBrokerage
        • VoteWitnessAccount
        • GetReward
        • WithdrawBalance
        • GetNextMaintenanceTime
      • Smart Contracts
        • TriggerSmartContract
        • DeployContract
        • UpdateSetting
        • UpdateEnergyLimit
        • ClearAbi
        • GetContract
        • TriggerConstantContract
      • Proposals
      • Solidity Node API
    • RPC List
  • AIXCHAIN CLI
  • Aixchain SDK
    • Quickstart
    • Address and Signature
    • Sending Transaction
    • Smart Contract
  • Faucet Aixchain
  • Wallets
Powered by GitBook
On this page
  1. Aixchain SDK

Smart Contract

Smart contract is a key feature of AIXCHAIN network. It’s easy to creating and interacting with smart contracts through Aixchain SDK.

Calling smart contract

There are two types of smart contract calls: const call and trigger call.

Simply, a const call returns result immediately once and no need to sign or broadcast.

Trigger call is a type of system contract call, needs signing and broadcasting. It fetches the result through the API.

You may see the functions of a specified contract by ContractFunction.toString(), then you can construct a Function object to make a constant/trigger call.

Get contract

Get a Contract object from the address.

PARAMS

1. contractAddress(String)

The address of a smart contract.

RETURN

A Contract object.

THROW

Throws if the given contract address does not match any.

Example :

public void getSmartContract() {
        try {
            AixcClient client = new AixcClient("172.104.51.182:16669","172.104.51.182:16669","private key");
            Contract cntr = client.getContract("AV27cVbuGmTv9q6qgtPxsLUkuG9ohUUVPd"); //JST
             for (ContractFunction cf : cntr.getFunctions()) {
                System.out.println(cf.toString());
            }
        } catch (Exception e) {
            System.out.println("error: " + e);
        }
    }

The result is:

Contract name: ARC721Token
cntr.getOriginAddr()
<ByteString@2ce86164 size=21 contents="AB\003HZSZ@r\311\373\372\255\337\342\240\020\255\v\315\260">
Contract functions: []

Trigger call

Make a trigger call. Trigger calls require signature and broadcasting. Refer to RPC_APIs for the signing and broadcasting functions.

The first half of the trigger call process is similar to the const call.

You can easily set feeLimit, memo and other common attributes via the TransactionBuilder

PARAMS

1. ownerAddr(String)*

The caller’s address.

2. contractAddr(String)*

The contract’s address.

3. function(Function)*

The exact function you are calling, you can find the example in the triggerCallDemo.

RETURN

A TransactionBuilder object, for easily setting memos, feelimit, Etc.

THROW

Throws if the function does not match any in the smart contract.

Example:

publ public void triggerCallDemo() {
        AixClient client = new AixcClient("172.104.51.182:16669","172.104.51.182:16669","private key");
        try {
            //function 'setApprovalForAll'
            //params: function name, function params
            Function arc721Transfer = new Function("setApprovalForAll",
                    Arrays.asList(new Address("41a9c46373aEB4749E3CE45acA242b027A46f486f9"),
                            new Bool(false)),
                    Arrays.asList(new TypeReference<Bool>() {}));

            //the params are: owner address, contract address, function
            TransactionBuilder builder = client.triggerCall("414203485a535a4072C9FBFaADDfe2A010AD0BcdB0", "WV27cVbuGmTv9q6qgtPxsLUkuG9ohUUVPd", wrc721Transfer); //JST
            //set extra params
            builder.setFeeLimit(100000000L);
            builder.setMemo("Let's go!");
            //sign transaction
            Transaction signedTxn = client.signTransaction(builder.build());
            System.out.println(signedTxn.toString());
            //broadcast transaction
            String ret = client.broadcastTransaction(signedTxn);
            System.out.println("======== Result ========\n" + ret);
        } catch (Exception e) {
            System.out.println("error: " + e);
        }
    }

======== Result ======== 0d2b6a4a7d52e0775da63443e285010441ab9490cf57c47c097ff85b79aff3e0

constantCall

Make a constant call, without broadcasting.

PARAMS

1. ownerAddr(String)*

The caller’s address.

2. contractAddr(String)*

The contract’s address.

3. function(Function)*

The exact function you are calling, you can find the example in the triggerCallDemo.

RETURN

A TransactionExtention object

THROW

Throws if the function does not match any in the smart contract.

PreviousSending TransactionNextFaucet Aixchain

Last updated 29 days ago