All Products
Search
Document Center

Blockchain as a Service:Platform Interface Functions

Last Updated:Oct 20, 2022

The Ant Blockchain contract platform allows contract developers to obtain both block and transaction data, and enables them to implement encryption methods.

Block data interface functions

  • block.blockhash(uint blockNumber) returns (bytes32): imports blockNumber and returns the hash value of a block.

  • block.gaslimit (uint): specifies the gas limit of the system.

  • block.number (uint): specifies the block height.

  • block.timestamp (uint): specifies the timestamp when a block is created.

  • now (uint): specifies the alias of block.timestamp.

Transaction data interface functions

In the following methods, information in parentheses () indicates the data types of the returned data.

  • msg.data (bytes): specifies data provided by a user.

  • msg.gas (uint): specifies the gas value of a transaction.

  • msg.sender (identity): specifies the sender of a transaction.

  • msg.sig (bytes4): specifies the first four bytes of the data that a user provides in a transaction.

  • msg.value (uint): specifies the gas value transferred in a transaction.

You can also query the Ant Blockchain contract platform for the hash value of a transaction by using the following method:

tx.txhash   (identity / uint256)

This method can be used to obtain the hash value of the current transaction. In version 0.4.24, the data type is identity, and in version 0.6.4 and above, the data type is uint256.

Encryption interface functions

sha256

  • Function prototype

sha256(bytes data) returns(bytes32 result) ;
  • Request parameters

Parameter

Required

Type

Description

data

Yes

bytes

The data to be encrypted.

  • Response parameters

Parameter

Required

Type

Description

result

Yes

bytes

The encryption result of sha256.

Note: The sha256 function is modified for the Ant Blockchain contract platform. This is implemented by using the OpenSSL encryption library.

ecrecover

  • Function prototype

ecrecover(bytes32 hash, uint8 v, bytes32 r,bytes s) returns(identity id) ;
  • Request parameters

Parameter

Required

Type

Description

hash

Yes

bytes32

The hash result of the signature.

r

Yes

bytes32

The first 32 bytes of the signature.

s

Yes

bytes32

The last 32 bytes of the signature.

v

Yes

uint8

The last byte of the signature.

  • Response parameters

Parameter

Required

Type

Description

id

Yes

identity

The ID of the account.

Note

Note: The ecrecover function is modified for the Ant Blockchain contract platform. After obtaining the public key based on both the signature and the hash value of the signature, the platform uses the sha256 function to encrypt the key and returns the encryption result to the user as an ID.

ripemd160

The Ant Blockchain contract platform does not provide the ripemd160 function library.