{"id":10786,"date":"2025-04-07T16:54:29","date_gmt":"2025-04-07T14:54:29","guid":{"rendered":"https:\/\/wsj-crypto.com\/?p=10786"},"modified":"2025-04-07T16:54:29","modified_gmt":"2025-04-07T14:54:29","slug":"mastering-pyethereum-and-serpent-a-comprehensive-programming-guide","status":"publish","type":"post","link":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/","title":{"rendered":"Mastering Pyethereum and Serpent: A Comprehensive Programming Guide"},"content":{"rendered":"<p> &#8220;`html<br \/>\n<\/p>\n<div id=\"\">\n<p class=\"chakra-text css-gi02ar\"><i>The material presented in this guide is designed to pertain to PoC5. Most of the directives provided beneath will not function in the previous PoC4 versions of AlethZero (C++) and Ethereal (Go)<!-- --><\/i><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">In the preceding weeks, we have introduced a considerable amount of modifications to the Ethereum protocol. POC4, which brought a significant array of changes initiated by Gavin Wood and myself, was <!-- --><a class=\"chakra-link css-ug8vf0\" href=\"https:\/\/blog.ethereum.org\/2014\/03\/20\/the-latest-evm-ethereum-is-a-trust-free-closure-system\">revealed as an informal explanation<!-- --><\/a> a fortnight ago and has been formally detailed in Gavin Wood\u2019s \u201cyellow paper\u201d at <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/gavwood.com\/Paper.pdf\"\/><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/gavwood.com\/Paper.pdf\">http:\/\/gavwood.com\/Paper.pdf<!-- --><\/a>. The specification of the protocol did undergo substantial changes, yet concurrently, aspects are becoming more stable; we understand why we wish transactions to incur fees rather than contracts, so that\u2019s unlikely to change, we are aware that code and data will remain distinct, and the byte-based code and memory along with the 32-byte-block-based stack and storage are unlikely to undergo modifications, plus we recognize that the functionalities of the EVM broadly will be comparable to their current state instead of resembling an intricate Merkle-code-tree arrangement. POC4 has granted me what I desired from <!-- --><a class=\"chakra-link css-ug8vf0\" href=\"https:\/\/blog.ethereum.org\/2014\/02\/03\/introducing-ethereum-script-2-0\">Ethereum Script 2<!-- --><\/a>, presented Gavin a much more optimization-appropriate VM architecture, and offered users a <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/cpp-ethereum\/wiki\/LLL-Examples-for-PoC-4\">sparkling new currency<!-- --><\/a>. Simultaneously, Chen Houwu, Heiko Kees, and Konrad Feldmeier have stepped up as our primary Python developers, and the networking segment of the pyethereum client is progressing towards readiness for communication with Go and C++. Alongside all the administrative duties that come with holding a crucial position in an extensive project, I have taken it upon myself to enhance the pyethereum VM implementation and the compiler for the HLL programming syntax.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The goal of this entry will be to deliver a comprehensive technical guide into the functionalities of pyethereum and Serpent, demonstrating how you can begin creating the instruments to construct your own contracts and applications. The Bitcoin Expo hackathon is occurring today and tomorrow, so feel welcome to make an Ethereum contract your endeavor if you are among those participating.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">First and foremost, importantly, HLL has been renamed; the language is now referred to as Serpent. Why? Because it\u2019s fundamentally Python.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">With the latest enhancements to the compiler, Serpent is now a highly comprehensive programming language, equipped with powerful capabilities including:<!-- --><\/p>\n<p><!-- --><\/p>\n<ul role=\"list\" class=\"css-1onhfjo\">\n<li class=\"css-cvpopp\">Arrays (e.g., x[0] = 123)<!-- --><\/li>\n<li class=\"css-cvpopp\">Array literals (e.g., x = [ 34, 56, 78 ])<!-- --><\/li>\n<li class=\"css-cvpopp\">Nested arrays (e.g., z = [ 34, [ 5, 6 ], y ])<!-- --><\/li>\n<li class=\"css-cvpopp\">Hexadecimal support (e.g., receiving_address = 0xb156066c2978d7b9188f2467b815d4c62ae32fe2)<!-- --><\/li>\n<li class=\"css-cvpopp\">String support (e.g., x = &#8220;cow&#8221;)<!-- --><\/li>\n<li class=\"css-cvpopp\">Inline message calling (e.g., usdprice = eth * msg(ethcontract,0,tx.gas-100,[500],1))<!-- --><\/li>\n<li class=\"css-cvpopp\">Out-of-line message calling (e.g., msg(multifeedcontract,0,tx.gas-100,inparray,5,outarray,5))<!-- --><\/li>\n<li class=\"css-cvpopp\">Simple value transfer operation (e.g., send(receiver, value, tx.gas-100))<!-- --><\/li>\n<li class=\"css-cvpopp\">Returning values (e.g., return(45) and return([10,20,30,40],4))<!-- --><\/li>\n<li class=\"css-cvpopp\">Treating message data and storage as arrays (e.g., contract.storage[1000] = msg.data[0])<!-- --><\/li>\n<li class=\"css-cvpopp\">Byte arrays (e.g., x = bytes(100), setch(x,45,&#8221;c&#8221;)), y = getch(x,45)<!-- --><\/li>\n<\/ul>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The aim of the Serpent language is to simplify the task of programming smart contracts and decentralized applications on Ethereum as easily as coding mundane command line applications is in Python. The language is crafted to be maximally clear and straightforward, merging the advantages of a compiled language with an accessible coding experience. Just the logic, and solely the logic. Regrettably, floating-point numbers are lacking, along with advanced constructs such as list comprehensions and closures, but aside from that, Serpent encompasses practically everything you require.<!-- --><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"getting-started\">Initiating the Process<!-- --><\/h3>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">How do you program in Serpent? The initial step is to establish the development and execution setting. To achieve this, first download two libraries: <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/github.com\/ethereum\/pyethereum\">pyethereum<!-- --><\/a> and <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/github.com\/ethereum\/pyethereum\">serpent<!-- --><\/a>. The easiest method to acquire them is to either grab the zip files from Github and extract them, or execute git clone <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/github.com\/ethereum\/pyethereum\"\/><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/github.com\/ethereum\/pyethereum\">http:\/\/github.com\/ethereum\/pyethereum<!-- --><\/a> and git clone<!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/github.com\/ethereum\/serpent\"\/><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/github.com\/ethereum\/serpent\">http:\/\/github.com\/ethereum\/serpent<!-- --><\/a>. Afterwards, navigate to the pyethereum directory, and execute sudo python setup.py install to install pyethereum on your system, and repeat this for serpent.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now that the software is set up, let&#8217;s dive right in. To begin, try this:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">serpent compile_to_assembly &#8216;x = 5&#8217;<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">[&#8220;<!-- --><span class=\"math math-inline\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<!-- --><\/mi><mi>e<!-- --><\/mi><mi>g<!-- --><\/mi><mi>i<!-- --><\/mi><mi>n<!-- --><\/mi><mi>c<!-- --><\/mi><mi>o<!-- --><\/mi><mi>d<!-- --><\/mi><msub><mi>e<!-- --><\/mi><mn>0<!-- --><\/mn><\/msub><mi mathvariant=\"normal\">.<!-- --><\/mi><mi>e<!-- --><\/mi><mi>n<!-- --><\/mi><mi>d<!-- --><\/mi><mi>c<!-- --><\/mi><mi>o<!-- --><\/mi><mi>d<!-- --><\/mi><msub><mi>e<!-- --><\/mi><mn>0<!-- --><\/mn><\/msub><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>D<!-- --><\/mi><mi>U<!-- --><\/mi><mi>P<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>M<!-- --><\/mi><mi>S<!-- --><\/mi><mi>I<!-- --><\/mi><mi>Z<!-- --><\/mi><mi>E<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>S<!-- --><\/mi><mi>W<!-- --><\/mi><mi>A<!-- --><\/mi><mi>P<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>M<!-- --><\/mi><mi>S<!-- --><\/mi><mi>I<!-- --><\/mi><mi>Z\n&#8220;&#8220;&#8220;html\n<!-- --><\/mi><mi>E<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><\/mrow><annotation encoding=\"application\/x-tex\">begincode_0.endcode_0&#8243;, &#8220;DUP&#8221;, &#8220;MSIZE&#8221;, &#8220;SWAP&#8221;, &#8220;MSIZE&#8221;, &#8220;<!-- --><\/annotation><\/semantics><\/math><\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.8889em;vertical-align:-0.1944em\"\/><span class=\"mord mathnormal\">b<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em\">g<!-- --><\/span><span class=\"mord mathnormal\">in<!-- --><\/span><span class=\"mord mathnormal\">co<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord\"><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3011em\"><span style=\"top:-2.55em;margin-left:0em;margin-right:0.05em\"><span class=\"pstrut\" style=\"height:2.7em\"\/><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">0<!-- --><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<!-- --><\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em\"><span\/><\/span><\/span><\/span><\/span><\/span><span class=\"mord\">.<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\">n<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord mathnormal\">co<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord\"><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3011em\"><span style=\"top:-2.55em;margin-left:0em;margin-right:0.05em\"><span class=\"pstrut\" style=\"height:2.7em\"\/><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">0<!-- --><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<!-- --><\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em\"><span\/><\/span><\/span><\/span><\/span><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.02778em\">D<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.10903em\">U<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">P<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">MS<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.07847em\">I<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">ZE<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">S<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">W<!-- --><\/span><span class=\"mord mathnormal\">A<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">P<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><\/span><\/span><\/span><\/span>begincode_0&#8243;, &#8220;CALLDATACOPY&#8221;, &#8220;RETURN&#8221;, &#8220;~begincode_0&#8221;, &#8220;#CODE_BEGIN&#8221;, 5, 0, &#8220;MSTORE&#8221;, &#8220;#CODE_END&#8221;, &#8220;~endcode_0&#8221;]<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The compile_to_assembly command translates the code into an intermediate human-readable \u201cassembly language\u201d format instead of standard bytecode. Using the traditional serpent compilation would result in a significantly more difficult, yet compact, output of 6005515b525b600a37f26005600054. In this scenario, the &#8220;core&#8221; of the code is [5, 0, &#8220;MSTORE&#8221;], which places the value 5 into memory position 0, while the remainder of the code essentially indicates to return a contract containing that code. Another potentially useful command is serpent get_vars; it provides a list of all variables along with their respective memory indices. Thus, you get {&#8216;x&#8217;: 0}, which signifies that the compiler opts to use memory index 0 to hold the variable x. The final intriguing command is parse, utilized to transform Serpent into an intermediate high-level parse tree. Given that Serpent is a programming language, we aim to execute programs, making it imperative to create contracts and run them as swiftly as possible. Let\u2019s proceed with that. First, establish a file named \u201cnamecoin.se\u201c and insert the following code into it:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">if !contract.storage[msg.data[0]]:<br \/>\ncontract.storage[msg.data[0]] = msg.data[1]<br \/>\nreturn(1)<br \/>\nelse:<br \/>\nreturn(0)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This is the beloved two-line Namecoin example, enhanced with return values for ease of use in this tutorial. Executing serpent compile namecoin.se should result in:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">6025515b525b600a37f260003556601b596020356000355760015b525b54602052f260255860005b525b54602052f2<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now, let\u2019s verify if we can indeed run the code. To achieve this, the first action is to create an account for ourselves. The process here closely mirrors that in my Python Bitcoin library <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/vbuterin\/pybitcointools\">pybitcointools<!-- --><\/a>; generally, anyone familiar with pybitcointools should find pyethereum quite comfortable, although, regrettably, it was not truly feasible to adhere to pybitcointools\u2019 \u201cno classes\u201d principle throughout the code in pyethereum. The initial step is to produce a private key:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">pyethtool sha3 cow<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">In actual production code, you should clearly substitute \u201ccow\u201d with a genuinely secure password. If you desire your account to be a \u201cbrainwallet\u201d that is easy to remember, my primary suggestion is to prepend a username, e.g., \u201cvbuterin:bl@hbl@hm0nk33y#!$!%\u201d, ensuring that attackers must target you specifically instead of conducting a widespread attack on all users; assuming 10000 brainwallet users, this lowers your risk from a trial-and-error attack by 99.99%.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Should you wish to utilize your key later, on any conventional Linux shell, you can also type in key=<!-- --><span class=\"chakra-text css-ons8vw\">pyethtool sha3 cow<\/span>, after which use$key for subsequent key utilization. We will adopt that format from here onward, so if you are following along, you should also perform both tasks:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">key=<!-- --><span class=\"chakra-text css-ons8vw\">pyethtool sha3 cow<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n&#8220;`<\/p>\n<p class=\"chakra-text css-gi02ar\">code=<!-- --><span class=\"chakra-text css-ons8vw\">serpent compile namecoin.se<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now, let\u2019s proceed further.<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">addr=<!-- --><span class=\"chakra-text css-ons8vw\">pyethtool privtoaddr $key<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">echo $addr<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">cd2a3d9f938e13cd947ec05abc7fe734df8dd826<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Next, we generate a new genesis block, setting the primary endowment at 1018 wei (1 ether) for your address.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">genesis=<!-- --><span class=\"chakra-text css-ons8vw\">pyethtool mkgenesis $addr 1000000000000000000<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">echo $genesis<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">f8b2f8aea00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0bcddd284bf396739c224dba0411566c891c32115feb998a3e2b4e61f3f35582a80834000008087038d7ea4c68000830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now that this is settled, we can focus on performing actions on the block. The only method to execute anything in a blockchain framework is to create and execute a transaction. Here, we require multiple transactions: the initial one to establish the contract, followed by subsequent ones to actively use it. Here&#8217;s how to set up the contract:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">unsignedtx=<!-- --><span class=\"chakra-text css-ons8vw\">pyethtool mkcontract 0 0 $code<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">echo $unsignedtx<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">f83c8085e8d4a510008227108080af6025515b525b600a37f260003556601b596020356000355760015b525b54602052f260255860005b525b54602052f2<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">tx=<!-- --><span class=\"chakra-text css-ons8vw\">pyethtool sign $unsignedtx $key<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">echo $tx<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">f87f8085e8d4a510008227108080af6025515b525b600a37f260003556601b596020356000355760015b525b54602052f260255860005b525b54602052f21ca04565b5a48b29ef623ad2caffe0917a3fc6a6f1b50f1df06876f3caa6fb4957c6a0123c928257c1f248fb3d362c125a0aea091ab08467efb52f8c3676ca73d727bf<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Alternatively, the simpler approach:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">tx=<!-- --><span class=\"chakra-text css-ons8vw\">pyethtool mkcontract 0 0 $code | pyethtool -s sign $key<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">echo $tx<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">f87f8085e8d4a510008227108080af6025515b525b600a37f260003556601b596020356000355760015b525b54602052f260255860005b525b54602052f21ca04565b5a48b29ef623ad2caffe0917a3fc6a6f1b50f1df06876f3caa6fb4957c6a0123c928257c1f248fb3d362c125a0aea091ab08467efb52f8c3676ca73d727bf<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The initial segment in mkcontract is a nonce, which must correspond to the tally of transactions already dispatched from that account. This nonce requirement is intended to avert replay assaults; without it, if one sent Bob 200 ether, he could merely replay that transaction repetitively until the funds deplete. However, with the nonce in place, the transaction may only succeed once. The subsequent field denotes the ether amount to dispatch (in the context of contract creation, the ether amount to initially allocate to the contract), while the final field represents the code. It is important to notice that the Transaction.contract<!-- --><i>function call<!-- --><\/i> also includes two additional fields amid value and recipient: gasprice and startgas. Pyethtool helps by initializing these parameters to 1 szabo (i.e., 10^12 wei or one millionth of an ether) for each gas and 10,000 gas, respectively. This provides a theoretical upper limit of 10,000 computational steps for the code to execute, though in practice, it may deplete after 1,000 if numerous costly operations are employed. Lastly, upon generating the transaction, it must be signed with your private key.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Once that task is completed, we simply:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">pyethtool applytx <!-- --><span class=\"math math-inline\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>g<!-- --><\/mi><mi>e<!-- --><\/mi><mi>n<!-- --><\/mi><mi>e<!-- --><\/mi><mi>s<!-- --><\/mi><mi>i<!-- --><\/mi><mi>s<!-- --><\/mi><\/mrow><annotation encoding=\"application\/x-tex\">genesis <!-- --><\/annotation><\/semantics><\/math><\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.854em;vertical-align:-0.1944em\"\/><span class=\"mord mathnormal\" style=\"margin-right:0.03588em\">g<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\">n<!-- --><\/span><span class=\"mord mathnormal\">es<!-- --><\/span><span class=\"mord mathnormal\">i<!-- --><\/span><span class=\"mord mathnormal\">s<!-- --><\/span><\/span><\/span><\/span><\/span>tx<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">{&#8220;result&#8221;: &#8220;da7ce79725418f4f6e13bf5f520c89cec5f6a974&#8221;, &#8220;block&#8221;: &#8220;f9017ef8d0a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a00bcec36bf7ffc27418b1746986574526efeb09b34f733039749f291f778d4aaca03575f60ad6c929d7c98a50a12ff1ef9b07ecf3182e74962872064648a66f3da0834000008087038d7ea4c68000830f42408204b08080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829f8a9f8a7b881f87f8085e8d4a510008227108080af6025515b525b600a37f260003556601b596020356000355760015b525b54602052f260255860005b525b54602052f21ca04565b5a48b29ef623ad2caffe0917a3fc6a6f1b50f1df06876f3caa6fb4957c6a0123c928257c1f248fb3d362c125a0aea091ab08467efb52f8c3676ca73d727bfa00bcec36bf7ffc27418b1746986574526efeb09b34f733039749f291f778d4aac8204b0c0&#8221;}<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This provides you with two outputs. The first is the contract&#8217;s address, while the second represents the new block data. Be mindful that the block data does not encompass the complete block; additional state data resides in the statedb directory. Therefore, attempting to deserialize the block on a new machine may not succeed. From the values returned, assign the first output to contract and the second to med for future reference. Following that, we need to devise a transaction to utilize this contract. Let\u2019s say we wish to register &#8220;george&#8221; with 45. However, to accomplish this, we are required to complete another tedious task: package.up the information. Luckily, the Serpent compiler provides a tool for accomplishing just that:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">data=<!-- --><span class=\"chakra-text css-ons8vw\">echo &#8216;[&#8220;george&#8221;,45]&#8217; | serpent -j encode_datalist<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">echo $data<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">000000000000000000000000000000000000000000000000000067656f726765000000000000000000000000000000000000000000000000000000000000002d<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The namecoin agreement accepts data in two segments: the key and the value, allowing us to place them into a JSON array and employ Serpent to encode it. The encoder can handle both strings and numbers as the distinct elements within the array. It\u2019s important to note that unfortunately, Python&#8217;s JSON decoder mandates double quotes for internal strings; &#8220;[&#8216;george&#8217;,45]&#8221; would not function correctly.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now, we execute the following:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">tx2=<!-- --><span class=\"chakra-text css-ons8vw\">pyethtool mktx 1 $contract 0 $data | pyethtool -s sign $key<\/span><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">echo $tx2<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">f8a50185e8d4a5100082271094da7ce79725418f4f6e13bf5f520c89cec5f6a97480b840000000000000000000000000000000000000000000000000000067656f726765000000000000000000000000000000000000000000000000000000000000002d1ba064363844c718f0f38907d39508adb2c2b9134e52e7d436fb20965044c01f41c2a0e1123d26cf810c4ef9d397974e2fc336d16e452d71df3c3d7245b40ed12c603b<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Additionally:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">pyethtool applytx <!-- --><span class=\"math math-inline\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>m<!-- --><\/mi><mi>e<!-- --><\/mi><mi>d<!-- --><\/mi><\/mrow><annotation encoding=\"application\/x-tex\">med <!-- --><\/annotation><\/semantics><\/math><\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6944em\"\/><span class=\"mord mathnormal\">m<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><\/span><\/span><\/span><\/span>tx2<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">{&#8220;result&#8221;: &#8220;0000000000000000000000000000000000000000000000000000000000000001&#8221;, &#8220;block&#8221;: &#8220;f9024ef8d0a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a066d2524d921fadb5056983cf4bb215d339cdaeb7048b8913bfdf8fe867eb5682a0d669d3b5cfb150e4ef7f900cc613b0231abc8551544c389ddcd6668f784c4cb3834000008087038d7ea4c68000830f4240820a8f8080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829f90178f8a7b881f87f8085e8d4a510008227108080af6025515b525b600a37f260003556601b596020356000355760015b525b54602052f260255860005b525b54602052f21ca04565b5a48b29ef623ad2caffe0917a3fc6a6f1b50f1df06876f3caa6fb4957c6a0123c928257c1f248fb3d362c125a0aea091ab08467efb52f8c3676ca73d727bfa00bcec36bf7ffc27418b1746986574526efeb09b34f733039749f291f778d4aac8204b0f8cdb8a7f8a50185e8d4a5100082271094da7ce79725418f4f6e13bf5f520c89cec5f6a97480b840000000000000000000000000000000000000000000000000000067656f726765000000000000000000000000000000000000000000000000000000000000002d1ba064363844c718f0f38907d39508adb2c2b9134e52e7d436fb20965044c01f41c2a0e1123d26cf810c4ef9d397974e2fc336d16e452d71df3c3d7245b40ed12c603b<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Registration completed successfully! The output consists of two values, just like previously: the first value indicates the new block state and the second is the reply from the contract. According to the contract&#8217;s definition above, &#8220;1&#8221; signifies success. Now, to confirm, let\u2019s establish the end to the block hex received from the preceding command and inspect the state:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<blockquote class=\"chakra-code css-1cl98my\"><p>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">pyethtool getstate $end<!-- --><\/p>\n<p><!-- --><\/p><\/blockquote>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">{&#8216;nonce&#8217;: &#8216;x04x99OgxdcUxb0x9ex81Jxb7xffxc8xdf6x86xb4xafxb2xbbSxe6x0exaex97xefx04?xe0?xb8)&#8217;, &#8216;min_gas_price&#8217;: 1000000000000000L, &#8216;extra_data&#8217;: &#8221;, &#8216;state_root&#8217;: &#8216;fxd2RMx92x1fxadxb5x05ix83xcfKxb2x15xd39xcdxaexb7x04x8bx89x13xbfxdfx8fxe8gxebVx82&#8217;, &#8216;difficulty&#8217;: 4194304L, &#8216;timestamp&#8217;: 0L, &#8216;number&#8217;: 0L, &#8216;gas_used&#8217;: 2703L, &#8216;coinbase&#8217;: &#8216;0000000000000000000000000000000000000000&#8217;, &#8216;tx_list_root&#8217;: &#8216;xd6ixd3xb5xcfxb1Pxe4xefx7fx90x0cxc6x13xb0#x1axbcx85QTL8x9dxdcxd6fx8fxLLxb3&#8217;, &#8216;state&#8217;: {&#8216;0000000000000000000000000000000000000000&#8217;: {&#8216;nonce&#8217;: 0L, &#8216;balance&#8217;: 2703000000000000L, &#8216;storage&#8217;: {}, &#8216;code&#8217;: &#8221;}, &#8216;da7ce79725418f4f6e13bf5f520c89cec5f6a974&#8217;: {&#8216;nonce&#8217;: 0L, &#8216;balance&#8217;: 0L, &#8216;storage&#8217;: {113685359126373L: 45L}, &#8216;code&#8217;: &#8216;60003556601b596020356000355760015b525b54602052f260255860005b525b54602052f2&#8217;}, &#8216;cd2a3d9f938e13cd947ec05abc7fe734df8dd826&#8217;: {&#8216;nonce&#8217;: 2L, &#8216;balance&#8217;: 997297000000000000L, &#8216;storage&#8217;: {}, &#8216;code&#8217;: &#8221;}}, &#8216;uncles_hash&#8217;: &#8216;x1dxccMxe8xdexc7]zxabx85xb5gxb6xccxd4x1axd3x12Ex1bx94x8atx13xf0xa1Bxfd@xd4x93G&#8217;, &#8216;prevhash&#8217;: &#8216;x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00&#8217;, &#8216;gas_limit&#8217;: 1000000L}<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">You can observe the contract account near the start of the state outline, with &#8220;george&#8221; assigned to 45 as anticipated. We have completed the task! As an exercise, attempt crafting two additional transactions; one registering &#8220;george&#8221; to 60 and another registering &#8220;harry&#8221; to 80. If you apply them all in the correct order following these two, the transaction registering &#8220;george&#8221; to 60 should yield 0, while the one registering &#8220;harry&#8221; to 80 should be successful.<!-- --><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"doing-it-in-python\">Executing it in Python<!-- --><\/h3>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This is pyethtool, the command-line tool. Now, how would it function using pyethereum itself? As it turns out, it\u2019s quite straightforward. Here\u2019s the session:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; import serpent<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; from pyethereum import transactions, blocks, processblock, utils<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; code = serpent.compile(open(&#8216;namecoin.se&#8217;).read())<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; key = utils.sha3(&#8216;cow&#8217;)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; addr = utils.privtoaddr(key)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; genesis = blocks.genesis({ addr: 10**18 })<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; tx1 = transactions.contract(0,10**12,10000,0,code).sign(key)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; result, contract = processblock.apply_tx(genesis,tx1)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; tx2 = transactions.Transaction(1,10**12,10000,contract,0,serpent.encode_datalist([&#8216;george&#8217;,45])).sign(key)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; result, ans = processblock.apply_tx(genesis,tx2)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; serpent.decode_datalist(ans)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">[1]<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; genesis.to_dict()<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&#8216;nonce&#8217;: &#8216;x04x99OgxdcUxb0x9ex81Jxb7xffxc8xdf6x86xb4xafxb2xbbSxe6x0exaex97xefx04?xe0?xb8)&#8217;, &#8216;min_gas_price&#8217;: 1000000000000000L, &#8216;extra_data&#8217;: &#8221;, &#8216;state_root&#8217;: &#8221;, &#8216;difficulty&#8217;: 4194304, &#8216;timestamp&#8217;: 0, &#8216;number&#8217;: 0, &#8216;gas_used&#8217;: 2712L, &#8216;coinbase&#8217;: &#8216;0000000000000000000000000000000000000000&#8217;, &#8216;tx_list_root&#8217;: &#8216;x17x90x87x966xbdb!x14|Rxb0&amp; xb04x90xb9bsx12x85x90xdaBxedx83n*x8eEx8e&#8217;, &#8216;state&#8217;: {&#8216;0000000000000000000000000000000000000000&#8217;: {&#8216;nonce&#8217;: 0L, &#8216;balance&#8217;: 2712000000000000L, &#8216;storage&#8217;: {}, &#8216;code&#8217;: &#8221;}, &#8216;da7ce79725418f4f6e13bf5f520c89cec5f6a974&#8217;: {&#8216;nonce&#8217;: 0L, &#8216;balance&#8217;: 0L, &#8216;storage&#8217;: {113685359126373L: 45L}, &#8216;code&#8217;: &#8216;60003556601e596020356000355760015b525b54602052f260285860005b525b54602052f2&#8217;}, &#8216;cd2a3d9f938e13cd947ec05abc7fe734df8dd826&#8217;: {&#8216;nonce&#8217;: 2L, &#8216;balance&#8217;: 997288000000000000L, &#8216;storage&#8217;: {}, &#8216;code&#8217;: &#8221;}}, &#8216;uncles_hash&#8217;: &#8216;x1dxccMxe8xdexc7]zxabx85xb5gxb6xccxd4x1axd3x12Ex1bx94x8atx13xf0xa1Bxfd@xd4x93G&#8217;, &#8216;prevhash&#8217;: &#8216;x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00&#8217;, &#8216;gas_limit&#8217;: 1000000}<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; genesis.get_balance(addr)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">997288000000000000L<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">&gt;&gt;&gt; genesis.get_storage_data(contract,&#8217;george&#8217;)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">45L<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Another crucial command is processblock.debug = 1; this initiates step-by-step printing of code execution, assisting you in identifying errors in your contract code &#8211; or within my pyethereum VM or Serpent implementation!<!-- --><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"getting-into-the-code\">Diving into the Code<!-- --><\/h3>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">So that concludes your primer on utilizing pyethereum. Now, let\u2019s delve into the most enjoyable aspect, crafting contracts. For enhanced readability, let\u2019s present the Namecoin contract again:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">if !contract.storage[msg.data[0]]:<br \/>\ncontract.storage[msg.data[0]] = msg.data[1]<br \/>\nreturn(1)<br \/>\nelse:<br \/>\nreturn(0)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">What is the purpose of this contract? Essentially, it adopts a name registration database, simply employing that as the exclusive function for the contract\u2019s long-term storage. Theoretically, contract code has three locations for data placement: stack, memory, and storage. Among these, stack and memory are utilized implicitly in Serpent to facilitate arithmetic and variable handling; however, long-term storage is the sole option that endures after execution concludes. In this scenario, when you register &#8220;george&#8221; with 45, the contract first verifies if contract.storage[&#8220;george&#8221;] is non-zero, i.e., it is zero. If so, it assigns that storage index the provided value, 45, before returning 1. If it is not, it returns zero. Be aware that this contract does not facilitate access by other contracts; it is primarily usable by external applications. More sophisticated name registries would provide an API for contracts to retrieve data corresponding to a name as well.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now, let&#8217;s proceed to a more complex example:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">init:<br \/>\ncontract.storage[0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826] = 1000000<br \/>\ncode:<br \/>\nif msg.datasize == 1:<br \/>\naddr = msg.data[0]<br \/>\nreturn(contract.storage[addr])<br \/>\nelse:<br \/>\nfrom = msg.sender<br \/>\nfromvalue = contract.storage[from]<br \/>\nto = msg.data[0]<br \/>\nvalue = msg.data[1]<br \/>\nif fromvalue &gt;= value:<br \/>\ncontract.storage[from] = fromvalue &#8211; value<br \/>\ncontract.storage[to] = contract.storage[to] + value<br \/>\nreturn(1)<br \/>\nelse:<br \/>\nreturn(0)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This constitutes the &#8220;currency contract&#8221;, or specifically a refined version of it that includes return values for simpler debugging. This contract is intriguing for several reasons. Firstly, it contains an initialization procedure, which is invoked when the contract is created. This establishes an account with 1000000 currency units allotted to that account.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Subsequently, there are two pathways in the code. Initially, incoming messages might carry only one data field. In such a case, these messages are interpreted as balance inquiries, simply returning the balance of the specified address. It is noteworthy that msg.data[0] supplies the integer occupying bytes 0&#8230;31 of the transaction data, msg.data[1] provides the integer occupying bytes 32&#8230;63, and so forth. This convenience was introduced in Serpent; the foundational transaction data is formatted entirely in bytes. Incidentally, this necessity for Serpent&#8217;s encode_datalist function to generate transaction data hence arises.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">In contrast, incoming messages might comprise two data fields. In that instance, the messages are regarded as requests to transfer to that address. The sender is inferred from the origin of the message, with the recipient and the value derived from the first two fields (i.e., the initial 64 bytes) in msg.data. If there are sufficient funds to execute the transfer, the money is transferred, returning 1; otherwise, it returns 0.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><b>Challenge<!-- --><\/b>: devise a currency contract that deducts a fee, denominated in its internal currency, from each transaction, while refunding a small amount of ether to anyone executing a successful transaction, thus alleviating the need for individuals (or contracts) operating in this currency to maintain simultaneous currency and ether balances. This contract would also encompass a third transaction type, potentially taking zero arguments, via which an individual can acquire internal currency units from the contract by sending it ether. The contract should monitor two variables: its own balance in currency and its ether balance, dynamically adjusting the transaction fee and exchange rate to maintain both balances in &#8211; well, in an approximate equilibrium.<!-- --><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"contracts-calling-contracts\">Contracts Invoking Other Contracts<!-- --><\/h3>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This is a proprietary data feed contract:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">owner = 0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826<br \/>\nif msg.sender == owner and msg.datasize == 2:<br \/>\ncontract.storage[msg.data[0]] = msg.data[1]<br \/>\nreturn(1)<br \/>\nelse:<br \/>\nreturn(contract.storage[msg.data[0]])<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This contract is crafted to function as a key\/value pair editable solely by its owner while permitting anyone to inquire its contents; the aim is for the owner to utilize various storage indices to document fluctuating data such as the USD price of ether. There are two primary &#8220;clauses&#8221; in this contract, one for altering storage initiated when a key and value are supplied, and the message is sent by the contract&#8217;s owner, alongside another for merely reading storage. The msg.datasize variable signifies the number of 32-byte data fields present in the message data. There are no particularly new features here; this contract remains quite straightforward, and I encourage you to first follow the logic to ensure understanding before experimenting with the contract, initiating it within a block, and subsequently submitting set and query transactions.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">However, the intriguing segment unfolds when we utilize this contract within another contract. Introducing this intricate creation, a hedging contract:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">if !contract.storage[1000]:<br \/>\ncontract.storage[1000] = msg.sender<br \/>\ncontract.storage[1002]&#8220;`python<br \/>\n = msg.value<br \/>\ncontract.storage[1003] = msg.data[0]<br \/>\ncontract.storage[1004] = msg.data[1]<br \/>\nreturn(1)<br \/>\nelif !contract.storage[1001]:<br \/>\nethvalue = contract.storage[1002]<br \/>\nif msg.value >= ethvalue:<br \/>\ncontract.storage[1001] = msg.sender<br \/>\ndatasource = contract.storage[1003]<br \/>\ndataindex = contract.storage[1004]<br \/>\nothervalue = ethvalue * msg(datasource,0,tx.gas-100,[dataindex],1)<br \/>\ncontract.storage[1005] = othervalue<br \/>\ncontract.storage[1006] = block.timestamp + 86400<br \/>\nreturn([2,othervalue],2)<br \/>\nelse:<br \/>\ndatasource = contract.storage[1003]<br \/>\ndataindex = contract.storage[1004]<br \/>\nothervalue = contract.storage[1005]<br \/>\nethvalue = othervalue \/ msg(dataindex,0,tx.gas-100,[datasource],1)<br \/>\nif ethvalue >= contract.balance:<br \/>\nsend(contract.storage[1000],contract.balance,tx.gas-100)<br \/>\nreturn(3)<br \/>\nelif block.timestamp > contract.storage[1006]:<br \/>\nsend(contract.storage[1001],contract.balance &#8211; ethvalue,tx.gas-100)<br \/>\nsend(contract.storage[1000],ethvalue,tx.gas-100)<br \/>\nreturn(4)<br \/>\nelse:<br \/>\nreturn(5)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This contract is extensive because it&#8217;s structured to be more test-friendly; an efficient implementation is about half its size. The operation of the contract is as follows:<!-- --><\/p>\n<p><!-- --><\/p>\n<ol role=\"list\" class=\"css-13a5a39\">\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Party A inputs X ether along with a data feed contract D and a currency code C as data elements, which are recorded at contract storage index 1000. X, D, and C are documented in storage indices 1002, 1003, and 1004. For instance, if the currency code denotes USD.<!-- --><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Party B submits X ether, registering at contract storage index 1001. The contract subsequently invokes D with data C to ascertain the price of ether in the specified currency, applying this to calculate V, the value in USD contributed by each participant. V is allocated at index 1005, along with a due time set for 24 hours ahead stored at index 1006.<!-- --><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Perhaps, the price of ether in USD declines by more than 50%. If this occurs, then there isn\u2019t enough ether in the contract overall to satisfy V USD. To avert this, the moment the price drops below the 50% threshold, anyone (typically A) can initiate the contract to retrieve all 2X ether into A&#8217;s address, effectively allowing A to recover nearly the entire amount measured in USD that A invested, leaving B with nothing. If this transpires, the contract returns 3.<!-- --><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Similarly, after a day has passed, anyone may transmit a transaction to &#8220;ping&#8221; the contract, triggering it to send V USD&#8217;s worth of ether to A and the remaining ether to B, which results in a return of 4.<!-- --><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">In the absence of a &#8220;margin call&#8221; or &#8220;expiry&#8221; event, a ping to the contract produces no effect and returns 5.<!-- --><\/p>\n<p><!-- --><\/li>\n<\/ol>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The objective of the hedging contract is that A gains by consistently receiving the same amount of USD that he invested, whereas B profits if he anticipates that the value of ether will increase, considering that a 10% increment in the ether price will, under these conditions, yield him a 20% return. USD can certainly be replaced with various alternatives, such as CNY, gold, or the consumer price index.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The notable new features examined here are msg, send, and array literals. Both msg and send serve as methods to transmit messages to other contracts. The syntaxes are:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\u00a0<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">send(to, value, gas)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">out = msg(to, value, gas, datastart, datalength)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">msg(to, value, gas, datastart, datalength, outstart, outlength)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Send is more straightforward, presupposing all you need is to transfer funds without any additional complexities involved. The latter two represent equivalent methods of transmitting a message to another contract, differing solely in their handling of the output: the first restricts output to 32 bytes and directly assigns it to a variable, while the second accepts two parameters for the memory location where the output should be stored. The &#8220;output&#8221; of a message remains empty if the recipient is either nonexistent, an externally owned account, or does not specifically indicate a return value; when a return value is specified, it corresponds to that value (where &#8220;value&#8221; signifies an arbitrary-length byte array, not a 32-byte number). Therefore, both phrases essentially imply the same concept:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">d = array(3)<br \/>\nd[0] = 5<br \/>\nd[1] = 10<br \/>\nd[2] = 15<br \/>\nx = msg(A, B, C, d, 3)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">And:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">d = array(3)<br \/>\nd[0] = 5<br \/>\nd[1] = 10<br \/>\nd[2] = 15<br \/>\nw = array(1)<br \/>\nmsg(A, B, C, d, 3, w, 1)<br \/>\nx = w[0]<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">In the above contract example, we utilized the data feed contract to deliver the price of ether in USD, directly incorporating it into the equation othervalue = ethvalue * msg(datasource, 0, tx.gas &#8211; 100, [dataindex], 1).<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Array literals represent another handy convenience feature; the genuinely optimal method to write the preceding code is as follows:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">x = msg(A, B, C, [5, 10, 15], 3)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">However, it is unfortunate that you still need to specify the array length. Nonetheless, in this instance, the array itself is instantiated and referenced inline, eliminating the need for manual setup. All the magic is executed by the Serpent compiler.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">So, that wraps up today&#8217;s discussion. What might you consider coding in Serpent? Here are several potential ideas:<!-- --><\/p>\n<p><!-- --><\/p>\n<ol role=\"list\" class=\"css-13a5a39\">\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><a class=\"chakra-link css-ug8vf0\" href=\"https:\/\/blog.ethereum.org\/2014\/03\/28\/schellingcoin-a-minimal-trust-universal-data-feed\">SchellingCoin<!-- --><\/a><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">A contract-driven implementation of <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"http:\/\/just-dice.com\/\">JustDice<!-- --><\/a>.<!-- --><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Some foundational code for a decentralized organization.<!-- --><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">A board game (e.g., chess, Go)<!-- --><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">A decentralized exchange, featuring a contract-based order book, between ether and the aforementioned sub-currency contract.<!-- --><\/p>\n<p><!-- --><\/li>\n<li class=\"css-cvpopp\">\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Any of the additional examples in our <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/wiki\/wiki\/%5BEnglish%5D-White-Paper\">whitepaper<!-- --><\/a><\/p>\n<p><!-- --><\/li>\n<\/ol>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Enjoy, and have a great time! Also, if you discover any bugs in pyethereum or Serpent, please make sure to report them.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">See also: <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/wiki\/wiki\/%5BEnglish%5D-Serpent-programming-language-operations\">list of Serpent language operations<!-- --><\/a><\/p>\n<\/div>\n<p><br \/>\n<br \/><a href=\"https:\/\/blog.ethereum.org\/en\/2014\/04\/10\/pyethereum-and-serpent-programming-guide\">Source link <\/a><br \/>\n&#8220;`<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`html The material presented in this guide is designed to pertain to PoC5. Most of the directives provided beneath will not function in the previous PoC4 versions of AlethZero (C++) and Ethereal (Go) In the preceding weeks, we have introduced a considerable amount of modifications to the Ethereum protocol. POC4, which brought a significant array<\/p>\n","protected":false},"author":3,"featured_media":8282,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[2031],"class_list":{"0":"post-10786","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ethereum","8":"tag-return-a-list-of-comma-separated-tags-from-this-title-pyethereum-and-serpent-programming-guide"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Mastering Pyethereum and Serpent: A Comprehensive Programming Guide - WSJ-Crypto<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mastering Pyethereum and Serpent: A Comprehensive Programming Guide - WSJ-Crypto\" \/>\n<meta property=\"og:description\" content=\"&#8220;`html The material presented in this guide is designed to pertain to PoC5. Most of the directives provided beneath will not function in the previous PoC4 versions of AlethZero (C++) and Ethereal (Go) In the preceding weeks, we have introduced a considerable amount of modifications to the Ethereum protocol. POC4, which brought a significant array\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"WSJ-Crypto\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-07T14:54:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"2100\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"wsjcrypto\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Scritto da\" \/>\n\t<meta name=\"twitter:data1\" content=\"wsjcrypto\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data2\" content=\"23 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/\",\"url\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/\",\"name\":\"Mastering Pyethereum and Serpent: A Comprehensive Programming Guide - WSJ-Crypto\",\"isPartOf\":{\"@id\":\"https:\/\/wsj-crypto.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg\",\"datePublished\":\"2025-04-07T14:54:29+00:00\",\"author\":{\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7\"},\"breadcrumb\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#primaryimage\",\"url\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg\",\"contentUrl\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg\",\"width\":2100,\"height\":900},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wsj-crypto.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mastering Pyethereum and Serpent: A Comprehensive Programming Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wsj-crypto.com\/#website\",\"url\":\"https:\/\/wsj-crypto.com\/\",\"name\":\"WSJ-Crypto\",\"description\":\"Just Another Crypto News Website\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wsj-crypto.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7\",\"name\":\"wsjcrypto\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g\",\"caption\":\"wsjcrypto\"},\"url\":\"https:\/\/wsj-crypto.com\/index.php\/author\/wsjcrypto\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mastering Pyethereum and Serpent: A Comprehensive Programming Guide - WSJ-Crypto","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/","og_locale":"it_IT","og_type":"article","og_title":"Mastering Pyethereum and Serpent: A Comprehensive Programming Guide - WSJ-Crypto","og_description":"&#8220;`html The material presented in this guide is designed to pertain to PoC5. Most of the directives provided beneath will not function in the previous PoC4 versions of AlethZero (C++) and Ethereal (Go) In the preceding weeks, we have introduced a considerable amount of modifications to the Ethereum protocol. POC4, which brought a significant array","og_url":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/","og_site_name":"WSJ-Crypto","article_published_time":"2025-04-07T14:54:29+00:00","og_image":[{"width":2100,"height":900,"url":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg","type":"image\/jpeg"}],"author":"wsjcrypto","twitter_card":"summary_large_image","twitter_misc":{"Scritto da":"wsjcrypto","Tempo di lettura stimato":"23 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/","url":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/","name":"Mastering Pyethereum and Serpent: A Comprehensive Programming Guide - WSJ-Crypto","isPartOf":{"@id":"https:\/\/wsj-crypto.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#primaryimage"},"image":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg","datePublished":"2025-04-07T14:54:29+00:00","author":{"@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7"},"breadcrumb":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/"]}]},{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#primaryimage","url":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg","contentUrl":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg","width":2100,"height":900},{"@type":"BreadcrumbList","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/07\/mastering-pyethereum-and-serpent-a-comprehensive-programming-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wsj-crypto.com\/"},{"@type":"ListItem","position":2,"name":"Mastering Pyethereum and Serpent: A Comprehensive Programming Guide"}]},{"@type":"WebSite","@id":"https:\/\/wsj-crypto.com\/#website","url":"https:\/\/wsj-crypto.com\/","name":"WSJ-Crypto","description":"Just Another Crypto News Website","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wsj-crypto.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7","name":"wsjcrypto","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g","caption":"wsjcrypto"},"url":"https:\/\/wsj-crypto.com\/index.php\/author\/wsjcrypto\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/10786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/comments?post=10786"}],"version-history":[{"count":2,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/10786\/revisions"}],"predecessor-version":[{"id":10792,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/10786\/revisions\/10792"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/media\/8282"}],"wp:attachment":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/media?parent=10786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/categories?post=10786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/tags?post=10786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}