<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Augusto Chirico</title>
        <link>https://paragraph.com/@augusto-chirico</link>
        <description>Software Engineer &amp; Cloud Architect, Blockchain Developer. Agile enthusiast. Nerd. Father, Husband, Friend. Sometimes, musician.</description>
        <lastBuildDate>Thu, 16 Jul 2026 23:53:47 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[How to create and call smart contracts with AngelLang, a DSL for building RSKj unit tests]]></title>
            <link>https://paragraph.com/@augusto-chirico/how-to-create-and-call-smart-contracts-with-angellang-a-dsl-for-building-rskj-unit-tests</link>
            <guid>Pq4t8PXbbYBt98s3H5IY</guid>
            <pubDate>Sat, 19 Feb 2022 10:38:03 GMT</pubDate>
            <description><![CDATA[Angel “Java” Lopez was one of the first core developers of the RSKj platform. Back in 2016, he created a DSL (domain specific language) to easily create RSK unit tests involving transactions, blocks and contracts. Sadly, Angel is no longer with us, but to honor him we will name this useful (but yet unnamed) language AngelLang. I‘ve recently had the chance to play with AngelLang for a bit. I wanted to create this tiny story to take advantage of my recent experience, in case this can help anyon...]]></description>
            <content:encoded><![CDATA[<figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/171dc115be99075079ae1f158712627d3491f1b8a5f1eb056bfdd0cc88385b9e.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>Angel “Java” Lopez was one of the first core developers of the RSKj platform. Back in 2016, he created a DSL (domain specific language) to <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://angeljavalopez.medium.com/using-a-dsl-domain-specific-language-for-rsk-java-implementation-tests-c57a36b8870f">easily create RSK unit tests</a> involving transactions, blocks and contracts. Sadly, Angel is no longer with us, but to honor him we will name this useful (but yet unnamed) language <em>AngelLang</em>.</p><p>I‘ve recently had the chance to play with AngelLang for a bit. I wanted to create this tiny story to take advantage of my recent experience, in case this can help anyone else who’s trying to use them and can’t find documented ways for using them successfully. I’m writing this article in a way either a senior or a junior developer can follow it. You can find the full example in this <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/aguschirico/rsk-dsl-example-smart-contract">repo</a>.</p><h2 id="h-creating-a-smart-contract-with-angellang" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Creating a Smart Contract with AngelLang</h2><p>As explained in “Mastering Ethereum”, contracts in both Ethereum and RSK are deployed using the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/ethereumbook/ethereumbook/blob/develop/06transactions.asciidoc#special-transaction-contract-creation">Zero Address</a>. The way to specify this in the AngelLang language is by setting the receiverAddress to 0, 00 or if you prefer not including the receiverAddress it will default to this same behavior.</p><p>Imagine we have a smart contract, and we want to create a test case that uses this contract. The first step we want to take is to create a transaction <em>tx01</em>, that we’ll include in the first block <em>b01</em>. Our contract will be called “Payable”, and we will add basic operations like deposit, transfer or withdrawal to it. Here’s the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/aguschirico/rsk-dsl-example-smart-contract/blob/bb00a4ccad43262b3865d38af32ae88457474ad5/Payable.sol">code</a> of the contract.</p><p>In RSK, as in Ethereum, a contract is created under a special transaction, where the calldata is the encoded ByteCode of the contract. In order to get this call data you can use any of the following approaches:</p><ul><li><p><strong>Remix</strong>: The compiler tab allows you to pick the ByteCode</p></li></ul><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3fae22db1481810e0938438399648ec1b6e67fff569db2d9c2607c1a41e9a604.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>After you paste this code into an editor, you’ll see that there is a json-like object that contains an “object” field. The content of that field is the contract that you’ll use as the calldata in your transaction.</p><ul><li><p><strong>Solc</strong>: Using Solidity compiler to compile the contract as described <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.soliditylang.org/en/v0.8.10/using-the-compiler.html">here</a>. The output file will contain the encoded ByteCode of your contract.</p></li><li><p><strong>Solcjs</strong>: As described in <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/ethereum/solc-js">here</a>. The output file will contain the encoded ByteCode of your contract.</p></li></ul><p>The resulting ByteCode has to be placed in the “data” parameter of the contract creation transaction, as displayed in the following image:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/8f504cf7e2b980915c93dc35a82edbba644e6835ebbcef3c587a2ceb829a8235.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>Notice that if your ByteCode contains a 0x prefix, you may need to remove it.</p><p>Once you’ve set this up, you have the contract deployment transaction properly configured.</p><p>Then we can create the first block and connect it to the blockchain.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e687aa5154a72cfede335f608d0b5da6ac177031741fe5c1f6a6b77d17ed0af7.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h2 id="h-using-a-smart-contract-with-angellang" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Using a Smart Contract with AngelLang</h2><p>Once we create the smart contract and deploy it in our first block, we may want to use it, so we need a second transaction that calls one of the functions of our contract.</p><p>In order to be able to call the contract, we need to understand how calling a contract works, taking into account that the transaction must contain the information about what function to call, and how to send parameters to that function. In Ethereum (and in RSK), there’s a specific format to send the data to the contract, so it understands what you are trying to do with it. To simplify the theory, we will say that we need to send the first 4 bytes of the hex-encoded signature of the function, and if the function receives arguments, we send those arguments encoded according to the ABI specification of this function. For a more detailed explanation, feel free to read <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/ethereumbook/ethereumbook/blob/develop/06transactions.asciidoc#transmitting-a-data-payload-to-an-eoa-or-contract">this section</a> of “Mastering Ethereum” or the Solidity <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.soliditylang.org/en/v0.8.10/abi-spec.html">specification</a>.</p><p>The easiest way to get all this information is by using Remix. If we’ve used remix in our previous step (deploying the contract), we will be able to interact with it easily through the Remix interface, under the deployment tab. We can make a call to the function we want to use from our test, with the parameters we want to give to it. Let’s imagine I want to call the “deposit()” function, which doesn’t receive any arguments, and I send 300 WEI to the contract.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/709b9c9a555293db79682eca2a5cf5e56b7de6ca55c849f415cb5cdc1d413272.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>In order to extract the input data from Remix so we can use it in our AngelLang example, we can check the debug console, expand the desired transaction and pick the content of the “input” field, which is exactly what we need (first 4 bytes of the encoded function signature + the encoded arguments as specified in the ABI specification). There’s also a way to achieve this by using <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://web3js.readthedocs.io/en/v1.5.2/web3-eth-abi.html#encodefunctionsignature">web3</a> or <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.ethers.io/v5/api/utils/abi/interface/#Interface--encoding">ethersjs</a>, but I found it a bit simpler to use a GUI like Remix.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/15e246245256f24f24cc91e4aecae677510ba4c0cbc66ec2a86cbb75d917e39c.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>Then we can simply go to our AngelLang definition and put that input data as the transaction’s call data.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7dc6326fae7fdea86c629249d2192bc0a9346a92f4b22a44b256a42881d9ef1b.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>With AngelLang in RSK, you can make assertions directly in the definition of the blockchain, as there are a few commands that you can use to validate the state of your blockchain and/or the transactions you performed. In this case I want to validate that my contract has effectively received the 300 wei I sent, and the block 2 (b02) has been successfully connected to the blockchain (it’s become the best block after all).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3842a186f577e42985b6e6276d976825558a23ecdc9309dcf24a251236d7b9a9.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>The way to use this AngelLang specification from the code, is to create a test case that uses that file, parses its content and builds the blockchain as in any of the examples that already exist in the RSKj <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/rsksmart/rskj/blob/master/rskj-core/src/test/java/co/rsk/test/DslFilesTest.java">DSL tests folder</a>.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cd86e23fcb79d5c1a117a275b88025ee6cb269d850b3a5c642f02eae17dd3a62.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h2 id="h-tdd-with-angellang" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">TDD with AngelLang</h2><p>As you might have noticed, the AngelLang is a quite powerful tool when you want to create controlled scenarios where you need to perform changes to the behavior of the blockchain, in a way you can assure nothing gets broken in the middle. It’s a perfect match if you want to use TDD for your development. However, it’s hardly documented so it can be fuzzy how to use it at the very beginning. I hope you guys found this helpful. See you in the next story!</p>]]></content:encoded>
            <author>augusto-chirico@newsletter.paragraph.com (Augusto Chirico)</author>
        </item>
    </channel>
</rss>