As the ancients said, read more and learn more in a bear market. Without further ado, today I will share with you the relevant knowledge of block transaction information API and ABI in ETH smart contract development language solidity. It is not easy to write, I hope you can support me and look forward to ETH breaking through 10,000 US dollars in the next bull market🙌$ETH

1. What are the commonly used APIs for blocks and transactions?

blockhash(uint blockNumber) Returns the hash value of the given block number, only supports the most recent 256 blocks

block.coinbase returns(address)       The address of the miner of the current block

block.difficulty returns(uint)             The difficulty of the current block

block.gaslimit returns(uint)                The gaslimit of the current block

block.number returns(uint)                The block number of the current block

block.timestamp returns(uint)          Timestamp of the current block

gasleft    returns(uint)                       Get the remaining gas

msg.data    returns(uint256)              Complete call data (calldata)

msg.sender    returns(address)          the address of the current caller

msg.sig    returns(bytes4)                   The first four bytes of calldata, e.g., function identifier

msg.value returns(uint)                      The ether attached to this message, in wei

tx.gasprice returns(uint)                      The gas price of the transaction

tx.origin returns(address)                   The sender of the transaction

2. ABI encoding

ABI stands for Application Binary Interface. When we initiate a transaction (call a function) to a contract address, the transaction content is the ABI encoded data. The following figure is ABI

ABI related encoding functions

abi.encode(...) returns(bytes)                             ABI encoding of the computation parameters

abi.encodePacked(...) returns(bytes)                   Computes a tightly packed encoding of the arguments

abi.encodeWithSelector(...) returns(bytes)         Computes the ABI encoding of a function selector and arguments

abi.encodeWithSignature(...) returns(bytes) Computes the ABI encoding of the function selector and arguments

3. Related code exercises