API of Contract

  • Use the global function ‘transfer_from_contract_to_address’ to transfer an amount of an asset to an address from the current contract (the contract where the function calls the code).The first argument is the destination address(string),The second parameter is asset name(for example ACT),The third parameter is 100,000 times the number of transfers(int64 type),must be positive.
Return value
     0   Transfer successfully
    -1  Unknown system exception
    -2  Asset_symbol exception
    -3  Contract address is illegal
    -4  Destination address is illegal
    -5  Account balance is insufficient to pay the transfer
    -6  The transfer amount is negative
  • Use the global function ‘get_contract_balance_amount’ to get a contract with the accuracy of the balance(accuracy is 100000),The first argument is the contract address(Support the balance of other contracts).The second parameter is asset name(for example ACT),Returns the balance of the contract with precision(int64 type),If there is an error or the contract does not exist, return a negative number.
Return value
    Non-negative number balance of contract account
    -1  Asset id exception
    -2  Contract address exception
  • Use the global function ‘get_chain_now’ to get the current time on the blockchain.No input parameters.
Return value
    positive number  Timestamp
    0     System exception
  • Use the global function ‘get_chain_random’ to get a pseudo-random number on the blockchain.But the same operation on this blockchain, different nodes at different times will get the same return result.(The actual operation is taken on the block prev_secret_hash and the deal is combined with the hash)
Return value
    Random result
  • Use the global function’ get_header_block_num’ to get the block number of the previous block.
Return value
    The block number of the current chain.
  • Use the global function ‘get_waited(num)’ to get a pseudo-random number from the data of the future block.<num> is the block number of the future block(But need to call again in the future.At that time the first num block is the past block will be able to know the results)
Return value
    positive number result value
    -1  The target block is not reached
    -2  The target block is less than 1
  • Use the global function ‘get_current_contract_address’ to get the contract address where it is called. No input parameters.
  • The global variable caller stores the public key of the user who call the contract. The global variable caller_address stores the account address of the user who call the contract
  • When transfer to contract,If the contract defines ‘on_deposit’(The parameter is the transfer amount),the API will be called after the transfer occurs. And ensure that the transfer and trigger this API is atomic. If failed, the overall rollback, transfer failure.
  • Use the statement emit EventName(arg: string) to throw an event. emit is a keyword. Write the event name as needed into EventName, Recorded by the block chain. Other nodes to sync to emit triggered event can call the local settings callback.
  • Use global function ‘get_transaction_fee()’ to get a transaction fee.
Return value
    positive number result value
    -1  Asset id exception
    -2  System exception
  • Use global function ‘transfer_from_contract_to_public_account(to_account_name: string, asset_type: string, amount: int)’ to transfer from the current contract to the account name on the chain. Return the state of transfer.
Return value
    0   Transfer successful
   -1  Unknown system exception
   -2  Asset_symbol exception
   -3  Contract address is illegal
   -4  Destination address is illegal
   -5  Account balance is insufficient to pay the transfer
   -6  Transfer amount is negative
   -7  Account name does not exist