Ethernet Square Intelligent Contract Abi (Ethereum Contract ABI)

Source: Internet
Author: User
Tags aliases
Basic DesignWe assume that the application binary interface (ABI) is strongly typed and is known both at compile time and static. Will not provide an introspective mechanism. We assert that all contracts have interface definitions for any contracts that they invoke at compile time.

This specification does not deal with contracts whose interfaces are dynamic or only known at run time. If these conditions become important they can be properly disposed of in the etheric Square ecological construction facility.

The interface of the contract is not attached to the ABI, and function calls can refer to any number of arguments that are to be filled into 32 bytes and are spliced. An exception to this is that the first parameter is encoded in exactly 4 bytes, in which case there is no need to fill and use the function symbol directly.

feature Select the first four bytes of the call data for a function call in the contract interaction specifies the function to invoke. The first four bytes after 0x, this is the signature hash of the Keccak (SHA-3) function. The signature is defined as the canonical expression of the basic prototype, which is the parentheses in the list of function names and parameter types. parameter types are separated by a comma-no spaces are used. Then the function call data is the 0x+ function name (function type N, function type N1,..) The first 4 bytes of the Keccak (SHA-3) value

Example:

function issue (Address account, uint amount) {
	        if (msg.sender!= issuer) throw;
	        Balances[account] + = amount;
	    }
This function is named issue, there are two parameters, respectively, the address and uint type, then the call to this function requires that we pass the data as the first 4 bytes of the SHA3 value of 0x+issue (address,uint256).


Then intercept the first 4 bytes, one byte = 2 16 characters, all 867904b4, then the last call to this function requires that the parameter be passed as 0X867904B4.parameter EncodingFor functions that call without parameters, the above is OK, for function calls that have arguments, you need to add parameters starting with the 5th byte, and the encoding of the parameter is associated with the basic type of the parameter.Basic TypeUint<m>:m is the integer type representing M bits,0 < M <= 256, m% 8 = 0, such as uint32,uint8,uint256. Int<m>: ditto. The same is an unsigned integer from 8 to 256 digits. UINT and int: integers, respectively, are aliases for uint256 and int256. This is also the example above where the function parameter type is uint, the reason for turning sha3 code into uint256. Address: Addresses, 20 bytes, 160bits, a ethereum address, and the type of address can also have members as base for all contracts. BOOL: Boolean type, 1 bytes, true:1,false:0. Bytes<m&gt: A fixed-size array of bytes, 0<m<=32,byte are aliases of bytes1. Bytes: Dynamically allocating size byte array. Not a value type! String: Dynamic size UTF8 encoded strings, not a value type! As a common sense, use bytes to represent arbitrary-length raw byte data, using string to represent specific length string data (Utf-8 encoding). If you want to qualify a specific number of byte lengths, use Bytes1 to Bytes32, because it takes less storage space.The following example shows how bytes's parameters Implement delivery: For example, if a parameter type is bytes, we need to handle the pass parameter value, bytes as a dynamic size array, the length can only be obtained by passing characters ' lengths, such as "Hello, world!" There are 13 bytes, then we need to pass this length over, that is, 13 of the 16:0x000000000000000000000000000000000000000000000000000000000000000d, remember that the complement is 32 bytes. The length of the array is there, and the next step is to pass the argument, which is "Hello, world!." Hexadecimal encoding: 0x48656c6c6f2c20776f726c6421, where the automatic complement is 32 bytes, Complement from right: 0x48656c6c6f2c20776f726c642100000000000000000000000000000000000000, then the final pass parameter is 0x function + 000000000000000000000000000000000000000000000000000000000000000d+ 48656c6c6f2c20776f726c642100000000000000000000000000000000000000+ other parameters, where the red part represents the parameters of the bytes type. For a fixed-size array, the principle is similar, the first step: the number of elements in the array parameter passed, such as [65,78] has 65 and 752 parameters, then the number of elements is: 2, Convert to 16:0x0000000000000000000000000000000000000000000000000000000000000002, and then start parsing the first element 65: 0x0000000000000000000000000000000000000000000000000000000000000041, The second element 75:0x000000000000000000000000000000000000000000000000000000000000004b, then the final pass is: 0x function + 0000000000000000000000000000000000000000000000000000000000000002+ 0000000000000000000000000000000000000000000000000000000000000041+000000000000000000000000000000000000000000000000000000000000004b+ other parameters, where the red section represents the parameters of a fixed-size array type.
This is some of the most commonly used basic data types, and there are some other types that need to be understood to Https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI view.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.