I'm still learning solidity but having some hard times while trying to understand how abi.encode works. I mean when i try to see it's output i see a long hex value. For example if i call this function :
function getHexTest() public pure returns(bytes memory){
return abi.encode("1","2");
}
I see this output on remix:
0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013200000000000000000000000000000000000000000000000000000000000000
So i couldn't understand how this works and how this value calculated exactly. Because it's not equal to these values hex ascii or any other thing. So question is how this is structured? I see different examples in documentation like encoding functions and arguments but to be able o fully understand i need to understand this first.
Best Answer
Incoming (parameters) or outcoming data package for a contract is formed according to the following principle:
Let’s consider, for example, a block, where the following data are sent: address, string, uint32, address[] (a hexadecimal address relative to the beginning of the block is given in the beginning of every 32-byte sting for the convenience)
In you keys we recieve 2 string variable: