<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gaspard on Medium]]></title>
        <description><![CDATA[Stories by Gaspard on Medium]]></description>
        <link>https://medium.com/@Typs?source=rss-eefb8eb643be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*r1SziOut2vnBF_r0rgNHSA.jpeg</url>
            <title>Stories by Gaspard on Medium</title>
            <link>https://medium.com/@Typs?source=rss-eefb8eb643be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 15:13:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Typs/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Ethereum ABI Encoding Explanation]]></title>
            <link>https://medium.com/b2expand/abi-encoding-explanation-4f470927092d?source=rss-eefb8eb643be------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f470927092d</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Gaspard]]></dc:creator>
            <pubDate>Wed, 23 May 2018 15:34:22 GMT</pubDate>
            <atom:updated>2018-05-24T14:43:09.298Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeItuF4ex1c8HX3fR14etA.png" /></figure><p>Solidity is a statically typed language, below you will be able to find a list of the main types (fig1.) and informations about how they are encoded in the ABI. More detailed informations can be found in the solidity <a href="https://solidity.readthedocs.io/en/v0.4.23/types.html">documentation</a>. Each of these types could be static or dynamic. As we can read in the <a href="https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI">ethereum wiki</a> :</p><blockquote>“Static types are encoded in-place and dynamic types are encoded at a separately allocated location after the current block.”</blockquote><p>Functions are not really a type but we explain how it is encoded because we are considering the ABI encoding (function encoding is needed while calling a function). In the tuple part, we will introduce what we have called an only-static tuple and will explain how this kind of tuple are treated differently while encoding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*Uj8ghHAwyU8vedcwdBU70g.png" /><figcaption>Fig1. main types</figcaption></figure><h3><strong>Uint (static) :</strong></h3><p>An unsigned integer between 8 and 256 bits long, padded left to 32 bytes while encoding.</p><h3><strong>Int </strong>(static) <strong>:</strong></h3><p>A two’s complement signed integer between 8 and 256 bits long, padded left to 32 bytes while encoding.</p><h3><strong>Address </strong>(static) <strong>:</strong></h3><p>A 20 bytes hexadecimal, encoded like an uint.</p><h3><strong>Bool </strong>(static) <strong>:</strong></h3><p>An uint8 where 0 is used for false and 1 for true.</p><h3><strong>Bytes&lt;m&gt; </strong>(static) <strong>:</strong></h3><p>A binary type of m bytes with 0&lt;m&lt;=32. The byte sequence is encoded as it is and padded right to 32 bytes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nby5sug4m0OE4mWS2c7zyQ.png" /><figcaption>Fig2. The illustrated different static types</figcaption></figure><h3>Bytes (dynamic) :</h3><p>A dynamic sized bytes sequence padded on the right if needed. The encoded sequence is prepended with the number of bytes.</p><h3>String (dynamic) :</h3><p>A string is encoded in utf-8 and then treated has a bytes type. The number of bytes represents here the number of characters in the string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jIn5U1GU8t8sMNFi2eOGHg.png" /><figcaption>Fig3. Bytes and string encoded</figcaption></figure><h3>Non-fixed size Array (dynamic) :</h3><p>A non-fixed array is an array with a dynamic number of elements. While encoding, non-fixed array are prefixed by the number of elements they have.</p><h3><strong>Fixed-size Array (dynamic and static) :</strong></h3><p>A fixed-size array is an array of m elements with m &gt;=0. Elements of the array are treated like a tuple with only one type. If this type is fixed, the array is like an only-static tuple (<a href="#0795">see tuple section below</a>).</p><p>Examples of array can be found in the <a href="#c61d">examples section</a>.</p><h3><strong>Tuples </strong>(dynamic and static)<strong> :</strong></h3><p>A tuple is a combination of types.</p><p>A tuple can contain static or dynamic types, an only-static tuple means that the tuple contains only static elements. Only-static tuple is the different elements padded to 32 bytes and put one after the other, the tail will be empty. An only-static tuple is considered as a static type.</p><p>A tuple which contains at least a single dynamic element is encoded in a different way. If the element is dynamic it’s head represents an offset where you can find the encoded element (this is called the tail of the element), if an element is static the head is the encoded element. An offset means the number of bytes between the first head of the tuple and the element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZlTanRne5hEWUItM9JFww.png" /><figcaption>Fig4. Difference between static and dynamic tuples</figcaption></figure><h3><strong>Function selector and arguments :</strong></h3><p>Function selector is represented by hashing the function’s signature with keccak256 and by taking the first 4 bytes of the result. The arguments passed to the function are then treated like a tuple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSnpkjmjFohPf0jJhRBuHg.png" /><figcaption>Fig5. Illustrated function</figcaption></figure><h3><strong>Examples :</strong></h3><p>In fig6. you can see a dynamic array of fixed struct. As you can see the number of element is prefixing the encoding of the elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*A3im3C_9VkWO3oO4PKBnng.png" /><figcaption>Fig6. Dynamic array of fixed struct</figcaption></figure><p>In fig7. You can see a dynamic array of dynamic struct, this can be for example a list of differents assets for a shop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWf2If24HUkOYsBsgqwaEg.png" /><figcaption>Fig7. Array of Dynamic struct</figcaption></figure><p>In fig8. you can see a tuple containing the two arrays of fig5. and fig6. This can be for example a function which is returning (array1, array2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErkGdAWsyLU8vug_0Dn2XQ.png" /><figcaption>Fig8. Tuple of arrays</figcaption></figure><p>And finally, an example of commented bytecode. This is an asset for the game : <a href="https://beyond-the-void.net/">Beyond The Void</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*A_Bhh8vRR7nJ_XXtVTEGIg.png" /><figcaption>Fig9. Commented bytecode of struct asset</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f470927092d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/b2expand/abi-encoding-explanation-4f470927092d">Ethereum ABI Encoding Explanation</a> was originally published in <a href="https://medium.com/b2expand">B2Expand</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>