<?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 Leonardo Simone Digiorgio on Medium]]></title>
        <description><![CDATA[Stories by Leonardo Simone Digiorgio on Medium]]></description>
        <link>https://medium.com/@simon-digiorgio?source=rss-8bab071ce786------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Fs7PFlutNXIqeoqs26U6RQ.jpeg</url>
            <title>Stories by Leonardo Simone Digiorgio on Medium</title>
            <link>https://medium.com/@simon-digiorgio?source=rss-8bab071ce786------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 08:33:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@simon-digiorgio/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[Stack Exploder: Bridging Saga Chainlet NFTs Across EVM Networks using Hyperlane]]></title>
            <link>https://medium.com/sagaxyz/stack-exploder-bridging-saga-chainlet-nfts-across-evm-networks-using-hyperlane-911d6fbcc222?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/911d6fbcc222</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Sun, 12 May 2024 19:59:55 GMT</pubDate>
            <atom:updated>2024-05-12T19:59:55.151Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*mLxCqHhKwGIRx6ExfXLgWg.png" /></figure><p>In our previous Stack Exploder guide we explored how you can bridge assets like ERC20 tokens between your Saga Chainlet and any EVM network. <br>However, at the time of publishing both, the previous blog post and this one (<em>Hyperlane CLI version 3.10.0</em>), you couldn’t perform a warp for ERC721 tokens, which made it impossible to bridge NFTs between chains.</p><p>However, in this tutorial, we will use another solution (still using Hyperlane) for bridging NFTs between your Saga Chainlet and an EVM network, specifically Sepolia.</p><p><em>⚠️ </em><strong><em>Note: This is considered the follow-up to the </em></strong><a href="https://medium.com/sagaxyz/stack-explorer-bridging-your-saga-chainlet-assets-across-evm-networks-using-hyperlane-28b1cfe8f69e"><strong><em>Stack Exploder: Bridging Your Saga Chainlet Assets Across EVM Networks using Hyperlane</em></strong></a><strong><em> blog post. Before continuing, you should be prepared:</em></strong></p><ul><li>Your Saga Chainlet</li><li><a href="https://medium.com/sagaxyz/stack-explorer-bridging-your-saga-chainlet-assets-across-evm-networks-using-hyperlane-28b1cfe8f69e#113e">Deployed the Hyperlane Smart Contracts in both chain</a> and most importantly have the <a href="https://medium.com/sagaxyz/stack-explorer-bridging-your-saga-chainlet-assets-across-evm-networks-using-hyperlane-28b1cfe8f69e#c6fb">core-deployment-{timestamp}.json</a></li><li><a href="https://medium.com/sagaxyz/stack-explorer-bridging-your-saga-chainlet-assets-across-evm-networks-using-hyperlane-28b1cfe8f69e#2b2c">Validators and Relayer running</a></li></ul><h3>How to deploy Warp Route</h3><p>The current Hyperlane CLI version 3.11.1 does not support ERC721 tokens. So as a workaround, we will install a previous version of Hyperlane:</p><pre>npm install -g @hyperlane-xyz/cli@3.7.0</pre><p>As we did in the previous blog post (where we created a bridge for ERC20), we are now going to create a config for the deployment of the warp using the command:</p><pre>hyperlane config create warp</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*ckojhGyJAsw0cXIXkEVFAA.png" /></figure><p>You should notice that the output file will be named warp-tokens.yaml instead of warp-route-deployment.yaml, but the content structure is identical to that of the warp-route-deployment.yaml file.</p><pre>base:<br>  chainName: &lt;chainlet_name&gt;<br>  type: collateral<br>  address: &quot;&lt;contract_address_of_the_erc721&gt;&quot;<br>  isNft: true<br>synthetics:<br>  - chainName: sepolia</pre><p>In this tutorial:</p><pre>base:<br>  chainName: omegachain<br>  type: collateral<br>  address: &quot;0x01FDCCb5f12140f8Ea36272C772f5efBF48Ac731&quot;<br>  isNft: true<br>synthetics:<br>  - chainName: sepolia</pre><h4>Deployment</h4><p>Execute the following command to start the Warp Route deployment:</p><pre>hyperlane deploy warp </pre><p>If the deployment went well, you should see an output similar to this in your terminal:</p><pre>Hyperlane CLI<br>Reading file configs in ./configs/chains.yaml<br>All chain configs in ./configs/chains.yaml are valid<br>? Do you want to use some core deployment address artifacts? This is required for PI chains (non-core chains). yes<br>? Select contract deployment artifacts file core-deployment-2024-04-19-10-48-17.json<br>Using warp config at ./configs/warp-tokens.yaml<br>Assembling token configs<br>Fetching token metadata for 0x01FDCCb5f12140f8Ea36272C772f5efBF48Ac731 on omegachain}<br>Using base token metadata: Name: Saga Cats Dogs Food, Symbol: SCDF, Decimals: 0<br>Token configs ready<br>WARP Deployment plan<br><br>Deployment plan<br>===============<br>Transaction signer and owner of new contracts will be 0x4cDF9dd5d678E4274e5DBB902E91b80373899513<br>Deploying a warp route with a base of Saga Cats Dogs Food token on omegachain<br>Connecting it to new synthetic tokens on sepolia<br>Using token standard ERC721<br>? Is this deployment plan correct? yes<br>Running pre-flight checks...<br>Running pre-flight checks...<br>Chains are valid ✅<br>Signer is valid ✅<br>Balances are sufficient ✅<br>All systems ready, captain! Beginning deployment...<br>Contract addresses will be written to artifacts/warp-deployment-2024-05-06-19-11-27.json<br>Warp UI token config will be written to artifacts/warp-ui-token-config-2024-05-06-19-11-27.json<br>Start deploy to omegachain,sepolia<br><br>===============<br>Various smart contracts deployed on both chains<br>===============<br><br>Mailbox client on sepolia initialized...<br>Transferring ownership of ownables...<br>Finished deploying router contracts for all chains.<br>Hyp token deployments complete<br>Writing deployment artifacts<br>Deployment is complete!<br>Contract address artifacts are in artifacts/warp-deployment-2024-05-06-19-11-27.json<br>Warp UI token config is in artifacts/warp-ui-token-config-2024-05-06-19-11-27.json</pre><p>When completed, the CLI (<strong>of this version</strong>) will generate two new JSON artifact files: warp-deployment-{timestamp} and warp-ui-token-config-{timestamp}.</p><p>The first contains just addresses for the newly deployed Warp router contracts.<br>The second is a config file for the Warp UI, which you can use for the <strong>next step.</strong></p><p>In my case warp-ui-token-config files are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mqKlgiTf7OSQ5HLZ0Ibz2Q.png" /></figure><h3>Interact with the Warp Routes</h3><p>Now that you have deployed a Warp Route, you can interact with your routes:</p><ul><li>Using a different version of the <strong>Hyperlane Warp UI Template</strong> (any commit version before “Migration to warp core (#134)”, you can use this <a href="https://github.com/hyperlane-xyz/hyperlane-warp-ui-template/tree/d01d616e7791bd8d467101f01b41c6519172777b">commit branch and download ZIP</a>)</li><li>You can fork this <a href="https://github.com/chefleo/hyperlane-saga-ui-warp">repo</a> (which is still using that version of Hyperlane Warp UI)</li></ul><p>Before continuing, there are a few changes to do with this repo:</p><ol><li><a href="https://github.com/chefleo/hyperlane-saga-ui-warp/commit/ca1b459d117552a438a78dc9e54cd2459644e4b2#diff-76a86babff22ab91c287fb3203d3efcb7093a870ad73767cf9591da960cecdc1R45">Set the state variable “isNft” to true</a> (but ONLY if you’re using a single NFT warp route). <br>This is because of a UI bug where the form on the initial page defaults to ‘select the amount’ instead of ‘select the token ID,’ which is what we want.</li><li>Do some check changes on validateForm.ts file (<a href="https://github.com/chefleo/hyperlane-saga-ui-warp/commit/3a7a8f198b1c84ff3aedd676794d2daeb087674d#diff-441481e0847d68162e0f130b05edc15099326940775c19d33a6125d522ad1badR54">1</a>, <a href="https://github.com/chefleo/hyperlane-saga-ui-warp/commit/3a7a8f198b1c84ff3aedd676794d2daeb087674d#diff-441481e0847d68162e0f130b05edc15099326940775c19d33a6125d522ad1badR54">2</a>).<br>This is because the repo considers 0 to be an incorrect value, so if you choose “<strong>token ID:</strong> <strong>0”</strong> to bridge, it will result in an error, which is something we want to avoid.</li></ol><p>Using this repo now you can easily “connect” your warp routes:</p><ol><li>Install dependencies with yarn</li><li>Copy warp-ui-token-config-{timestamp} and paste into .src/consts/tokens.json</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-lx1xCqWtlmcTsUD0-cnCQ.png" /></figure><p>3. Add your chainlet config by copying the <em>chains.yaml</em> file from the hyperlane config create chain section. Additionally, include nativeToken information such as name, symbol, and decimals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zcXO9A9uXdNguZNMDEO2qQ.png" /></figure><p>4. Lastly build the project using yarn build and then yarn dev</p><p>Now let’s the magic happen 🪄 ✨</p><p>For this tutorial we are going to use the NFT Collection “<strong>Saga Cats Dogs Food</strong>”.</p><p>You can see that this wallet has 4 Nfts (on the <a href="https://omegachain-1712771388991266-1.testnet.sagaexplorer.io/token/0x01FDCCb5f12140f8Ea36272C772f5efBF48Ac731">chainlet explorer</a> and Metamask)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jDxJrCJuF2TAjf9ZmIJYag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*hKludGaQ4aH5PG5Xqjv4nA.png" /></figure><p>And doesn’t have any in <strong>Sepolia</strong> Etherscan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*_8J6Sml35WdJWI8LW7HADA.png" /></figure><p>In the Hyperlane Warp UI, we bridge the <strong>token id 0</strong> from <strong>Omegachain</strong> to <strong>Sepolia.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jR4yffvLggxhw2xMgoN_jw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jppfIP8F_m5Ptr31L6Qg0w.png" /></figure><p>You can observe that the process requires two transactions:</p><ul><li>The <strong>approve</strong> transaction, where you allow the <strong>HypERC721Collateral</strong> smart contract to utilize your tokens.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*CkQyrQfqJzIj9zKR1z-f5g.png" /></figure><ul><li>The <strong>transfer</strong> transaction, where you transfer the NFT to the <strong>HypERC721Collateral </strong>(you can check the flow in <a href="https://medium.com/sagaxyz/stack-explorer-bridging-your-saga-chainlet-assets-across-evm-networks-using-hyperlane-28b1cfe8f69e#c649">this chapter</a> in the previous blog post).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*uo2tIuWHwJbnOpw-DcJfzQ.png" /></figure><p>After a few minutes, you’ll notice that your NFT (token ID 0) is now on the Sepolia network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*re75HizAKIR_bOJEC0B5Ig.png" /></figure><p>The entire code for this guide is available in these github repos:</p><ul><li>Hyperlane-saga: <a href="https://github.com/chefleo/hyperlane-saga/tree/warps/omegachain">https://github.com/chefleo/hyperlane-saga/tree/warps/omegachain</a></li><li>Hyperlane Warp UI (different version): <a href="https://github.com/chefleo/hyperlane-saga-ui-warp">https://github.com/chefleo/hyperlane-saga_ui_warp</a></li></ul><h3>Conclusion</h3><p>Congratulations! You have bridged your ERC721 tokens between your Saga chainlet and the Ethereum chain. <br>This tutorial is a preview into how you can evolve your chainlet to incorporate a “<strong>portal</strong>” that establishes connections with other chains. You have now <strong>unblocked</strong> a realm of boundless possibilities.</p><p>For more details around how you can <strong>Unblock your application</strong>, follow us on <a href="https://twitter.com/Sagaxyz__">X</a>, join our <a href="https://discord.gg/UCRsTy82Ub">Discord</a> and <a href="https://xyz.us10.list-manage.com/track/click?u=ca44fab3b7b6185f64afb274a&amp;id=f450024c8d&amp;e=4c17c9cc64">Telegram</a> and subscribe to our <a href="https://xyz.us10.list-manage.com/track/click?u=ca44fab3b7b6185f64afb274a&amp;id=853c5406bb&amp;e=4c17c9cc64">Medium</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=911d6fbcc222" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sagaxyz/stack-exploder-bridging-saga-chainlet-nfts-across-evm-networks-using-hyperlane-911d6fbcc222">Stack Exploder: Bridging Saga Chainlet NFTs Across EVM Networks using Hyperlane</a> was originally published in <a href="https://medium.com/sagaxyz">Saga AI Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stack Exploder: Account Abstraction + No-fee transactions — Protocol Native Account Abstraction]]></title>
            <link>https://medium.com/sagaxyz/stack-exploder-account-abstraction-no-fee-transactions-protocol-native-account-abstraction-f66d0368fca3?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/f66d0368fca3</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[account-abstraction]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 14:29:11 GMT</pubDate>
            <atom:updated>2024-04-30T14:29:11.699Z</atom:updated>
            <content:encoded><![CDATA[<h3>Stack Exploder: Account Abstraction + No-fee transactions — Protocol Native Account Abstraction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*4k5vASq3vAEhvSUKlwONOA.png" /></figure><p>In the blog posts<a href="https://medium.com/sagaxyz/stack-exploder-unblocking-web3-products-with-costless-transactions-387b9f03b7c5"> <strong>Stack Exploder: Unblocking Web3 Products With Costless Transactions</strong></a>, we saw how Saga’s revolutionary token flows enable Chainlet developers to achieve costless transactions.</p><p>We also showcased how to easily implement this flow into your dApp in<a href="https://medium.com/sagaxyz/stack-exploder-implementing-costless-transactions-using-recycled-gas-tokens-ee51548b390e"> <strong>Stack Exploder: Implementing Costless Transactions Using Recycled Gas Tokens</strong></a></p><p>However, it’s important to note that while Saga provides <strong>protocol-native costless transactions</strong>, there might be scenarios where users require additional functionalities, such as account abstraction.</p><p>In this blog post, we deep-dive into how <strong>Account Abstraction</strong> can be implemented and utilized on your chainlet.</p><h3><strong>Introduction Account Abstraction (ERC-4337)</strong></h3><p>The Ethereum ERC-4337, which is an EIP related to Account Abstraction,enhances the user interaction with decentralized applications (DApps), thereby making the key to unlock mass adoption of web3 technologies.</p><p>Account Abstraction enables assets to be exclusively managed by smart contracts instead of externally-owned accounts (EOAs). At the forefront of this evolution is the ERC-4337 standard, a token standard empowering the capabilities of smart contract crypto wallets on the Ethereum blockchain.</p><p>From the perspective of an Ethereum user, the integration of account abstraction represents a significant advancement, as it conceals the intricate technical details involved in Web3 interactions. This not only streamlines wallet design but also significantly elevates the overall user experience.</p><p>Note: This tutorial is focused on the implementation of Account Abstraction in the Chainlet. If you want to read more about Account Abstraction head over to: <a href="https://www.erc4337.io/docs">https://www.erc4337.io/docs</a></p><h4>Understanding the Mechanics of ERC-4337</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ObQ42RR54IPTmuc5qmA2hg.png" /></figure><p>ERC-4337 introduces a novel concept called a “<strong>UserOperation</strong>” which serves as a pseudo-transaction object facilitating the execution of transactions on behalf of users. Unconfirmed UserOperation transactions are temporarily stored in an “<strong>alt mempool</strong>”, which is special mempool different from the main Ethereum mempool.</p><p>Within the Ethereum network, certain nodes can assume the role of a “<strong>Bundler</strong>,” responsible for aggregating multiple UserOperations from the alt mempool into a single transaction referred to as a bundle transaction. This makes the transaction more efficieint, thereby reducing gas fees.</p><p>These bundle transactions are then transmitted to a singular global smart contract known as the “<strong>EntryPoint</strong>” on the Ethereum blockchain, emphasizing that there is only one entry point in the Ethereum network.</p><p>The Bundler triggers a function call on the EntryPoint smart contract called “<strong>handleOps</strong>.” In this function, the bundle transaction is received, and subsequently, a distinctive function, “validateUserOp,” is invoked for each account.</p><p>The primary objective of “<strong>validateUserOp</strong>” is to authenticate the signature of the operation and, upon confirmation that the operation aligns with the account’s criteria, process the associated gas fee payment. Subsequently, each smart contract wallet is required to implement an additional function to execute the operation sent in by the EntryPoint contract. This transformation renders the entire process programmatic, eliminating the need for private key dependencies and simplifying the user experience.</p><h3>Implementing Account Abstraction on your chainlet</h3><p>In this tutorial, we give you an easy approach on how to implement Account Abstraction for your Saga chainlet.</p><p>Because of the complexity of implementing Account Abstraction, we recommend taking small steps. Hence this tutorial is broken down into three parts:</p><ol><li><strong>Implement Simple Account Abstraction.</strong></li><li><strong>Implement Paymaster.</strong></li><li><strong>Implement Account Validation.</strong></li></ol><h3>Implementing a Simple Account Abstraction</h3><p>To start off, we are going to build a Hardhat project to test if everything is working as expected (using a Hardhat node first), and only then deploy it to the chainlet. If everything is working fine in the Hardhat project, we will then implement it on the frontend of the dApp.</p><p>We have created a <a href="https://github.com/chefleo/saga_aa/tree/simple_aa">github repo</a> with the project used for this tutorial. We recommend to use it along with this tutorial.</p><p>Let’s kickstart by installing these contracts in hardhat:<a href="https://github.com/eth-infinitism/account-abstraction"> https://github.com/eth-infinitism/account-abstraction</a> (if you’re using npm you can do npm i @account-abstraction/contracts@0.6.0).</p><pre>npm i @account-abstraction/contracts@0.6.0</pre><p>Also you’ll need to install openZeppelin</p><pre>npm i @openzeppelin/contracts@4.2.0</pre><p>Deploying the <strong>EntryPoint</strong> is your first step. This is the <strong>heart</strong> of the Account Abstraction as it manages the execution logic for transactions, ensuring they’re processed correctly.</p><p>You’ll find that in the repository under node_modules/@account-abstraction/contracts/core/EntryPoint.sol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*9YIPnx6uUmumpncT4C7XnA.png" /><figcaption>deployEP.js</figcaption></figure><blockquote>Sometimes, when deploying this contract, you might encounter an error indicating that the contract code size exceeds the limit. To resolve this, ensure that the compiler settings are configured to utilize the optimizer with 1000 runs.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*-0pDWCMX6OXXoA8lnR3ytA.png" /><figcaption>hardhat.config.js</figcaption></figure><h4>Build the Account and AccountFactory Contract</h4><p>We’re going to create two smart contracts: the <strong>Account</strong> and the <strong>AccountFactory</strong>.</p><p>The <strong>Account </strong>contract is the smart account (or smart wallet) and <strong>AccountFactory </strong>is the smart contract that creates the smart account. Another way to look at Account Factory is as the smart contract that generates the smart contracts.</p><p>Let us start with the Account Factory! You’ll be working closely with the EntryPoint. Here’s our first look! We need to find the code where the EntryPoint is creating the smart account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AN-ms6WONylEasv8iF3m5g.png" /><figcaption>node_modules/@account-abstraction/contracts/EntryPoint.sol</figcaption></figure><p>Specifically, in the line 6:</p><pre>address sender1 = senderCreator.createSender{gas : opInfo.mUserOp.verificationGasLimit}(initCode);</pre><p>It calls out to senderCreator to create the smart contract. Let’s dive into senderCreator and explore its functionality!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mQuvrRQ1mvtA9qKlTckPbA.png" /><figcaption>node_modules/@account-abstraction/contracts/SenderCreator.sol</figcaption></figure><p>Notice that the factory address is the beginning part of the initCode, specifically the first 20 bytes. Later on in this tutorial, we’ll be creating this initCode ourselves, so remember this detail.</p><p>The remaining part of the initCode is called initCallData, and it’s sent to the factory within the assembly block. It is important to note that there is no fixed method to call on the factory. Instead, the contract sends all the calldata directly to the factory, which means we’ll have to decide which method to call ourselves.</p><p>Another thing to note is that the outcome of the call should be the address of the newly created smart account. The EntryPoint anticipates this, so it’s crucial to ensure that we return it. So, our factory should look something like this:</p><pre>contract AccountFactory {<br>    function createAccount(address _owner) public returns (address) {<br>        Account newAccount = new Account(_owner);<br>        return address(newAccount);<br>    }<br>}</pre><blockquote><strong>How would you like your account to work?</strong></blockquote><blockquote>You have a lot of freedom here! Are there any other constructor arguments you want to pass to your account? Using _owner seems like a good idea, but it’s entirely up to you how you want to design your account. You can name the function createAccount as we did, but that’s entirely your choice. Additionally, we’ve opted for the CREATE opcode here, which deploys the address using the hash(factory, nonce). However, if you prefer to use CREATE2, feel free to do so.</blockquote><p>Once you’ve created the structure of your factory, it’s time to create your Account. The Account smart contract will need to accept the constructor arguments that you defined in your factory.</p><p>Additionally, it will need to implement the account interface here:<a href="https://github.com/eth-infinitism/account-abstraction/blob/ver0.6.0/contracts/interfaces/IAccount.sol"> https://github.com/eth-infinitism/account-abstraction/blob/ver0.6.0/contracts/interfaces/IAccount.sol</a> — specifically the validateUserOp method. For now, let’s keep it simple and Return 0 so that the EntryPoint knows the user op it sent is valid, and can be executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0gtkULvh9JMP32OXHgemnw.png" /><figcaption><a href="https://github.com/chefleo/saga_aa/blob/simple_aa/contracts/Account.sol">contracts/Account.sol</a></figcaption></figure><h4>Deploy Account Factory and EntryPoint</h4><p>To deploy the smart contract, simply create a scripts inside the ‘scripts’ folder. In our project, we created a script called <strong>deployAF.js</strong> and <strong>deployEP.js</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1eCBNCVlnpGRWsLPbYwnw.png" /><figcaption>deployAF.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*9YIPnx6uUmumpncT4C7XnA.png" /><figcaption>deployEP.js</figcaption></figure><p>Run npx hardhat node to create an hardhat node (As mentioned earlier, we test first on the local node before using our chainlet)</p><p>Then run this command to deploy the two smart contracts</p><pre>npx hardhat run scripts/deployAF.js<br>npx hardhat run scripts/deployEP.js</pre><p>Before moving on to the next section, we will also deploy this simple smart contract to test if our Account Abstraction worked and to execute the desired smart contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*fSupEYIs2IwCweiErzto2A.png" /><figcaption>SimpleStorage.sol</figcaption></figure><h4>Build &amp; Send the UserOp</h4><p><strong>UserOp</strong> represents transaction details to be executed on behalf of a user, encapsulating all necessary information for execution.</p><p>Before diving into the structure of the UserOp, let’s start by creating the script. Create a file named ‘execute.js’ and begin by adding the contract address variable at the beginning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uhxYQcMm554Kpxd358Vwng.png" /></figure><p>Let’s just take a look at all the fields of a user operation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*Lug4s_FqCBw4ur08ZcQTLw.png" /><figcaption>scripts/execute.js</figcaption></figure><p>It does appear to be quite a few fields. However, we’ll focus solely on the initial four fields. <br>For the rest, we’ll estimate gas values and mark ‘0x’ for ‘paymasterAndData’ and signature. As mentioned earlier, we are taking small steps at a time, and ‘paymasterAndData’ and signature will be covered in the Paymaster and Account Validation chapters.</p><p>So for now the user operation will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsGT_Xj4jAS5KNEfljhioA.png" /><figcaption>scripts/execute.js</figcaption></figure><h4>Sender (Smart Wallet/Smart Account)</h4><p>One aspect of the EntryPoint’s structure is the sender’s address that we’ll have to pre-calculate to include it in the user operation.</p><p>We can compute it locally, preferably leveraging a library (such as ethers or web3) with methods for obtaining a contract address using both <strong>CREATE</strong> and <strong>CREATE2</strong>.</p><p>If CREATE was utilized, as we did, then factoring in the factory’s nonce will be necessary in the calculation to acquire the sender’s address (which is hash(deployer + nonce)). Initially, when deploying a smart account, the nonce for address calculation will be 1, incrementing by 1 with each subsequent contract deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*Pa-UDZ22nv7Ef4nd-iEPfg.png" /><figcaption>scripts/execute.js</figcaption></figure><h4>Nonce</h4><p>Another interesting aspect of the EntryPoint is its internal handling of nonces (<a href="https://github.com/eth-infinitism/account-abstraction/blob/ver0.6.0/contracts/core/NonceManager.sol">NonceManager</a>).</p><p>Each sender can possess multiple nonces, facilitating transactions with various keys without necessitating sequential ordering, yet still ensuring replay protection. Let’s designate our nonce key as 0. Consequently, to fetch the nonce for our sender, we can simply invoke the entryPoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*T7Qu_ux_9Mil6u6uDZuuGw.png" /><figcaption>scripts/execute.js</figcaption></figure><h4>InitCode</h4><p>We’ve already examined this field in the <strong>SenderCreator</strong> contract, observing that the initial 20 bytes represent the factory address, followed by the calldata to be sent to the factory. Now, let’s proceed to write the code to determine what our initCode will be!</p><p>You’ll need to encode the calldata for the factory’s method for creating the account. In the example provided earlier, we used createAccount. Therefore, for this example, the calldata will be the <strong>keccak hash of createAccount(address)</strong>, concatenated with the address we intend to use for the owner, padded to 32 bytes. Most libraries like viem, ethers have methods to assist you in encoding function data, so manual encoding isn’t necessary.</p><p>Once you have these two components, you have to merge them. The calldata should be <strong>the factory address + the encoded calldata</strong> to send along to the factory. Take caution when manipulating strings to avoid appending “0x” from the encoded calldata, ensuring you achieve “0x{factory}{calldata}” rather than “0x{factory}0x{calldata}”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mlwz2QCc6yb6IJ_mG0Jfnw.png" /><figcaption>scripts/execute.js</figcaption></figure><p>However we only need the initCode once. That is, when <strong>we create the sender (smart wallet/smart account) for the first time </strong>(so when nonce is ≥ 1). After that, the initCode will be ‘0x’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*qAJ9IFrcZZ9sUwSAvL_nDA.png" /><figcaption>scripts/execute.js</figcaption></figure><h4>Calldata</h4><p>Finally, it’s time to encode what we actually want to do with the smart wallet! <br>Similar to encoding the calldata for the factory’s method, you’ll likely want to use a library to handle this encoding for you.</p><p>In the Account example provided earlier, this would involve encoding the calldata to call the state-changing function execute().</p><p>The function <strong>execute</strong> essentially invokes the smart contract that we are going to pass (in our case, the SimpleStorage contract). It requires the smart contract address, value, and the encoded ABI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sQYAandEXnW7ARcyt8dleg.png" /><figcaption>Account.sol</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1kXGkxXhH4sLkZt1K7TWQ.png" /><figcaption>scripts/execute.js</figcaption></figure><h4>Pre-Fund the Account</h4><p>After calculating the sender address, you’ll need to pre-fund this address with some ether on the EntryPoint. The EntryPoint utilizes this deposited ether for gas fees, so ensuring there is ether available is crucial before attempting to execute a user operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQrd0cu8SV7psebMb90mBQ.png" /><figcaption>scripts/execute.js</figcaption></figure><p>Finally, after we have all the necessary “variables” for the userOps, we are going to fill the userOp and use it as an argument for the ‘entryPoint.handleOps’ method. Then, we will put the address as the second argument (which will be the beneficiary to receive fees).</p><p>In the end, your <strong>execute.js</strong> file should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4c0a86913793efb5f3ece087d2ed530/href">https://medium.com/media/f4c0a86913793efb5f3ece087d2ed530/href</a></iframe><p>Now the moment of the truth — it is time to execute the scripts using</p><pre>npx hardhat run scripts/execute.js</pre><p>If everything is okay in the hardhat node you will have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1X1k9jLCIM-qbmpL8tb0gg.png" /></figure><p>Also, create a test to check if the smart contract that we put in the callData worked (the set function, line 38–41 of the gist above).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y7YAAGXo7ih8emCGW68P5g.png" /><figcaption>testSimpleStorage.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RVTTVKIrE7HgDUUIuNfGvw.png" /></figure><h4>Implementing a Simple Account Abstraction on your chainlet</h4><p>To get the account abstraction on your chainlet, you need to launch a chainlet.<br>If you need help to launch your chainlet, you can visit the Saga<a href="https://docs.saga.xyz/working-with-chainlets/launch-your-chainlet#launching-a-chainlet-using-saga-web-app"> <strong>documentation</strong></a><strong> </strong>and this<a href="https://medium.com/sagaxyz/stack-explorer-democratizing-blockchain-development-sagas-no-code-solutions-saga-under-the-0203b2856346"> <strong>blog post</strong></a> for step-by-step guidance.</p><h4>Config your hardhat with your chainlet info</h4><p>Before deploy the necessary smart contract, you need to config your hardhat, add a network entry to your hardhat.config.js file and add your own chain like this:</p><pre>require(&quot;@nomicfoundation/hardhat-toolbox&quot;);<br>require(&quot;dotenv&quot;).config();<br><br>const PRIVATE_KEY = process.env.PRIVATE_KEY;<br><br>/** @type import(&#39;hardhat/config&#39;).HardhatUserConfig */<br>module.exports = {<br>  defaultNetwork: &quot;localhost&quot;,<br>  networks: {<br>    tutorialworldV2: {<br>      chainId: 2705143118829000,<br>      // If you use Chainlet Testnet it will be with --&gt; .jsonrpc.testnet.sagarpc.io<br>      // If you use Mainnet it will be with --&gt; .jsonrpc.sagarpc.io<br>      url: &quot;https://tutorialworldtwo-2705143118829000-1.jsonrpc.testnet.sagarpc.io&quot;,<br>      accounts: [PRIVATE_KEY], // Private Key of your metamask wallet<br>    },<br>  },<br>  solidity: {<br>    version: &quot;0.8.23&quot;,<br>    settings: {<br>      optimizer: {<br>        enabled: true,<br>        runs: 1000,<br>      },<br>    },<br>  },<br>};</pre><p>In your case will be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48d0ac589d6b60cf5e0748dcc8238d23/href">https://medium.com/media/48d0ac589d6b60cf5e0748dcc8238d23/href</a></iframe><p>Where PRIVATE_KEY is the private key of the your Metamask wallet.<br>To get your private key follow this <a href="https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key#:~:text=On%20the%20&#39;Account%20details&#39;%20page,private%20key%20to%20your%20clipboard.">guide</a> from Metamask.</p><blockquote><em>⚠️ Note: Please ensure that you keep your private key hidden from anyone by adding it to the .env file and including the .env file in your .gitignore.</em></blockquote><p>If you are a beginner check this guide: <a href="https://consensys.io/blog/how-to-avoid-uploading-your-private-key-to-github-approaches-to-prevent-making-your-secrets-public">How to Avoid Uploading Your Private Key to GitHub</a> and <strong>use your dev/test wallet</strong> for your projects NOT your main one.</p><h4>Deploy EntryPoint and AccountFactory</h4><p>To deploy the smart contract, simply you are going to use the scripts <strong>deployAF.js</strong> and <strong>deployEP.js</strong>. The only difference is adding the <strong>network</strong> flag followed by your chainlet network.</p><pre>npx hardhat run scripts/deployAF.js --network &lt;chainlet&gt;<br>npx hardhat run scripts/deployEP.js --network &lt;chainlet&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZN94DThYw7aLpbnFWmyFEQ.png" /></figure><p>Also you can see the contracts deployed on your chainlet explorer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5oyKyxbuoyqdoVy5HU1l6Q.png" /></figure><h4>Testing Account Abstraction in your chainlet</h4><p>To test the account abstraction we are going to deploy SimpleStorage.sol using the command</p><pre>npx hardhat run scripts/deploySimpleStorage.js --network &lt;chainlet&gt;</pre><p>Then change all the contract addresses of AccountFactory, EntryPoint and SimpleStorage in the <strong>execute.js.</strong></p><p>And finally run</p><pre>npx hardhat run scripts/execute.js --network &lt;chainlet&gt;</pre><p>If everything is okay you have in your chainlet explorer the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PdJ_UldI3-FwGBp46JGsnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cqeq80JTMvQuz1BpNh7c7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qB45VBqsC_LFELWbk_1CgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMfXRh6YXsXwlzi4DPvwRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eHsTz1d2pVug-nmX1pp3og.png" /></figure><p>And if you test the SimpleStorage contract (or any other contract that you deploy), you should notice a change in its state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFVeCeDURxSzXTqy6LB57g.png" /></figure><h3>Prepare your dApp for Account Abstraction</h3><p>To implement Account Abstraction, we are going to use as an example an <strong>Erc1155 nft claim (</strong><a href="https://github.com/chefleo/saga_nft_drop/tree/simple_aa"><strong>Github</strong></a><strong>).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KrpKmxVzQdeYcvmEDfsQ0g.png" /></figure><p>To do this first of all we are going to use thirdweb to <a href="https://thirdweb.com/thirdweb.eth/DropERC1155"><strong>deploy our erc1155</strong></a><strong>.</strong></p><p>Create your repo using the command:</p><pre>npx thirdweb create</pre><p>Wrap your app in the ThirdwebProvider to access the SDK’s functionality from anywhere in your app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c69f64840e44b52f4575605134819238/href">https://medium.com/media/c69f64840e44b52f4575605134819238/href</a></iframe><p>To use the ThirdwebProvider, you need a client ID. You can obtain one by going to <a href="https://thirdweb.com/dashboard/settings">https://thirdweb.com/dashboard/settings</a> → CREATE API KEY and then copying the client ID and storing it in the .env file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pgvRygmd49mzvb6lZKRU2w.png" /></figure><p>For read/write contracts, we are going to use Viem. To install it, use the following command:</p><pre>yarn add Viem</pre><p>In your dApp, create a folder to store all the necessary files for your Account Abstraction. These include the <strong>address contracts</strong> and <strong>ABIs</strong> of <strong>EntryPoint</strong>, <strong>AccountFactory</strong>, <strong>Account</strong> (only the ABI for this one) and <strong>your deployed contract</strong> (in our case, the ERC1155).</p><p>To obtain the ABIs, navigate to the hardhat project and access the artifacts folder. You can find the ABIs in the &lt;contract&gt;.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VV84Vxm6BILAFTUGcXivWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XggvW9pW-I2gG64UUM7ufQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*ZiKe70KDBXvVwbTrP-56YA.png" /></figure><p>To get the ABI on your contract deployed on thirdweb, you need to go on your <a href="https://thirdweb.com/dashboard/contracts/deploy">thirdweb contracts deploy dashboard</a> → click to your contract deployed → Sources -&gt; ABI (should be the last one)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1vT8KJr8T7Y-cf1bVeB-KQ.png" /></figure><p>In the end, your folder (which I called constant) should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWOfSj8JvLP7sgbOfqGzzg.png" /></figure><p>Next, create a ‘lib’ folder and within it, create a ‘chainlet.ts’ file. Add your chainlet information to this file like this (we need this for Viem later).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a75f97059c5308ae32e01f135a028125/href">https://medium.com/media/a75f97059c5308ae32e01f135a028125/href</a></iframe><p>Lastly as in the hardhat project we need the <strong>dev private key</strong> and store .env (we need this for Viem later).</p><p>Now it is time to prepare App.tsx for Account Abstraction</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53c18ada5e5efab4e6ffa80fa87e76df/href">https://medium.com/media/53c18ada5e5efab4e6ffa80fa87e76df/href</a></iframe><h4>Implement Account Abstraction in your dApp</h4><p>Now that we have everything we need, let’s start by creating createPublicClient (for reading from smart contracts in your chainlet) and createWalletClient, which will execute the <strong>handleOps</strong> of the entryPoint. Here, we are going to use the <strong>dev wallet</strong> using its private key (stored in the .env file to avoid theft).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1O8K0i5ca3CQ2woqjQNEZA.png" /></figure><h4>Prepare the UserOps</h4><p><strong>Sender<br></strong>Let’s start with the sender as in the hardhat project, we are going to use CREATE op to create the sender.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SbAjY9xHzYSAdySDUhLBjQ.png" /></figure><blockquote>NOTE: <em>in this project we are going to create and use only one Smart Account, with the owner being the dev account. However, in the future, you may want to use a smart account associated with each user. For that, you can follow the</em><a href="https://github.com/eth-infinitism/account-abstraction/blob/releases/v0.6/contracts/samples/SimpleAccount.sol"><em> Account</em></a><em> and</em><a href="https://github.com/eth-infinitism/account-abstraction/blob/releases/v0.6/contracts/samples/SimpleAccountFactory.sol"><em> AccountFactory</em></a><em> samples in this repo.</em></blockquote><h4>Nonce</h4><p>To get the nonce simply read from the entryPoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CL0taamcnFfjhK6XxB4R8Q.png" /></figure><h4><strong>InitCode</strong></h4><p>Here we are going to use the <strong>encodeFunctionData</strong> from Viem to get <strong>the encoded calldata of createAddress </strong>to send along to the factory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ClNXnNn2iVmK5J-mebUEHA.png" /></figure><h4>CallData</h4><p>Here we are going to <strong>encodeFunctionData </strong>the write function “claim” of the Erc1155 contract and “execute” of the Account contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GDDRJge_x4rZGxl_bxns5g.png" /></figure><h4>Pre-Fund the Account</h4><p>Before fulfilling the userOps, we need to fund the Smart Account, like we did in the Hardhat project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oCV5w5cWWiPREuUM7JwSog.png" /></figure><h4>UserOps and handleOps</h4><p>Finally, after assembling all the necessary components, we’ll populate the <strong>userOp</strong> (with a TUPLE, not an Object) and use it as an argument for the <strong>handleOps</strong> method. Subsequently, we’ll specify the dev address as the second argument and execute the transaction using the dev account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*55JdT65-UgpVqUJxJExlOA.png" /></figure><p>If everything is okay, your chainlet explorer will show all the same events that occurred in the section: <a href="#8187"><strong>Testing Account Abstraction in your chainlet</strong></a>.</p><h3>Implement Paymaster</h3><p>The Paymaster contract in ERC 4337 Account Abstraction enables someone else to cover the gas costs on behalf of the smart account. This feature grants flexibility in managing gas payments, allowing for sponsorship or alternative payment methods. Let’s proceed by deploying our own Paymaster contract to delve deeper into its functionality.</p><h4>Create and Deploy Paymaster Contract</h4><p>In this step, we’ll need to implement the Paymaster interface found here: <a href="https://github.com/eth-infinitism/account-abstraction/blob/releases/v0.6/contracts/interfaces/IPaymaster.sol">https://github.com/eth-infinitism/account-abstraction/blob/releases/v0.6/contracts/interfaces/IPaymaster.sol</a></p><p>Let’s proceed with creating an generous paymaster:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jW_bqnOhuTRk3vE35UYG1A.png" /></figure><p>This paymaster considers every user op valid, hence it will cover the expenses for any operation! <br>This behavior is evident in the validatePaymasterUserOp function, which the EntryPoint invokes for each user op it receives. Additionally, we’ve implemented a postOp function, although we’ve kept its body blank for now.</p><p>In the validatePaymasterUserOp function, you’ll notice that we have a couple of values we can return:</p><ul><li><strong>context: </strong>additional context which is supplied to the postOp</li><li><strong>validationData: </strong>which comprises a packed set of three variables. The entry point <a href="https://github.com/eth-infinitism/account-abstraction/blob/releases/v0.6/contracts/core/EntryPoint.sol#L476C10-L477">parses this data</a> to ensure that the first packed value, the <strong>sigAuthorizer</strong>, is set to 0. Additionally, it verifies that the <strong>block.timestamp</strong> falls within the range specified by the other two values: <strong>validAfter</strong> and <strong>validUntil</strong>. Zero represents a special value indicating a signature that is valid indefinitely with no expiration.</li></ul><p>Once you have your Paymaster ready, go ahead and deploy it to your local hardhat project (unless you turn off the Hardhat node, in that case you need to re-run hardhat node and re-deploy EntryPoint, AccountFactory).</p><h4>Update the PaymasterAndData field</h4><p>In this last step, you need simply do a small changes in the <strong>execute.js </strong>file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZZprfNwAIHptFY7t9yBN8A.png" /><figcaption>execute.js</figcaption></figure><h4>Execute the User Operation</h4><p>Once again, test it all out by executing the user operation! This time the gas should be covered by the paymaster.</p><p>If you’re able to set a variable in the SimpleStorage smart contract, just like in the step 1, you’re doing amazing!</p><p>Now let’s try with your chainlet, deploy Paymaster (remember to use the flag — network your_chainlet) and run the <strong>execute.js.</strong></p><p>If everything is okay, you should have the same event flow as described in the section: <a href="#8187"><strong>Testing Account Abstraction in your chainlet</strong></a><strong>.</strong></p><h4>Implement Paymaster on your dApp</h4><p>On the frontend side, just like the hardhat project, you only need to make some changes. (<a href="https://github.com/chefleo/saga_nft_drop/tree/with_paymaster"><strong>Github</strong></a> branch with_paymaster)</p><p>You need to add the <strong>contract address</strong> and <strong>ABI</strong> to the folder where you store the other contract addresses and ABIs, such as EntryPoint, AccountFactory, etc.</p><p>Then you need to make the same changes as in the <strong>execute.js</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oGpokPqRsWXVZft_jbPdrA.png" /></figure><h3><strong>Implement Account Validation</strong></h3><p>If we examine the smart account from step 1, we’ll notice that there’s currently no restriction preventing anyone from utilizing the smart account. <br>We’ll need to establish a method to validate each user operation and confirm whether the provided signature demonstrates the user’s authorization to execute the operation against this account. <br>In step 1, we included an owner in the constructor of the smart account; let’s explore how we can leverage it now!</p><p><strong>OpenZeppelin</strong> provides an audited utility library for<a href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.5/contracts/utils/cryptography/ECDSA.sol"> elliptic curve digital signature algorithm (ECDSA) operations</a>.</p><p>For this step, we’ll need to install OpenZeppelin’s contract library using the command:</p><pre>yarn add @openzeppelin/contracts@4.9.5</pre><p>Then, in your smart account, you can import the ECDSA utility from /contracts/utils/cryptography/ECDSA.sol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WaZcWJP7ezaVTlXt90xhzQ.png" /><figcaption>Account.sol</figcaption></figure><p>We are checking to see if the owner <strong>signed</strong> a message userOpHash (we are going to explain what this is soon) and, if they did, returning a 0 indicating that this is a valid signature.</p><p>We’ll need to sign the message userOpHash using ECDSA and pass it in the <strong>user op signature</strong> field. Both viem and ethers provide a signMessage utility that can be utilized for this purpose.</p><p>The signMessage concatenates the “\x19Ethereum Signed Message:\n” prefix, along with the <strong>length of the string</strong>, and finally, the <strong>string itself</strong>. Subsequently, it computes the <strong>keccak hash of this concatenated message</strong>, which is equivalent to the<a href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.5/contracts/utils/cryptography/ECDSA.sol#L165C1-L174"> toEthSignedMessageHash function in the OpenZeppelin ECDSA library on-chain</a>.</p><p>But what is the userOpHash? As the name suggests, the <strong>userOpHash</strong> is basically the hash of the userOp. We can obtain the hash by calling the ‘entryPoint.getUserOpHash(userOp)’ method, passing in the userOp struct (with the signature: “0x”) as the only argument.</p><p>After obtaining the userOpHash, we will sign it using the ‘<strong>signMessage</strong>’ function and replace the signature ‘0x’ with the actual signature obtained.</p><p>Now, use the ‘handleOps’ function as usual.</p><p>Note: Since the Account contract has been changed, you will need to redeploy AccountFactory.sol and update the account address of AccountFactory in execute.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q-8-YULtGs0JGQZLTy1h0A.png" /></figure><p>To test this out, simply run ‘npx hardhat run scripts/execute.js’. Then, in the execute.js file, add a new signer and sign with the new signer. You should get ‘FailedOp(0, “AA24 signature error”)’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SOaFUtXmxqSeVVi0SK8lAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNGKxGFDgVIhE_2aXMB5pg.png" /></figure><h4>Implement Account Validation in your dApp</h4><p>On the frontend side, you need to redeploy AccountFactory in your <strong>chainlet. </strong>Then, update the <strong>contract address</strong> of the AccountFactory and the <strong>ABI</strong> of the Account</p><p>Then, just like the Hardhat project, get the userOpHash and sign the hash using Viem signMessage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GZT0QjxdHfplC7iLPkDaHw.png" /></figure><h4>Conclusion</h4><p>Congratulations! Now that you have taken your first steps on Account Abstraction on your chainlet, feel free to personalize it and give your dApp some unique features.</p><p>For more details around how you can evolve your dApp, follow us on <a href="https://twitter.com/Sagaxyz__"><strong>X</strong></a>, join our <a href="https://discord.gg/UCRsTy82Ub"><strong>Discord</strong></a> and <a href="https://xyz.us10.list-manage.com/track/click?u=ca44fab3b7b6185f64afb274a&amp;id=f450024c8d&amp;e=4c17c9cc64"><strong>Telegram</strong></a> and subscribe to our <a href="https://xyz.us10.list-manage.com/track/click?u=ca44fab3b7b6185f64afb274a&amp;id=853c5406bb&amp;e=4c17c9cc64"><strong>Medium</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f66d0368fca3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sagaxyz/stack-exploder-account-abstraction-no-fee-transactions-protocol-native-account-abstraction-f66d0368fca3">Stack Exploder: Account Abstraction + No-fee transactions — Protocol Native Account Abstraction</a> was originally published in <a href="https://medium.com/sagaxyz">Saga AI Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stack Exploder: Bridging Your Saga Chainlet Assets Across EVM Networks using Hyperlane]]></title>
            <link>https://medium.com/sagaxyz/stack-explorer-bridging-your-saga-chainlet-assets-across-evm-networks-using-hyperlane-28b1cfe8f69e?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/28b1cfe8f69e</guid>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Sun, 21 Apr 2024 18:34:55 GMT</pubDate>
            <atom:updated>2024-04-22T14:07:18.972Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*xaedAuG6t50JbXUjooTAew.png" /></figure><p>The <a href="https://medium.com/sagaxyz/stack-explorer-democratizing-blockchain-development-sagas-no-code-solutions-saga-under-the-0203b2856346">Stack Exploder: Democratizing Blockchain Development using Saga’s No-Code Solutions</a> guide delved into how you can create a chainlet using the command line based <strong>sagacli</strong> or the user-friendly <a href="https://app.saga.xyz/launch"><strong>Saga Web App</strong></a><strong>.</strong></p><p>But sometimes you need to collaborate with a dApp or web3 game that is on another chain, such as Ethereum or even another chainlet on Saga. Or, simply migrate assets from your game on Ethereum (or any EVM chain) to your Saga chainlet.</p><p>Crosschain functionality is becoming important in the blockchain industry because it provides seamless communication and asset transfer between disparate networks. It promotes interoperability, allowing users to access services and assets across multiple blockchains. This will unlock new opportunities for decentralized finance, gaming, and other blockchain applications.</p><p>All this is possible using <a href="https://www.hyperlane.xyz/"><strong>Hyperlane</strong></a>.</p><p><strong>Hyperlane</strong> is a <a href="https://docs.hyperlane.xyz/docs/deploy-hyperlane">permissionless interoperability</a> layer that allows smart contract developers to send <strong>arbitrary data between blockchains</strong>.<br>Among its functionalities, developers can utilize Hyperlane to seamlessly transfer tokens such as ERC20 (digital tokens).</p><p>In this guide, we’ll deep-dive into leveraging Hyperlane to bridge ERC20 tokens between your Saga <strong>chainlet</strong> and <strong>Sepolia</strong>, facilitating bidirectional communication.</p><p>This guide will cover:</p><ol><li>Deploying Hyperlane into your Saga Chainlet</li><li>Running Validators and Relayers (using Kurtosis)</li><li>Testing the Bridge</li><li>Creating and deploying a Warp Route</li><li>Interacting with the Warp Routes</li></ol><h4>The Hyperlane protocol</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DH1jr1J5xVHFlWuqVO40-A.png" /></figure><p>Users interact with the Hyperlane protocol through <a href="https://docs.hyperlane.xyz/docs/protocol/mailbox"><strong>mailbox</strong></a> <strong>smart contracts</strong>, which provide an on-chain <a href="https://docs.hyperlane.xyz/docs/reference/messaging/messaging-interface">messaging interface</a> to send and receive interchain messages.<br>Hyperlane adopts a modular security paradigm, granting applications the flexibility to configure and select from a range of <a href="https://docs.hyperlane.xyz/docs/protocol/ISM/modular-security"><strong>Interchain Security Modules</strong></a> (ISMs). By specifying an ISM, applications can tailor the security model to suit their integration with the Hyperlane messaging interface.</p><p>Another more simple way to see the Hyperlane protocol is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1uHL9rFhhKgYNl-uhiPFog.png" /></figure><ol><li>The Hyperlane mailbox contract is like a post office, with offices open on each chain.</li><li>Every post office (or Hyperlane mailbox smart contract) manages both <strong>incoming</strong> and <strong>outgoing</strong> mail, ensuring that inbound correspondence is efficiently routed to individual PO boxes.</li><li>Each application that uses Hyperlane is an owner of a unique PO box.</li><li>The PO box owner (the app) controls the checklist (<a href="https://docs.hyperlane.xyz/docs/protocol/ISM/modular-security">interchain security module</a>).</li><li>The checklist serves as a comprehensive list of criteria, encompassing security model logic and message parameters. It acts as the arbiter, determining whether a message meets the requirements for delivery to the designated PO box.</li><li>Clerks (<strong>validators</strong>) are responsible for <strong>signing off</strong> on messages and holding PO box keys.</li><li>Mailmen (<strong>relayer</strong>) deliver messages to destination post offices (chains).</li><li>If message contents pass the criteria on the checklist (ISM) then the message is delivered.</li></ol><p>In essence, the flow of Hyperlane operates as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vbFpqioY-BOM15bgPj1geQ.png" /></figure><h3>Deploy Hyperlane into your chainlet</h3><p>Please note:</p><blockquote>The wallet you use to deploy will serve as your <strong>validator</strong> and <strong>relayer</strong>. As such, it is strongly recommended to create <strong>another wallet instead of using your Genesis chainlet wallet</strong>. You will, however, have to send some chainlet tokens and SepoliaETH to the new wallet to run this tutorial.</blockquote><h4>Setup</h4><p>First, install the <a href="https://www.npmjs.com/package/@hyperlane-xyz/cli">Hyperlane CLI</a> from NPM (<a href="https://nodejs.org/en/download">Node 16</a> or newer is required).</p><pre>npm install -g @hyperlane-xyz/cli</pre><p>Next, we need to create a <strong>custom chain configurations</strong> using your Saga chainlet info. <br>Any chains that are already included in the Hyperlane SDK won’t require a chain config (but you can optionally create one if you want to override default settings)</p><p>Running the following command will display the default SDK chains:</p><pre>hyperlane chains list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/0*hLVPQu3D55BXSoIe" /></figure><p>You can define the <strong>chain configuration</strong> manually using JSON or YAML (you can view<a href="https://github.com/chefleo/hyperlane-saga/blob/warps/omegachain/configs/chains.yaml"> my example</a> or the example provided by<a href="https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/cli/examples/chain-config.yaml"> Hyperlane</a>), or create them with the following command:</p><pre>hyperlane config create chain</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*LFFpiqLFS-u29Afo" /></figure><p>In the end you should have <em>chains.yaml</em> like this:</p><pre>&lt;chianlet_name&gt;:<br>  chainId: &lt;chainlet_chainId&gt;<br>  domainId: &lt;chainlet_chainId&gt;<br>  name: &lt;chainlet_name&gt;<br>  protocol: ethereum<br>  rpcUrls:<br>    - http: &lt;chainlet_rpcUrl&gt;</pre><p>You should add also (it will be useful later):</p><pre>isTestnet: true # If you created the chainlet on the testnet, otherwise you don&#39;t even need this line<br><br><br>nativeToken:<br>  name: &lt;your_chainlet_token_name&gt;<br>  symbol: &lt;your_chainlet_token_symbol&gt;<br>  decimals: 18</pre><p>For this tutorial it will be:</p><pre>omegachain:<br>  name: omegachain<br>  chainId: 1712771388991266<br>  domainId: 33333<br>  protocol: ethereum<br>  rpcUrls:<br>    - http: https://omegachain-1712771388991266-1.jsonrpc.testnet.sagarpc.io<br><br># Optional fields, not required for Hyperlane deployments but useful for later<br>  isTestnet: true<br><br>  nativeToken:<br>    name: ome<br>    symbol: ome<br>    decimals: 18</pre><blockquote>⚠️ <strong>Note</strong>: You need to change <strong>domainId</strong> to another number of your choice that is not a chainlet ID. The reason for that is you will probably get an ‘Error: value out-of-bounds’ (because the chainId is too big).</blockquote><p>Now the Hyperlane CLI is ready to interact with your Saga chainlet. However, it also needs to know how to configure your Interchain Security Module (ISM).</p><p>To create a multisig ISM config, you have to define it manually using JSON or YAML (you can view<a href="https://github.com/chefleo/hyperlane-saga/blob/main/configs/ism.yaml"> my example</a> or the example provided by<a href="https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/cli/examples/ism.yaml"> Hyperlane</a>), or create it with the following command:</p><pre>hyperlane config create ism</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9Sx0K0eN8Ji9Xris" /></figure><p>In the end you should have <em>ism.yaml</em> like this:</p><pre>&lt;chainlet_name&gt;:<br>  threshold: 1 # Number: Signatures required to approve a message<br>  validators: # Array: List of validator addresses<br>    - &quot;&lt;an_address_wallet&gt;&quot; #NOT your Genesis address wallet</pre><p>For this tutorial it will be:</p><pre>omegachain:<br>  threshold: 1<br>  validators:<br>    - &quot;0x4cDF9dd5d678E4274e5DBB902E91b80373899513&quot;</pre><p>In this guide, we will be using a 1/1 multisig with a threshold of 1. <br>However, if you want to explore<a href="https://docs.hyperlane.xyz/docs/protocol/ISM/modular-security"> advanced ISM</a> configurations, you can find them in this<a href="https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/cli/examples/ism-advanced.yaml"> GitHub example</a>.</p><h3>Deploy</h3><p>Now that our ISM module is configured, it’s time to deploy Hyperlane contracts. To deploy use the command:</p><pre>hyperlane deploy core \<br>    --targets chain1,chain2,... \ # all the chains you want to bridge between<br>    --chains $CHAIN_CONFIG_FILE \  # path to chains.yaml config e.g. ./configs/chains.yaml<br>    --ism $MULTISIG_CONFIG_FILE \ # path to ism.yaml config e.g. ./configs/ism.yaml<br>    --artifacts $PREDEPLOYED_ARTIFACT_FILE \ # (optional) in case you want to reuse contracts you&#39;ve already predeployed<br>    --out $OUT_DIR \ # (optional) deployment contract artifacts<br>    --key $WALLET_PRIVATE_KEY</pre><p>For this tutorial it will be:</p><pre>hyperlane deploy core \<br>--targets sepolia,omegachain \ # We are bridging between sepolia and omegachain chains<br>--chains ./configs/chains.yaml \ # The chain config file<br>--ism ./configs/ism.yaml \ # The ISM module config file<br>--key 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6<br># This private key is from a test wallet and only for the purpose of this guide. Never share your private keys. </pre><p>If the deployment went well, you should see an output similar to this in your terminal:</p><pre>Hyperlane CLI<br>Hyperlane permissionless core deployment<br>----------------------------------------<br>Reading file configs in ./configs/chains.yaml<br>All chain configs in ./configs/chains.yaml are valid<br><br>Deployments can be totally new or can use some existing contract addresses.<br>? Do you want use some existing contract addresses? no<br>All multisig configs in ./configs/ism.yaml are valid<br>Found configs for chains: sepolia, omegachain<br><br>Deployment plan<br>===============<br>Transaction signer and owner of new contracts will be 0x4cDF9dd5d678E4274e5DBB902E91b80373899513<br>Deploying to sepolia, omegachain<br>There are several contracts required for each chain but contracts in the Hyperlane SDK will be skipped<br>? Is this deployment plan correct? yes<br>Running pre-flight checks...<br>Chains are valid ✅<br>Signer is valid ✅<br>Balances are sufficient ✅<br>All systems ready, captain! Beginning deployment...<br>Contract addresses will be written to artifacts/core-deployment-2024-02-28-09-12-01.json<br>Agent configs will be written to artifacts/agent-config-2024-02-28-09-12-01.json<br>Deploying ISM factory contracts<br>Start deploy to sepolia,omegachain<br><br><br>===============<br><br># A looong list of smart contract deployments<br><br>===============<br><br>Writing agent configs<br>Agent configs written<br>Deployment is complete!<br>Contract address artifacts are in artifacts/core-deployment-2024-02-28-09-12-01.json<br>Agent configs are in artifacts/agent-config-2024-02-28-09-12-01.json</pre><p>Deployment contract artifacts will be written to to the artifacts/ folder by default. The deployer will create two timestamped files:</p><ul><li>agent-config-{timestamp}.json which contains the data needed to run Hyperlane agents for the next step (<a href="https://github.com/chefleo/hyperlane-saga/blob/warps/omegachain/artifacts/agent-config-2024-04-19-10-48-17.json">my agent config obtained</a>).</li><li>core-deployment-{timestamp}.json which contains the addresses of core contracts, , organized by chain (<a href="https://github.com/chefleo/hyperlane-saga/blob/warps/omegachain/artifacts/core-deployment-2024-04-19-10-48-17.json">my core deployment obtained</a>).</li></ul><h3>Run validators and relayer</h3><p><strong>Validators</strong> monitor the <a href="https://docs.hyperlane.xyz/docs/protocol/mailbox">Mailbox</a> contract, while <strong>relayers</strong> ensure messages reach their intended recipients successfully.</p><p>In this guide, we will use <a href="https://www.kurtosis.com/">Kurtosis</a>, which is a single-click <strong>validator</strong> and <strong>relayer</strong> deployment in the cloud, partnered with Hyperlane.</p><p>To get started, use the deploy kurtosis-agents command to generate a link for configuring your Kurtosis deployment.</p><pre>hyperlane deploy kurtosis-agents</pre><p>Follow the prompts and then click on the Kurtosis Cloud link provided by the command output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/0*Rv_q5O7Ol7VSOF3b" /></figure><blockquote>If this is your first time using Kurtosis Cloud, you’ll need to sign in with Github and Kurtosis will provision a remote cloud instance for your validator and relayer.</blockquote><p>When you click the Kurtosis Cloud link, a prefilled configuration screen will pop up in your browser with all your relayer and validator information needed.</p><p>If you encounter issues deploying agents on Kurtosis Cloud through the CLI, you can manually input this information by:</p><ol><li>Signing into <a href="https://cloud.kurtosis.com/">Kurtosis Cloud</a>.</li><li>Clicking Run on the Hyperlane Package.</li><li>Filling in the configuration modal with your agent-config-{timestamp}.json.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HnEfAiV1T9-_kAZJBlSd5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6Bbwm6iH0EO48Fcl" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/0*Y6z_k3JJfKAh9sSy" /></figure><p>Then click Run to deploy your relayer and validator, if everything is done correctly you’ll see a green check mark!</p><p>Congratulations! You’ve now deployed your own relayer and validator with Kurtosis!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-8htsNq11r0Ebpl-5DiaQ.png" /></figure><p>You can access information about your relayer and validator deployment, including logs, by navigating to the Overview tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7bcNMwG5Dbwsgs-yiHzfTQ.png" /></figure><p>Before we proceed to the next step, we recommend waiting for 15 minutes to allow the relayer to sync with Sepolia and your chainlet network.</p><p>Alternatively, you can go to Relayer &gt; Logs and check for the synced tag on both chains before proceeding to the next step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*68ZpBXIO2meR1X4G" /></figure><h4>Testing the bridge by sending a message</h4><p>Now it’s time to test if the bridge works.<br>To test it, we are going to send a message from our chainlet to Sepolia.</p><p>Initiate the message using the CLI. It will prompt you to select a set of core deployment artifacts. Choose the core-deployments JSON file that you created in the <strong>Deploy</strong> section.</p><pre>hyperlane send message --key $PRIVATE_KEY</pre><p>The send message command will inform you when the message is dispatched. After a short wait, you’ll receive a confirmation of delivery.</p><blockquote>If the message delivery times out, there may be an issue with the Validator or Relayer setup outlined in the previous steps.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*omHQ0iq-jcbQ-RP-" /><figcaption>hyperlane send message output</figcaption></figure><p>You can see the transaction on<a href="https://explorer.hyperlane.xyz/"> <strong>Hyperlane Explorer</strong></a><strong>. </strong>In case the transaction doesn’t appear on the Hyperlane explorer, you can check if the message arrived on the destination chain (Sepolia in this case) through the recipient address in the events logs, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TJjocfVlm6ILgli021xBUA.png" /></figure><h3>Deploy a Warp Route (Bridging ERC-20)</h3><p>Warp Routes are contracts that allow any ERC-20, ERC-721 to move effortlessly between chains.</p><blockquote>⚠️ <strong>Note</strong>: At the time of creating this blog post (Hyperlane CLI version 3.10.0), performing a warp for ERC721 tokens and consequently bridging ERC721 tokens between chains is not possible due to an error occurring when executing the command hyperlane config create warp <br>However, it’s important to note that the difference in creating ERC20 and ERC721 tokens is minimal. In fact, it’s just a matter of setting the isNFT variable to true.<br>If you wish to bridge an NFT between chains, please check the <a href="https://github.com/hyperlane-xyz/hyperlane-monorepo"><strong>Hyperlane repository</strong></a> to see if they have released a version that properly supports NFT bridging.</blockquote><p>Warp Routes represent Hyperlane’s permissionless token bridging module, offering a distinct approach to token bridging. Unlike conventional token wrapping protocols, Warp Routes are secured by Interchain Security Modules (ISM).</p><h4>Collateral vs Synthetic chain</h4><p>Before jumping into creating Warp Routes, let’s first understand the difference between <strong>Collateral</strong> vs <strong>Synthetic</strong> chains so you can understand the architecture of the Warp Route.</p><ul><li><strong>Collateral chain: </strong>the origin chain where you deposit any ERC-20 or ERC-721 token to a HypCollateral contract.</li><li><strong>Synthetic chain: </strong>the destination chains between which HypERC-20/HypERC-721 tokens can flow. HypERC-20/HypERC-721 tokens are minted 1:1 from tokens locked as collateral.</li></ul><h4>Warp Route architecture overview</h4><p>Warp Route contracts transfer value between chains by initially locking tokens as collateral on the origin chain (Collateral chain) and then minting the tokens as wrapped tokens (HypERC-20/HypERC-721 synthetics) which are transferred to the destination chain (Synthetic chain). <br>The locked tokens can be returned to the origin chain at any time to reclaim the initial ERC-20/ERC-721 tokens (collateral). <br>Warp Routes use Hyperlane <strong>Mailbox contracts</strong> which enable communication between chains.</p><h4>Warp Route Token Flow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q7y1pvVpcQ50RcXwwl4tsw.png" /></figure><p>As a developer, you can transfer any ERC-20/ERC-721 contract on the Collateral chain which is wrapped by the HypERC20Collateral/HypERC721Collateral contract to mint new HypERC-20/HypERC-721 tokens.</p><p>The Mailbox contract on the collateral chain <strong>forwards the data as a message to the relayer</strong>, which then passes the message data to the <strong>Interchain Security Module</strong> (ISM) for verification. <br>Once verified, the ISM sends the information back to the Mailbox, which then forwards the data to the HypERC20/HypERC721 contract on the <strong>synthetic</strong> chain. This contract mints and reflects the value 1:1 of the ERC-20/ERC-721 contract on the <strong>Collateral</strong> (origin) chain.</p><p>Warp Routes require gas fees to function, which are paid as part of outbound messages. The Router estimates the gas fee for the transfer before transferring the HypERC20/HypERC721 tokens to the <strong>destination chains</strong>.</p><p>Therefore, it’s necessary to have a gas token, such as the chainlet native token (in this case, omegachain token), or any other native token (in this case, SepoliaETH), on the Collateral (origin) chain before deploying or using a Warp Route.</p><h3>How to deploy Warp Route</h3><p>For this guide, we will use these<a href="https://omegachain-1712771388991266-1.testnet.sagaexplorer.io/token/0x21198920Bc56b73DBfbF547a6Ee8118A515Ce04D"> <strong>ERC20</strong></a> tokens as examples (deployed on <strong>omegachain</strong> chainlet).</p><p>The easiest way to create a Warp Route is with the CLI’s config command. Alternatively, you can define it manually using YAML (you can see <a href="https://github.com/chefleo/hyperlane-saga/blob/warps/omegachain/configs/warp-route-deployment.yaml">my example</a> or the<a href="https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/cli/examples/warp-route-deployment.yaml"> Hyperlane example</a>)</p><pre>hyperlane config create warp</pre><h4>Base (Collateral/Origin)<a href="https://docs.hyperlane.xyz/docs/guides/deploy-warp-route#base">​</a></h4><p>Your config <strong>must</strong> have exactly <strong>one</strong> base entry. Here you will configure details about the token for which you are creating a Warp Route:</p><ul><li><strong>chainName</strong>: Set this equal to the chain (in our case the Chainlet name) on which your token exists</li><li><strong>type</strong>: Set this to TokenType.collateral to create a Warp Route for an ERC20/ERC721 token.</li><li><strong>address</strong>: If using TokenType.collateral, the address of the ERC20/ERC721 contract for which to create a route.</li><li><strong>isNft</strong>: If using TokenType.collateral for an ERC721 contract, set to true.</li></ul><h4>Synthetics<a href="https://docs.hyperlane.xyz/docs/guides/deploy-warp-route#synthetics">​</a></h4><p>Your config must have at least one synthetics entry. Here you will configure details about the remote chains supported by your Warp Route.<br>(For the optional fields, you can check <a href="https://docs.hyperlane.xyz/docs/guides/deploy-warp-route#optional-fields">Hyperlane docs</a>)</p><ul><li><strong>chainName</strong>: Set this equal to the chain on which you want a wrapped version of your token (our case Sepolia)</li></ul><p>In the end your should have <em>warp-route-deployment.yaml </em>like this:</p><pre>base:<br>  chainName: &lt;chainlet_name&gt;<br>  type: collateral<br>  address: &quot;&lt;contract_address_of_the_erc20/erc721&gt;&quot;<br>  isNft: false # if is erc721 set to true<br>synthetics:<br>  - chainName: sepolia</pre><p>In this tutorial:</p><pre>base:<br>  chainName: omegachain<br>  type: collateral<br>  address: &quot;0x21198920Bc56b73DBfbF547a6Ee8118A515Ce04D&quot;<br>  isNft: false<br>synthetics:<br>  - chainName: sepolia</pre><h3>Deployment</h3><p>Run the following command to initiate the deployment of the Warp Route:</p><pre>hyperlane deploy warp </pre><p>Once finished, the CLI will create two new JSON artifact files: warp-route-deployment-{timestamp} and warp-config-{timestamp}. <br>The first contains just addresses for the newly deployed Warp router contracts. <br>The second is a config file for the Warp UI, which you can use for the <strong>next step.</strong></p><p>In my case warp-ui-token-config files are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SbRB2bLVOvyGHbYl" /><figcaption>warp-config-{timestamp} of the OmegaERC20</figcaption></figure><h3>Interact with the Warp Routes</h3><p>After you’ve successfully deployed a Warp Route, you can interact with your routes by forking the <a href="https://github.com/hyperlane-xyz/hyperlane-warp-ui-template">Hyperlane Warp UI template</a> (I also provide my <a href="https://github.com/chefleo/hyperlane-saga-ui-warp">repository</a> for better understanding, although it is very similar to the original).</p><p>With this repo you can easily “connect” your warp routes:</p><ol><li>Install dependencies with yarn</li><li>Copy all the value from the warp-config-{timestamp} file and paste them into .src/consts/tokens.yaml</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kr0Fa6Zyb9HOgIRt" /><figcaption><a href="https://github.com/chefleo/hyperlane-saga_ui_warp/blob/main/src/consts/tokens.yaml">https://github.com/chefleo/hyperlane-saga_ui_warp/blob/main/src/consts/tokens.yaml</a></figcaption></figure><p>3. Add your chainlet config by copying the <em>chains.yaml</em> file from the hyperlane config create chain section. Additionally, include nativeToken information such as name, symbol, and decimals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aJwFwwBvdaO4JZlt" /><figcaption><a href="https://github.com/chefleo/hyperlane-saga_ui_warp/blob/main/src/consts/chains.yaml">https://github.com/chefleo/hyperlane-saga_ui_warp/blob/main/src/consts/chains.yaml</a></figcaption></figure><p>4. Lastly build the project using yarn build and then yarn dev</p><p>Now let’s the magic happen 🪄 ✨</p><p>Here, you can see that this wallet has 2000 <a href="https://omegachain-1712771388991266-1.testnet.sagaexplorer.io/token/0x21198920Bc56b73DBfbF547a6Ee8118A515Ce04D">OmegaERC20</a> (OE20 for short) in the <strong>Omegachain</strong> chainlet network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/0*dDPcCnRb4z6QBiYl" /></figure><p>However, this token is not present in <strong>Sepolia</strong> Etherscan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/0*ba7wthDojfU0_qBK" /></figure><p>In the Hyperlane Warp UI, I bridge 1000 OmegaERC20 tokens from <strong>Omegachain</strong> to <strong>Sepolia.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CR0c2T0-LLyyg3t1" /></figure><p>You can observe that the process requires two transactions:</p><ul><li>The <strong>approve</strong> transaction, where you allow the <strong>HypERC20Collateral</strong> smart contract to utilize your tokens.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/0*BQOUW69o6Tt7kbPx" /></figure><ul><li>The <strong>transfer</strong> transaction, where you transfer 1000 OE20 to the <strong>HypERC20Collateral </strong>after that you should know the flow 😉 .</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/0*zXRsUHljuN17YDjW" /></figure><p>After a few minutes, you’ll notice that 1000 OmegaERC20 tokens are in the Sepolia network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/0*z_5BJU2H7mXQettx" /></figure><p>For better understanding, I will provide a video demonstrating all of these steps:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FlWZnpxzK1HQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DlWZnpxzK1HQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FlWZnpxzK1HQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1960df5dc7cda128bafffe3af0d25bf8/href">https://medium.com/media/1960df5dc7cda128bafffe3af0d25bf8/href</a></iframe><p>The entire code for this guide is available in these github repos:</p><ul><li>Hyperlane-saga: <a href="https://github.com/chefleo/hyperlane-saga/tree/warps/omegachain">https://github.com/chefleo/hyperlane-saga/tree/warps/omegachain</a></li><li>Hyperlane Warp UI: <a href="https://github.com/chefleo/hyperlane-saga_ui_warp">https://github.com/chefleo/hyperlane-saga_ui_warp</a></li></ul><h3>Conclusion</h3><p>Congratulations! You have effortlessly bridged ERC20 tokens between your Saga chainlet and the Ethereum chain. This guide is a preview into how you can evolve your chainlet to incorporate a “portal” that establishes connections with other chains. you have now <strong>unblocked</strong> a realm of boundless possibilities.</p><p>For more details around how you can <strong>Unblock your application</strong>, follow us on <a href="https://twitter.com/Sagaxyz__">X</a>, join our <a href="https://discord.gg/UCRsTy82Ub">Discord</a> and <a href="https://xyz.us10.list-manage.com/track/click?u=ca44fab3b7b6185f64afb274a&amp;id=f450024c8d&amp;e=4c17c9cc64">Telegram</a> and subscribe to our <a href="https://xyz.us10.list-manage.com/track/click?u=ca44fab3b7b6185f64afb274a&amp;id=853c5406bb&amp;e=4c17c9cc64">Medium</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28b1cfe8f69e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sagaxyz/stack-explorer-bridging-your-saga-chainlet-assets-across-evm-networks-using-hyperlane-28b1cfe8f69e">Stack Exploder: Bridging Your Saga Chainlet Assets Across EVM Networks using Hyperlane</a> was originally published in <a href="https://medium.com/sagaxyz">Saga AI Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stack Exploder: Implementing Costless Transactions Using Recycled Gas Tokens]]></title>
            <link>https://medium.com/sagaxyz/stack-exploder-implementing-costless-transactions-using-recycled-gas-tokens-ee51548b390e?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee51548b390e</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[gaming]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Thu, 25 Jan 2024 17:36:45 GMT</pubDate>
            <atom:updated>2024-06-11T15:29:24.504Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*Y75mmJ9Bj_i-qaI4kbKiTA.png" /></figure><ul><li><a href="#95d9"><strong>Introduction</strong></a></li><li><a href="#f962"><strong>Launch of your Chainlet with the “Gas Return Account” feature</strong></a></li><li><a href="#444f"><strong>The project</strong></a></li><li><a href="#0ac8"><strong>The smart contract</strong></a></li><li><a href="#2b7e"><strong>Deploy the Smart Contract in your chainlet</strong></a></li><li><a href="#d281"><strong>Connecting my chainlet into the front end project</strong></a></li><li><a href="#1b43"><strong>The front-end of the Address Book project</strong></a></li><li><a href="#2807"><strong>A visual representation of the recycled token economic flow</strong></a></li><li><a href="#4f12"><strong>The code implementation</strong></a></li><li><a href="#6749"><strong>Conclusion</strong></a></li></ul><h3>Introduction</h3><p>In <a href="https://medium.com/sagaxyz/stack-exploder-unblocking-web3-products-with-costless-transactions-387b9f03b7c5">Stack Exploder: Unblocking Web3 Products With Costless Transactions</a> we introduced Recycled Gas Tokens, a new method for Chainlet developers to achieve costless transactions using Saga’s revolutionary token flows.</p><p>In this article, we are going to explain how to implement this flow using a faucet that dispenses an appropriate amount of tokens into the user’s wallet just-in-time (JIT).</p><h3>Launch of your Chainlet with the “Gas Return Account” feature</h3><p>First of all you need to launch a chainlet. Saga already provides excellent<a href="https://docs.saga.xyz/working-with-chainlets/launch-your-chainlet#launching-a-chainlet-using-saga-web-app"> <strong>documentation</strong></a><strong> </strong>and a <a href="https://medium.com/sagaxyz/stack-explorer-democratizing-blockchain-development-sagas-no-code-solutions-saga-under-the-0203b2856346"><strong>blog post</strong></a> for exploration. However, I’ll briefly walk you through what I did to build my chainlet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNGgy1hZYTqC-mgt1QsUDA.png" /></figure><p>Where:</p><ol><li>The name of your chainlet (this case TUTORIALWORLDTWO)</li><li>The denomination or simply the main currency of your chainlet (this case TWT)</li><li>The Number of days of Chainlet operation that will be credited to the escrow account.<br>The cost is SetupFee(10 psaga) + (num of days * 10psaga/day), so in this case 10 + ( 30 * 10 ) = 310 psaga (+ gas fee for the launch)<br><strong>IMPORTANT NOTE: it should be equal or more than 30 days</strong></li><li>The EVM address and the desired amount of full tokens ( TWT )</li></ol><p>And then for our example we want some custom configurations for the chainlets. To <strong>enable advanced settings click on the cogs and enable advanced options:</strong></p><p>5. <strong>Gas Return Account</strong>: The designed wallet that will collect all fees paid by users for transactions executed to interact with the Chainlet.</p><p>6. <strong>Fixed Base Gas Price</strong>: Allows the developer to specify the base gas price per unit of transaction gas (in my case 0.0000001 TWT) instead of demand-based market pricing of gas.</p><p>Note about the <strong>Fixed Base Gas Price</strong>: You can still manage how much the gas price is in your dApp. For example, my fixed gas price is 0.0000001 TWT, but if I wanted, I could create a subscription model where:</p><ul><li>if the users are NOT subscribed, they paid, for example 0.1 TWT as gas fee</li><li>if the users are subscribed, they paid the base fixed fee, which is 0.0000001 TWT</li></ul><p>And keep in mind that the gas fees will be returned to the designated wallet, in this case, the specified developer’s wallet.</p><p>After this just click “Launch Chainlet” and approve the transaction to create your Chainlet.</p><p>If everything is done correctly, you will see that the Saga Web App brings you to this screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CDQbeRUmLasbwsG0bJDY2w.png" /></figure><p>Now you have all needed for your dApp, you can check this article if you need guidance about “<a href="https://medium.com/@simon-digiorgio/your-blockchain-your-web3-configuring-a-personalized-web3-experience-using-the-power-of-saga-a85bc5f561f5#6dde">Connecting your own chain to a block explorer and Metamask</a>” and “<a href="https://medium.com/@simon-digiorgio/your-blockchain-your-web3-configuring-a-personalized-web3-experience-using-the-power-of-saga-a85bc5f561f5#7254">Connecting your own chain into your personal projects</a>”</p><h3>The project</h3><p>The project is just a simple Address Book project built using:</p><ul><li><a href="https://docs.walletconnect.com/web3modal/react/about"><strong>WalletConnect / WebModal V3</strong></a>: for wallet connectivity</li><li><a href="https://1.x.wagmi.sh/"><strong>Wagmi v1</strong></a><strong> and </strong><a href="https://viem.sh/"><strong>Viem</strong></a>: for read and write call smart contract from our front-end dApp</li><li><a href="https://react.dev/"><strong>React</strong></a> and <a href="https://vitejs.dev/"><strong>Vite</strong></a></li></ul><p>And of course Saga, using my chainlet created in the section above. We are first going to deploy a simple example without Recycled Gas Tokens; then add the components afterwards.</p><p>Feel free to fork my <a href="https://github.com/chefleo/multicallAddressBook/tree/saga_v2">GitHub</a> and go to the saga_v2 branch and follow along with the article for a concise and a better understanding guide.</p><p>If you want to see the recycled token economic flow in action directly, feel free to navigate to the <a href="https://multicall-addres-git-214f0f-leonardo-simone-digiorgios-projects.vercel.app/"><strong>live demo</strong></a>.</p><blockquote>⚠️ Note: At the time this article was written, an old version of the chainlet was used. The GitHub repository and live demo now use the latest version of chainlets (with a chainlet under a different name, <a href="https://testnet.app.saga.xyz/chainlets/omegachain_1712771388991266-1">Omegachain</a>). However, don’t worry because the procedure described in this article remains the same.</blockquote><h3>The smart contract</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TRmHGQgexgn7euIs" /></figure><p>There is nothing special about this contract, it allows one to save a list of Ethereum account addresses to the blockchain with an alias name. However it also implemented the ability to be able to add multiple contacts with only a single transaction that saves gas fees (if you want details about Multicall you can check this <a href="https://medium.com/coinsbench/optimizing-smart-contract-interactions-a-guide-to-multi-call-integration-in-web3-front-end-dapp-936331156b57">article</a>).</p><h3>Deploy the Smart Contract in your chainlet</h3><p>For this project I am going to use Foundry. However, if you choose to use Hardhat or Remix, you can refer to this <a href="https://simon-digiorgio.medium.com/a-deep-dive-into-smart-contract-deployment-on-your-custom-chain-built-on-saga-acdfa1c50173">article</a>.</p><p>To deploy the AddressBook smart contract using Foundry, you need your smart contract in the folder src/AddressBook.sol (src/your_contract.sol). Then try compiling your contract to make sure everything is in order.</p><pre>forge build</pre><p>If your output looks like this, the contracts are successfully compiled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/0*wTEy4ol5Cmlu2I1E" /></figure><p><em>And you should be able to get your ABI in out/AddressBook.sol/AddressBook.json (out/Your_Contract.sol/your_contract.json)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/0*MT7WhihPl7YfOt1t" /></figure><p>Next, in the folder script I created a file in it called AddressBook.s.sol. This is where we will create the deployment script itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/0*Q8QKKzmAbTA5pARr" /></figure><p>Where you have to import your smart contract from the src folder, and then add new AddressBook() between the vm.startBroadcast() and vm.stopBroadcast() inside the run function.</p><p>Lastly, before deploy you need to export your private key from <a href="https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key#:~:text=On%20the%20&#39;Account%20details&#39;%20page,private%20key%20to%20your%20clipboard.">Metamask</a> and the use this command in your terminal:</p><pre>export PRIVATE_KEY=&lt;your_private_key&gt;</pre><p>Then to deploy run the command:</p><pre>forge script script/AddressBook.s.sol:AddressBookScript — rpc-url https://tutorialworldtwo-2705143118829000-1.jsonrpc.testnet-sp1.sagarpc.io — private-key $PRIVATE_KEY — broadcast</pre><p>If done correctly you should have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-ah4vs7fk4k73-sc" /></figure><p>And have the contract address in the folder broadcast/AddressBook.s.sol/2705143118829000 (which remember that 2705143118829000 is the chain id of the chainlet)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kHHj3037bR21iWo_" /></figure><h3>Connecting my chainlet into the front end project</h3><p>To configure your dApp, set up the following configuration in your <strong>_app.tsx</strong> file (if you’re using Next.js) or <strong>main.tsx</strong> file (if you’re using Vite, as in this case). Ensure that all functions are called outside the App component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npu9ODFuAr-JzQN8MN-pwg.png" /></figure><p>But, most importantly, if you want to use your chain in your dApp, you need to apply this configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*flh5OPzPvxDqjsz_" /></figure><p>In the end you should have your file <strong>_app.tsx</strong> or <strong>main.tsx</strong> like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/941dfb350437a37bf0b899cb57fe4482/href">https://medium.com/media/941dfb350437a37bf0b899cb57fe4482/href</a></iframe><p>If everything is configured correctly, you should be able to connect your wallet to the dApp and see that your dApp network is <strong>your chainlet</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/0*7fXt_9_lQ4gHIpMu" /></figure><h3>The front-end of the Address Book project</h3><p>We’ll begin with the addContacts transaction which if you remember correctly in the smart contract is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i9q_ThIRiO2BSTlJ" /></figure><p>The AddContacts function simply allows the user to save an Ethereum address with an alias name.</p><p>To be able to use addContact and execute this write function on the AddressBook contract, we utilize the Wagmi hooks: <a href="https://1.x.wagmi.sh/react/prepare-hooks/usePrepareContractWrite"><strong>usePrepareContractWrite</strong></a> and <a href="https://1.x.wagmi.sh/react/hooks/useContractWrite"><strong>useContractWrite</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/0*uD-fUq6twfKYvfoc" /></figure><p>From a UI point of view, the interaction should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aGWXUoIOEYVGBNLD" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KqNDrXi2qrNCFr1s" /></figure><p>But you may notice that a user checking your dApp doesn’t have any of your tokens, including for paying gas fees.</p><p>Indeed every operation on the smart contract, even on a chainlet with the lowest gas fees, requires a minimum balance. If a user has a balance of 0, they cannot execute any operations, even if the operation costs as little as 0.000000000001 TWT.</p><p>There are two solution for this:</p><ul><li>Create a website faucet for the user. However, it could be inconvenient for the user to navigate back and forth.</li><li>Create a recycled token economic flow using <strong>Saga’s revolutionary token flows</strong> and implement an <strong>auto faucet</strong> on your dApp.</li></ul><p>The second option is more interesting and we will show how to improve the example to implement Recycled Gas Tokens.</p><h3>A visual representation of the recycled token economic flow</h3><p>Let’s see conceptually how the recycled token economic flow will look visually. I want to focus on these two wallets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*nn3yQXI9Y2yv9ZlQHkxwHA.png" /></figure><p>The <strong>Developer</strong> wallet was specified as the <strong>tutorialworldtwo</strong> chainlet’s designated wallet, which consequently collects all fees paid by users (including the <strong>User</strong> wallet in this case) for transactions executed to interact with the chainlet.</p><p>The <strong>User</strong> wallet is the one we are using in this visual representation. Note that this wallet doesn’t have any TWT tokens.</p><p>Note: To have a greater visual representation of the recycle, I have increased the gas price of the write function call ‘addContact’ from the base gas fee price of 0.0000001 TWT to 0.00005 TWT (but on the live demo is the base gas fee which is 0.0000001 TWT).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ahIT4BAI5LxjI5V18_axbA.png" /></figure><p>Now let’s finally dive into the visual representation of the front end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OjHV_jjNtIFR5bhcf3hr5Q.png" /></figure><p>After the User wallet fills the address input with an Ethereum address, provides a name of his choice, and clicks on ‘Add Contact’, we want it to begin with <strong>borrowing TWT from the Developer wallet to the User wallet</strong>.</p><p>After the first part, this should be the status of the wallets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*lsMPppMtzMPYHh39kislgg.png" /></figure><p>In the second part, the <strong>User</strong> just needs to sign for the actual intended transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iaFLFjv4zVqG14vNtE_N_Q.png" /></figure><p>Lastly, there is the third and final part, which involves the execution of the addContact write call and the confirmation of the block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F98VEu0C027bJlO7FFwVmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ZTZjFOOaopHAp58p1mfVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iCNh6roDIMvT_JMJ6AQWHQ.png" /></figure><p>As you can see, the total cost of the transaction should be 4.48555 TWT (total gas = gas price * gas usage == 0.00005 * 89711).</p><p>After the confirmation of the block, this should be the status of the wallets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*F_WFQuZIQo9DM6pzDQxSiw.png" /></figure><p>You can see that the 4.48555 TWT came back to the developer, thanks to the recycled token mechanism.</p><p>The intended flow is to implement the flow discussed in<a href="https://medium.com/sagaxyz/stack-exploder-unblocking-web3-products-with-costless-transactions-387b9f03b7c5"> Stack Exploder: Unblocking Web3 Products With Costless Transactions</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wG1IkLbZW35whDAInAi0DA.png" /></figure><h3>The code implementation</h3><p>To transfer the token from the Developer to the User, first, you need to obtain your private key (to get your private key follow this <a href="https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key#:~:text=On%20the%20%27Account%20details%27%20page,private%20key%20to%20your%20clipboard.">guide</a> from Metamask).</p><blockquote><em>⚠️ Note: Please ensure that you keep your private key hidden from anyone by adding it to the .env file and including the .env file in your .gitignore.</em></blockquote><p>If you are a beginner check this guide: <a href="https://consensys.io/blog/how-to-avoid-uploading-your-private-key-to-github-approaches-to-prevent-making-your-secrets-public">How to Avoid Uploading Your Private Key to GitHub</a> and <strong>use your dev/test wallet</strong> for your projects NOT your main one.</p><p>This is where the auto faucet mostly operates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*Hq0hg2oOjxicOjx4ig9mXA.png" /></figure><p>(1) Instantiate a Private Key Account (Developer) using privateKeyToAccount and create a Wallet Client which provides the ability to execute transactions, sign messages, etc through <a href="https://viem.sh/docs/actions/wallet/introduction.html">Wallet Actions</a>.</p><p>(2) Create a sendGasToken function that sends the TWT token (or the token of your choice in your chainlet) using the client.sendTransaction() method. <br>In the function, I specified the Developer wallet (accountDev) as the sender account and the User Wallet (utilizing the <a href="https://1.x.wagmi.sh/react/hooks/useAccount">useAccount</a> Wagmi hook) as the recipient (address). <br>Lastly, I set the value, representing the amount of gas needed for the transaction (See the code below for a better understanding).<br>Then using the client.waitForTransactionReceipt method, we wait for confirmation of at least 1 block, ensuring that the User Wallet receives the TWT token.</p><pre>const hash = await client.sendTransaction({<br>    account: &lt;Developer_Wallet&gt;,<br>    to: &lt;User_Wallet&gt;,<br>    value: parseEther((&lt;estimate_contract_gas_fee&gt; * &lt;chainlet_gas_price&gt;).toString()),<br>ty});</pre><blockquote>[Fast-speaking medical warning]</blockquote><blockquote>The amount of gas needed for your smart contract transactions can vary significantly from one contract to another. To ensure a smooth and error-free transaction, it is crucial that you consult with your trusted smart contract professional.</blockquote><blockquote>Be advised, Sagaxyz will not assume responsibility for any miscalculations or errors made by the developer. Your financial safety is of the utmost importance. Act responsibly and seek professional advice for your smart contract needs.</blockquote><p>After this, you can proceed with your <a href="https://1.x.wagmi.sh/react/hooks/useContractWrite">regular write function call</a>, in this case, using the ‘addContact’ method.<br>(The code is simplified for a better understanding of the implementation, excluding variables, hooks, and functions that may lead to confusion. For more details, you can check <a href="https://github.com/chefleo/multicallAddressBook/blob/saga_v2/src/App.tsx">here</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Q1RCRWItrabHyivdVAkS5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dysa36N-JZ6P_CazKfNx6w.png" /></figure><h3>Conclusion</h3><p>Congratulations! You have successfully integrated a new economic model into your dApp, leveraging the transformative capabilities of the Saga Revolutionizes Token Flows to compete effectively with other dApps.</p><p>For more details around how you can evolve your dApp, follow us on <a href="https://twitter.com/Sagaxyz__">X</a>, join our <a href="https://discord.gg/UCRsTy82Ub">Discord</a> and <a href="https://xyz.us10.list-manage.com/track/click?u=ca44fab3b7b6185f64afb274a&amp;id=f450024c8d&amp;e=4c17c9cc64">Telegram</a> and subscribe to our <a href="https://xyz.us10.list-manage.com/track/click?u=ca44fab3b7b6185f64afb274a&amp;id=853c5406bb&amp;e=4c17c9cc64">Medium</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee51548b390e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sagaxyz/stack-exploder-implementing-costless-transactions-using-recycled-gas-tokens-ee51548b390e">Stack Exploder: Implementing Costless Transactions Using Recycled Gas Tokens</a> was originally published in <a href="https://medium.com/sagaxyz">Saga AI Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stack Exploder: Democratizing Blockchain Development: Saga’s No-Code Solutions (Saga under the…]]></title>
            <link>https://medium.com/sagaxyz/stack-explorer-democratizing-blockchain-development-sagas-no-code-solutions-saga-under-the-0203b2856346?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/0203b2856346</guid>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[cosmos]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Mon, 22 Jan 2024 17:51:06 GMT</pubDate>
            <atom:updated>2024-04-22T13:51:32.489Z</atom:updated>
            <content:encoded><![CDATA[<h3>Stack Exploder: Democratizing Blockchain Development using Saga’s No-Code Solutions (Saga under the hood)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/0*6XsF0dg-ZtcWOwfd" /><figcaption>Generated with Bing image creator</figcaption></figure><h4>Introduction</h4><p>Creating your own blockchain is tough. Developers have to be experts in blockchain infrastructure, juggling the security, decentralization and scalability of their setup.</p><p>Developers have to manually piece together data availability, consensus, execution, and settlement, all while managing the blockchain trilemma (security, decentralization, and scalability) separately for each part.</p><p>With the <strong>sagacli</strong> launching your own blockchain is now achievable in less than 10 minutes! However, using the CLI requires some technical hurdles — we can make it even easier. With the <a href="https://testnet-app.saga.xyz/launch"><strong>Saga Web App</strong></a>, it can be done in less than 1 minute!</p><p>In this article, I am going to briefly explain how to launch your own blockchain (or chainlet) using the <strong>Saga Web App</strong>, and what happens when you deploy a chainlet under the hood.</p><h4>The Saga Web App</h4><p>Before utilizing the web app, ensure you have a wallet like <a href="https://www.keplr.app/"><strong>Keplr</strong></a> that supports Cosmos SDK-based blockchains. If you are new to the Keplr Wallet, follow this <a href="https://help.keplr.app/articles/installation-guide-for-keplr-extension-for-beginners">tutorial</a> for installation and getting started.</p><p>To get a chainlet in the Saga Web App, you need to connect your Saga wallet and simply fill out the form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*Rcg6e3zM_Tw0vsFa" /></figure><ol><li>The name of your chainlet (this case SIMONECHAINLET)</li><li>The Demon or simply the main currency of your chainlet (this case SCH)</li><li>The Number of days of Chainlet operation that will be credited to the escrow account.<br>The cost is SetupFee(10 psaga) + (num of days * 10psaga/day), so in this case 10 + ( 30 * 10 ) = 310 psaga (+ gas fee for the launch)</li><li>The EVM address and the desired amount of full tokens ( SCH )</li></ol><p>You can also fill in 2 Advanced options by clicking the cog on the top right corner:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*_EJmCpSRqlTW4chd" /></figure><ol><li>Gas Return Account: Which is the designed wallet that will collect all fees paid by users for transactions executed to interact with the Chainlet.</li><li>Fixed Base Gas Price: Which is the base gas price per unit of transaction gas.</li></ol><p>If you’re interested in the details about these two features, please read<a href="https://medium.com/sagaxyz/stack-exploder-exploring-the-innovative-horizons-of-pegasus-incentivized-testnet-81b045fae172"> <strong>Stack Exploder: Exploring the Innovative Horizons of Pegasus Incentivized Testnet</strong></a></p><p>Once you’re finished, just click “<strong>Launch Chainlet</strong>” and you’ll receive a prompt from the Keplr wallet to approve this transaction. Click “<strong>Approve</strong>,” and the Chainlet will be launched!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*SrQxsLYpLAeze6K7" /></figure><p>If everything is done correctly, you will see that the Saga Web App brings you to this screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NMgiDtjeh6wtBnjT" /></figure><p>Congratulation now you have your own personal chainlet which come with:</p><ul><li>A dedicated RPC and WebSocked endpoint (Essential if you intend to<a href="https://simon-digiorgio.medium.com/a-deep-dive-into-smart-contract-deployment-on-your-custom-chain-built-on-saga-acdfa1c50173"> deploy a smart contract</a> in your Chainlet.)</li><li>A dedicated block explorer</li></ul><p>But now, let’s see what happens under the hood when we deploy a chainlet.</p><h4>Saga under the hood</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a-8a4b2Cy-5OH6_X" /></figure><p>(1) Developers initiate a chainlet request on the <strong>Saga controller chain</strong> by submitting a transaction through the Keplr wallet.</p><p>(2) This transaction, which includes all the input fields filled in the <strong>Saga Web App</strong>, serves as the formalized request.</p><p>(3) Validators consistently monitor the Saga controller chain, promptly identifying incoming chainlet requests, and subsequently executing the provisioning of the requested chainlet.</p><p>Within this robust system, validators have already curated a whitelist of chainlet versions, with the initial version being an EVM-based chainlet (allowing developers to <a href="https://simon-digiorgio.medium.com/a-deep-dive-into-smart-contract-deployment-on-your-custom-chain-built-on-saga-acdfa1c50173"><strong>deploy Solidity smart contracts</strong></a> on their own chain).</p><p>However, the architecture allows for flexibility in accommodating diverse virtual machines (VMs), various consensus technologies, and potential future innovations.</p><p>Subsequently, the provisioning of additional infrastructure such as RPC and block explorer, is handled by Saga’s service provider stack.</p><p>Chainlets not only solve performance issues via <strong>horizontal scaling</strong> but also contribute to a more user-friendly and predictable blockchain in Saga architecture. <br>In a monolithic blockchain, developers are subject to the main chain’s token prices, governance decisions, and development pace.</p><p>Saga distinguishes itself by abstracting away these dependencies, granting developers autonomy and flexibility in economic and governance aspects without being tied to a specific technology.</p><p>This approach enhances the overall usability and predictability of the blockchain for both <strong>developers</strong> and <strong>end-users</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aONpYxdf_YI2W3dN" /></figure><h4>Conclusion</h4><p>In summary, creating your own blockchain used to be tough for developers, but with sagacli and the Saga Web App, it’s become much easier — taking less than 10 minutes or even just a minute.</p><p>We explained the steps to launch your own blockchain using the Saga Web App.</p><p>Each chainlet you create includes key elements such as RPC and WebSocket endpoints, as well as a personal block explorer. These components are vital, particularly if you intend to deploy smart contracts.</p><p>Under the hood, we explored how each chainlet is requested on the Saga Mainnet, giving developers flexibility with their own VM module and EVM support for deploying Solidity smart contracts.</p><p>In conclusion, the nature of Chainlet components, including the VM module, SDK, and Tendermint Core, allows for independent upgrades, providing flexibility and adaptability. Chainlets not only address performance issues through horizontal scaling but also contribute to a more user-friendly and predictable blockchain in the Saga architecture.</p><p>The distinction becomes evident when comparing with monolithic blockchains, where developers are constrained by the main chain’s token prices, governance decisions, and development pace. Saga sets itself apart by abstracting away these dependencies, offering developers autonomy and flexibility in economic and governance aspects without being confined to a specific technology.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0203b2856346" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sagaxyz/stack-explorer-democratizing-blockchain-development-sagas-no-code-solutions-saga-under-the-0203b2856346">Stack Exploder: Democratizing Blockchain Development: Saga’s No-Code Solutions (Saga under the…</a> was originally published in <a href="https://medium.com/sagaxyz">Saga AI Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building your own faucet for your own testnet chain built on Saga]]></title>
            <link>https://simon-digiorgio.medium.com/building-your-own-faucet-for-your-own-testnet-chain-built-on-saga-a2a27b6e266f?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2a27b6e266f</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[cosmos-ecosystem]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Thu, 30 Nov 2023 18:23:42 GMT</pubDate>
            <atom:updated>2023-11-30T18:23:42.203Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*9-wwbV1lf7eizSRzfMOYFA.png" /><figcaption>Generated with Bing (Image Creator)</figcaption></figure><h4>Introduction</h4><p>A “Faucet” in the crypto world refers to a service dispensing small amounts of cryptocurrency, and specifically addresses the needs of those working on test networks. These test networks, distinct from the main blockchain, provide a sandbox environment for experimentation without the fear of financial loss.</p><p>A Faucet operates on various test networks, such as Ethereum’s Rinkeby, Ropsten, or Kovan networks. <br>Unlike the main blockchain, these networks use test tokens or “testnet coins,” providing a risk-free space for developers and users to explore new features, test smart contracts, and identify potential vulnerabilities. <br>Users seeking testnet coins simply need to provide their public wallet address associated with the specific test network, and upon verification, Faucet dispenses a small amount of these testnet coins.<br><strong> </strong><br>The Testnet serves as a multifaceted tool with essential purposes for both developers and the broader crypto community. For developers, it offers a risk-free testing ground, allowing them to identify and rectify issues before deploying applications on the main blockchain. It facilitates debugging, improvements, and serves as a valuable learning platform for users new to blockchain development.</p><p>Developers leveraging the Testnet gain numerous advantages, including cost-efficient development through the use of testnet coins instead of real cryptocurrencies. This approach enables faster development cycles and instills confidence in deployment by thoroughly testing applications on test networks.</p><p>Now, let’s dive into the details of our guide: <strong>building your faucet for your own testnet chain built on Saga</strong>.</p><p>This is the third article in the Saga series:</p><ul><li><a href="https://simon-digiorgio.medium.com/your-blockchain-your-web3-configuring-a-personalized-web3-experience-using-the-power-of-saga-a85bc5f561f5">How configuring a Personalized Web3 Experience using the power of Saga</a></li><li><a href="https://simon-digiorgio.medium.com/a-deep-dive-into-smart-contract-deployment-on-your-custom-chain-built-on-saga-acdfa1c50173">How deploy your smart contract in your chain</a></li><li>How to create a faucet for your chain (This article)</li></ul><h4>The plan</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CmTX6CB7prFH7sS4Fhf9eg.png" /></figure><p>Establish a faucet smart contract wherein the owner funds the contract. The smart contract (faucet) will then send tokens to users as needed.</p><p>However, there’s a caveat: Every operation on the smart contract, even on a chain with the lowest gas fees, requires a minimum balance. If a user has a balance of 0, they cannot execute any operations, even if the operation costs as little as 0.000000000001 token.</p><p><strong>The Solution</strong>: Delegate the execution of operations to an external entity, who can perform the operation on behalf of the user and receive the corresponding tokens. <br>This approach allows users with a balance of 0 to still access and benefit from the faucet by relying on the external person to initiate the necessary operations.</p><p>The solution will be implemented as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBiIhnUyjZXMPpUJMWVyIA.png" /></figure><h4>The smart contract</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/609740af31bd1871ff428542a4d87197/href">https://medium.com/media/609740af31bd1871ff428542a4d87197/href</a></iframe><p>This Solidity smart contract is a faucet that dispenses a fixed amount of Ether (0.5 Ether) to addresses requesting tokens. <br>The requestTokens function can be called only by the owner and transfers 0.5 Ether to the requested address if certain conditions, such as time-lock expiration and sufficient funds, are met.</p><p>The project that I am using is called multicallAddressBook, where you can check:</p><ul><li>my <strong>faucet</strong>: <a href="https://multicall-address-book-git-saga-chefleo.vercel.app/faucet">https://multicall-address-book-git-saga-chefleo.vercel.app/faucet</a></li><li>my <strong>github: </strong><a href="https://github.com/chefleo/multicallAddressBook/tree/saga">https://github.com/chefleo/multicallAddressBook/tree/saga</a></li></ul><p>Also used in my two previous article:</p><ul><li><a href="https://simon-digiorgio.medium.com/your-blockchain-your-web3-configuring-a-personalized-web3-experience-using-the-power-of-saga-a85bc5f561f5">How configuring a Personalized Web3 Experience using the power of Saga</a> (Where I also explained how I launched my own chain using <strong>SagaCli</strong>.)</li><li><a href="https://simon-digiorgio.medium.com/a-deep-dive-into-smart-contract-deployment-on-your-custom-chain-built-on-saga-acdfa1c50173">How deploy your smart contract in your chain</a></li></ul><h4>The Frond End code</h4><p>From the <strong>front end</strong> perceptive:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yhDuJEeFOpHPvS4H_BKC5Q.png" /></figure><p>The user simply puts their wallet address in the field and clicks the ‘Send Me Tutorials token’ button to submit a request to me, the owner of the contract. I then use my wallet to call the requestTokens function from the smart contract, and subsequently, the smart contract faucet sends the Tutorials tokens to the user.</p><p>From a <strong>code</strong> perceptive, in the <a href="https://github.com/chefleo/multicallAddressBook/blob/saga/components/Faucet.tsx">Faucet.tsx</a> component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LseXryvflD94PKZu-__aBw.png" /><figcaption>Faucet.tsx component</figcaption></figure><p>This is where the faucet mostly operates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDtLOjJzZPgz91-Ohpgz6g.png" /></figure><ol><li>Where i instantiate a Private Key Account (To get your private key follow this <a href="https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key#:~:text=On%20the%20&#39;Account%20details&#39;%20page,private%20key%20to%20your%20clipboard.">guide</a> from Metamask.) using privateKeyToAccount and create a Wallet Client which provides the ability to execute transactions, sign messages, etc through <a href="https://viem.sh/docs/actions/wallet/introduction.html">Wallet Actions</a>.</li><li>Next, I call the requestTokens function on behalf of the user using simulateContract to check if the transaction will proceed smoothly. Subsequently, I use writeContract to execute the function that modifies the state of the blockchain and sends the TutorialsToken to the user.</li></ol><blockquote><em>⚠️ Note: Please ensure that you keep your private key hidden from anyone by adding it to the .env file and including the .env file in your .gitignore.</em></blockquote><p>If you are a beginner check this guide: <a href="https://consensys.io/blog/how-to-avoid-uploading-your-private-key-to-github-approaches-to-prevent-making-your-secrets-public">How to Avoid Uploading Your Private Key to GitHub</a> and <strong>use your dev/test wallet</strong> for your projects NOT your main one.</p><p>Before reaching the conclusion, I suggest adding a <a href="https://www.google.com/recaptcha/about/"><strong>reCAPTCHA</strong></a> to prevent bots from executing multiple transactions and depleting the tokens in the smart contract.</p><h4>Conclusion</h4><p>In summary, creating a faucet for your custom testnet chain built Saga is a valuable tool for developers and crypto enthusiasts. These faucets enable developers to gain access to testnets that provide a safe space for testing and experimenting with small amounts of cryptocurrency on test networks. They’re like a sandbox for developers, allowing them to try out ideas, fix issues, and refine their applications without any real financial risk.</p><p>Beyond just testing, the Testnet serve as a practical bridge between learning blockchain concepts and applying that knowledge. They help developers fine-tune their projects, validate applications, and understand how blockchain functions in a risk-free environment.</p><p>In essence, building a faucet simplifies the journey of creating and testing decentralized applications. It’s not just about dispensing tokens; it’s about making blockchain experimentation accessible to everyone. This approach contributes to the collaborative and inclusive spirit of the crypto community, where each faucet not only gives tokens but opens doors for growth, learning, and the continuous evolution of decentralized technologies.</p><p><em>If you found the article valuable and wish to offer a gesture of encouragement:</em></p><ol><li><em>Clap 50 times for this article</em></li><li><em>Leave a comment telling me what you think</em></li><li><em>Highlight the parts in this article that you resonate with</em></li></ol><h3>Further Reading</h3><ul><li><a href="https://docs.saga.xyz/introduction/pegasus-overview"><strong>Saga Docs</strong></a></li><li><a href="https://viem.sh/"><strong>Viem</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2a27b6e266f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Deep Dive into Smart Contract deployment on your custom Chain built on Saga]]></title>
            <link>https://simon-digiorgio.medium.com/a-deep-dive-into-smart-contract-deployment-on-your-custom-chain-built-on-saga-acdfa1c50173?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/acdfa1c50173</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[cosmos]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Fri, 10 Nov 2023 18:43:32 GMT</pubDate>
            <atom:updated>2023-11-30T18:26:42.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*kyCPRtxaOa85tTHCYYlhwg.png" /></figure><h4>Introduction</h4><p>“Deploying Smart Contracts on Your Custom Chain: A Comprehensive Approach” is your all-in-one guide to understanding and executing smart contract deployment on your unique chain built using <strong>Saga</strong>.</p><p>The core of this guide is its thorough exploration of smart contract deployment strategies. It provides detailed explanations on how to deploy, and interact with smart contracts on custom chains, utilizing well-known development tools. <br>Whether you’re a beginner seeking foundational knowledge or a seasoned developer looking to enhance your skills, this guide offers practical insights and real-world examples tailored to different expertise levels.</p><p>This is the second article in the Saga series:</p><ul><li><a href="https://simon-digiorgio.medium.com/your-blockchain-your-web3-configuring-a-personalized-web3-experience-using-the-power-of-saga-a85bc5f561f5">How configuring a Personalized Web3 Experience using the power of Saga</a></li><li>How deploy your smart contract in your chain (This article)</li><li><a href="https://simon-digiorgio.medium.com/building-your-own-faucet-for-your-own-testnet-chain-built-on-saga-a2a27b6e266f">How to create a faucet for your chain</a></li></ul><p>For this article, it is necessary that you have already built your own chain, and you should have the following available:</p><ul><li>The chain id of your chain</li><li>The JsonRPC</li></ul><p>To get this, you can run these <strong>sagacli</strong> command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G2QhH0K79Qtq9RfmSHgd9A.png" /></figure><pre>sagacli chainlet list<br>sagacli chainlet apis &lt;your_chain_id&gt;</pre><h4>The Smart Contract</h4><p>In this article, I’ll be using a project we discussed in the previous <strong>article</strong> (<a href="https://github.com/chefleo/multicallAddressBook/tree/saga">Github</a>). However, feel free to choose any <strong>Solidity Smart Contract</strong> for deployment on your custom chain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pMwRDs3zqE4d1wC2_S209w.png" /><figcaption>AddressBook.sol</figcaption></figure><p>This smart contract, allows users to manage their contacts on the Ethereum blockchain. <br>Users can add, view, and remove contacts. <br>Each contact is associated with an Ethereum address and an optional alias name chosen by the user. <br>The contract ensures that addresses and alias names are valid before processing any operations. The contract also supports batched function calls for gas efficiency (<a href="https://medium.com/coinsbench/optimizing-smart-contract-interactions-a-guide-to-multi-call-integration-in-web3-front-end-dapp-936331156b57">Multicall</a>).</p><h4>Deploy the Smart Contract in your custom chain using Remix (For beginners)</h4><p>The easy way to deploy a smart contract is using the <a href="https://remix.ethereum.org/"><strong>Remix Ethereum IDE</strong></a><strong>.</strong></p><p>First of all open <strong>Remix </strong>and create a new file called AddressBook.sol (&lt;your_smart_contract&gt;.sol).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*dzP-tCzldS5rDgu7USL2zw.png" /></figure><p>Then copy the smart contract above (1), navigate to Solidity compile (2) and compile BuyMeACoffee.sol (3). <br>Now you have access to the <strong>ABI</strong>,<strong> </strong>which it can be useful if you want to interact your the front-end dApp with the smart contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWXT16hkO1J7Q4T9gNhXMg.png" /></figure><p>Then:</p><ul><li>Navigate to “Deploy and run transaction” (1) &gt; Environment (2).</li><li>Click on Injected Provider, which should prompt the Metamask extension to appear (3).</li><li>Once connected, switch from the mainnet or the chain that you are now use it to your own chain network.<br>To do this, click on the second icon located at the top left (4), and then select your chain (5) (in my case the chain tutorialsworld).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N7KhtCHnzrNBRSP1_66abQ.png" /></figure><p>In the end, if you see the screen displaying the network as &lt;chainId&gt; (my case … ) and you can identify your account, you can be assured that you are on the right track (6).</p><p>You can proceed with the deployment of your smart contract by clicking the “Deploy” button (7).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*OYoFu929HP3ThVB12u2FPg.png" /></figure><p>After that, the MetaMask popup should appear, asking you to confirm the contract creation using your chain token (8).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*u-0up3ymRBpokZPtNdqT2Q.png" /></figure><p>Once you’ve done that, you should observe the following information displayed at the bottom (9).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IXuT9Ry4_eCytibeIDjkAQ.png" /></figure><p>Also you can see your smart contract creation on your chain explorer (check sagacli chainlet apis &lt;your_chain_id&gt;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5QvMwBWsTpx74sut1pLuw.png" /><figcaption>Your chain explorer</figcaption></figure><h4>Deploy the Smart Contract in your custom chain using Hardhat</h4><p>To deploy your smart contract using hardhat, you need first of all to add a network entry to your hardhat.config.js file and add your own chain like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t9rSP7WdptfunHrPgLFbpw.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c015fe9231303623ecc343dd4d784de/href">https://medium.com/media/2c015fe9231303623ecc343dd4d784de/href</a></iframe><p>Where PRIVATE_KEY is the private key of the your Metamask wallet. <br>To get your private key follow this <a href="https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key#:~:text=On%20the%20&#39;Account%20details&#39;%20page,private%20key%20to%20your%20clipboard.">guide</a> from Metamask.</p><blockquote><em>⚠️ Note: </em>Please ensure that you keep your private key hidden from anyone by adding it to the .env file and including the .env file in your .gitignore.</blockquote><p>If you are a beginner check this guide: <a href="https://consensys.io/blog/how-to-avoid-uploading-your-private-key-to-github-approaches-to-prevent-making-your-secrets-public">How to Avoid Uploading Your Private Key to GitHub</a> and <strong>use your dev/test wallet</strong> for your projects NOT your main one.</p><p>Before deployment, we need the smart contract ABI and its bytecode. To obtain these, we have to compile the contract and extract them from the artifacts.</p><p>To compile your smart contract using the command:</p><pre>npx hardhat compile</pre><p>After compile, you should see the folder artifacts appear. Then you can see in artifacts/contracts/&lt;your_smart_contract&gt;.sol/&lt;your_smart_contract&gt;.json your contract ABI and bytecode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*-8HM_bZSI8lwNIIpc2S7Eg.png" /></figure><p>After config your hardhat, you can deploy your smart contracts using scripts with a deployment script where:</p><p>In the first part we define your own Chain:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wp36qwJTlnDsX9NbDz41QQ.png" /><figcaption>First part of deploy.ts</figcaption></figure><p>In the second part, we deploy the smart contract using the ABI and bytecode we obtained earlier:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kh88R9paNGXtQc__MyES9A.png" /><figcaption>Second part of deploy.ts</figcaption></figure><p>In the end you should have your deploy.ts like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MhhQwd5nNVsie5F5xzxs3w.png" /></figure><p>Lastly open a new terminal and deploy the smart contract in your network chain using this command.</p><pre>npx hardhat run scripts/deploy.ts --network &lt;your_chain_name&gt;</pre><p>In my case:</p><pre>npx hardhat run scripts/deploy.ts --network tutorialsworld</pre><p>In case of success you should have this message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b2JYXCwBuqhdvBr7I24B9A.png" /></figure><h4>Deploy the Smart Contract in your custom chain using Foundry</h4><p>To deploy your smart contract using Foundry, you need first of all that you had your smart contract in the folder src/your_contract.sol then try compiling your contract to make sure everything is in order.</p><pre>forge build</pre><p>If your output looks like this, the contracts successfully compiled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*j5nnY8ha9jNVHbrtA8Vd_Q.png" /></figure><p>And you should be able to get your ABI in the out/Your_Contract.sol/your_contract.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*gme18xIF0IoEDoCYNpqbQA.png" /></figure><p>Next, in the folderscript and create a file in it called Your_Contract.s.sol. This is where we will create the deployment script itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*Ec3m8M8vXiE1R26wUJYgiw.png" /></figure><p>Where you have to import your smart contract from the src folder, and then add new YourContract() (my case new AddressBook()) between of the vm.startBroadcast() and vm.stopBroadcast() inside the run function.</p><p>If you want details on what happens under the hood of the Foundry script, you can refer to this <a href="https://book.getfoundry.sh/tutorials/solidity-scripting?highlight=--broadcast#writing-the-script">guide</a>.</p><p>Lastly, before deploy you need to export your private key from <a href="https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key#:~:text=On%20the%20&#39;Account%20details&#39;%20page,private%20key%20to%20your%20clipboard.">Metamask</a> and the use this command in your terminal:</p><pre>export PRIVATE_KEY=&lt;your_private_key&gt;</pre><p>Then to deploy run the command:</p><pre>forge script script/YourContract.s.sol:YourContractScript --rpc-url &lt;your_rpc_url&gt; --private-key $PRIVATE_KEY --broadcast</pre><p>Where you can get &lt;your_rpc_url&gt; using Sagacli:</p><pre>sagacli chainlet list<br>sagacli chainlet apis &lt;your_chain_id&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G2QhH0K79Qtq9RfmSHgd9A.png" /></figure><p>So if i want to deploy in my case will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uznr2v7WtK7jP4xgBhgrUA.png" /></figure><p>And if you added the flag --broadcast you can see also this output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fB4W6EMoDTkK3sCLB-WZLQ.png" /></figure><p>Otherwise you can check your contract address in the run-latest.json inside the broadcast folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfWSZBnePs39Hm4uz1Td4w.png" /></figure><h4>Conclusion</h4><p>Congratulations! You now know how to deploy smart contracts on your custom chain built with <strong>Saga</strong>, thanks to the comprehensive insights provided in this article.</p><p>Whether you’re a beginner seeking foundational knowledge or an experienced developer aiming to enhance your skills, the step-by-step instructions offered practical guidance for deploying smart contracts using various methods, including Remix, Hardhat, and Foundry. <br>By empowering you with this knowledge, the article ensures that you can confidently navigate the complexities of smart contract deployment, making the most out of Saga’s innovative blockchain technology.</p><p>You are now well-prepared to actively participate in the thriving community of proficient developers within the Saga network. By mastering the smart contract deployment techniques outlined in this article, you can confidently engage in building a secure, efficient, and innovative blockchain environment for your projects. This newfound expertise not only enhances your skills but also enables you to collaborate effectively with fellow developers, fostering a dynamic ecosystem of innovation and growth within the Saga community.</p><p><em>If you found the article valuable and wish to offer a gesture of encouragement:</em></p><ol><li><em>Clap 50 times for this article</em></li><li><em>Leave a comment telling me what you think</em></li><li><em>Highlight the parts in this article that you resonate with</em></li></ol><h4>Further Reading</h4><ul><li><a href="https://docs.saga.xyz/introduction/pegasus-overview"><strong>Saga Docs</strong></a></li><li><a href="https://remix-ide.readthedocs.io/en/latest/"><strong>Remix Docs</strong></a></li><li><a href="https://hardhat.org/hardhat-runner/docs/getting-started#quick-start"><strong>Hardhat Docs</strong></a></li><li><a href="https://book.getfoundry.sh/"><strong>Foundry Docs</strong></a></li><li><a href="https://book.getfoundry.sh/tutorials/solidity-scripting?highlight=--broadcast#solidity-scripting"><strong>Foundry Solidity Scripting</strong></a></li><li><a href="https://viem.sh/"><strong>Viem</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acdfa1c50173" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Blockchain, Your Web3: Configuring a Personalized Web3 Experience using the power of Saga]]></title>
            <link>https://simon-digiorgio.medium.com/your-blockchain-your-web3-configuring-a-personalized-web3-experience-using-the-power-of-saga-a85bc5f561f5?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/a85bc5f561f5</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[cosmos-ecosystem]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Fri, 10 Nov 2023 18:24:04 GMT</pubDate>
            <atom:updated>2023-11-30T18:26:09.812Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*p29hOi_RLMN2nKKqLggJzA.png" /><figcaption>credit: Gencraft</figcaption></figure><ul><li><a href="#5516"><strong>Introduction</strong></a></li><li><a href="#ce1b"><strong>Launching your own Chain using SagaCli</strong></a></li><li><a href="#6dde"><strong>Connecting your own chain to a block explorer and Metamask</strong></a></li><li><a href="#7254"><strong>Connecting your own chain into your personal projects</strong></a></li></ul><h4>Introduction</h4><p>Web3 has made remarkable strides since its inception. Back in the early 2010s, creating a Bitcoin wallet often required navigating a Command-Line Interface (CLI). Even in the present day, it can take seasoned cryptocurrency teams several months to successfully launch their own blockchain. However, thanks to Saga, launching your very own blockchain is now achievable in less than 10 minutes!</p><p>This will be a article series covering:</p><ul><li>How configuring a Personalized Web3 Experience using the power of Saga (this article)</li><li><a href="https://medium.com/@simon-digiorgio/a-deep-dive-into-smart-contract-deployment-on-your-custom-chain-built-on-saga-acdfa1c50173">How deploy your smart contract in your chain.</a></li><li><a href="https://simon-digiorgio.medium.com/building-your-own-faucet-for-your-own-testnet-chain-built-on-saga-a2a27b6e266f">How to create a faucet for your chain</a></li></ul><p>In this guide, we will demonstrate how to configure your own blockchain built using <strong>Saga</strong> within your web3 decentralized application (dApp).</p><h4>Launching your own Chain using SagaCli</h4><p>While Saga already provides excellent <a href="https://docs.saga.xyz/introduction/cassiopeia-overview"><strong>documentation</strong></a> for exploration, I’ll briefly walk you through what I did to build my chain.</p><p>After <a href="https://docs.saga.xyz/getting-started/quickstart-guide#1.-download-and-install-sagacli">downloading</a> and <a href="https://docs.saga.xyz/getting-started/quickstart-guide#2.-configure-sagacli">configuring</a> the <strong>SagaCLI</strong>, I utilized the following command:</p><pre>sagacli chainlet launch SagaOS 0.5.2 tutorialsworld \<br>--genesis-account 0x8D37cb3624e1CB8480DceCC7884330a0449Dd9f0:10000000000 --denom tworld --fees 2500upsaga</pre><p>Where:</p><ul><li>sagacli chainlet launch is the base command to launch chainlet</li><li>SagaOS 0.5.2 is the chainlet type and stack version to launch</li><li>tutorialsworld is your blockchain name</li><li>--genesis-account &lt;address&gt;:&lt;num_of_tokens&gt;The genesis-account flag consists of your EVM address and the desired number of full tokens in your account, separated by a colon “:”. You can directly copy the address from your Metamask wallet.</li><li>--denom <strong>tworld</strong> is the currency symbol you’ll create. (I suggest that should be between 2 and 6 characters).</li></ul><p>I have included an image below for better clarity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfoO5WECms_zn080qNhS3A.png" /></figure><p>Ultimately, you should achieve all of this once you have successfully launched your own chain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYOucK_RM8swt5o0J1Q3bg.png" /></figure><p>Following these steps, you can verify your setup by executing the command sagacli chainlet list to obtain your ChainId. Then, use the command sagacli chainlet apis &lt;your_chainId&gt; to retrieve all the endpoints associated with your ChainId.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G2QhH0K79Qtq9RfmSHgd9A.png" /></figure><p>In this case we have:</p><ul><li>ws (websocket): tutorialsworld-1699000173917438–1.ws.testnet-sp1.sagarpc.io</li><li>explorer: tutorialsworld-1699000173917438–1.jsonrpc.testnet-sp1.sagarpc.io</li><li>jsonrpc: tutorialsworld-1699000173917438–1.testnet-sp1.sagaexplorer.io</li></ul><p>Copy and paste the explorer endpoint into your web browser (in this case <a href="https://tutorialsworld-1699000173917438-1.testnet-sp1.sagaexplorer.io/">tutorialsworld-1699000173917438–1.testnet-sp1.sagaexplorer.io</a>). <br>Now, you can observe real-time updates of all the blocks being produced on your own chain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_D78bXHjiX-cjjGCBaTMDQ.png" /></figure><h4>Connecting your own chain to a block explorer and Metamask</h4><p>There are two ways to add your chain to Metamask:</p><ul><li>You can do it directly from the explorer</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9aqdSt7S1mRZWwtaRWyvQQ.png" /></figure><ul><li>Manually add your chain in the Metamask settings</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZPCRqczHGJoKbw2NUMa4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4U-N1f1FRGGAr5EsJxsv5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5m5TWy9NjjgrYWkmExp_9A.png" /></figure><h4>Connecting your own chain into your personal projects</h4><p>Now that we have everything we need, you can connect your own chain to any project you have built.</p><p>I am going to use one of my personal project which is a simple “AddressBook” (<a href="https://github.com/chefleo/multicallAddressBook/tree/saga">github saga branch</a>) and I’m going to explain how I configured my project to have access to my chain.</p><p>If you want to go into detail about this project, you can refer to this <a href="https://medium.com/coinsbench/optimizing-smart-contract-interactions-a-guide-to-multi-call-integration-in-web3-front-end-dapp-936331156b57">article</a>. Essentially, you need to know that in this project, we are going to use:</p><ul><li><a href="https://docs.walletconnect.com/web3modal/react/about"><strong>WalletConnect / WebModal V3</strong></a>: for wallet connectivity</li><li><a href="https://wagmi.sh/"><strong>Wagmi (Viem version)</strong></a>: for read and write call smart contract.</li></ul><p>You can also faucet some of mine <a href="https://multicall-address-book-git-saga-chefleo.vercel.app/faucet"><strong>TWorld</strong></a> token and enjoy the <a href="https://multicall-address-book-git-saga-chefleo.vercel.app/"><strong>Live Demo</strong></a> of the dApp.</p><p>To configure your dApp, set up the following configuration in your _app.tsx file (if you&#39;re using Next.js) or main.tsx file (if you&#39;re using Vite, as in this case). Ensure that all functions are called outside the App component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vekYKx3KXW7_k9TJYqOG6w.png" /></figure><p>But, most importantly, if you want to use your chain in your dApp, you need to apply this configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RhgsWxxlCH_vtTiUcpkuRw.png" /></figure><p>Then add your chain to configureChains:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kJpL7jUqXMpfSTByE2ZWjA.png" /></figure><p>In the end you should have your file _app.tsx or main.tsx like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b10713439e7a8249bb63b48c23742687/href">https://medium.com/media/b10713439e7a8249bb63b48c23742687/href</a></iframe><p>If everything is configured correctly, you should be able to connect your wallet to the dApp and see that your dApp network is <strong>your own chain</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*swX40kXQkJRzJbOSCMxCnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sj_M_DI4PK8GfU7OVTu5og.png" /></figure><h4>Conclusion</h4><p>In this guide, we’ve covered the essential steps to configure and connect your own blockchain chain within your web3 decentralized application (dApp). <br>Starting from setting up Saga and utilizing the <strong>SagaCLI</strong> for chain creation, to integrating your chain with a block explorer and Metamask, you now have the knowledge to bring your personal chain to life.</p><p>By following the provided instructions and ensuring correct configuration, you should be able to seamlessly connect your own chain to your dApp.</p><p>This empowers you to take control of your blockchain project and leverage it for your specific needs. With these insights, you’re well on your way to realizing the full potential of your decentralized applications.</p><p><em>If you found the article valuable and wish to offer a gesture of encouragement:</em></p><ol><li><em>Clap 50 times for this article</em></li><li><em>Leave a comment telling me what you think</em></li><li><em>Highlight the parts in this article that you resonate with</em></li></ol><h3>Further Reading</h3><ul><li><a href="https://docs.saga.xyz/introduction/pegasus-overview"><strong>Saga Docs</strong></a></li><li><a href="https://wagmi.sh/"><strong>Wagmi Docs</strong></a></li><li><a href="https://viem.sh/"><strong>Viem</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a85bc5f561f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Smart Contract Interactions: A Guide to Multi Call integration in Web3 Front-End DApp]]></title>
            <link>https://coinsbench.com/optimizing-smart-contract-interactions-a-guide-to-multi-call-integration-in-web3-front-end-dapp-936331156b57?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/936331156b57</guid>
            <category><![CDATA[onchain]]></category>
            <category><![CDATA[viem]]></category>
            <category><![CDATA[coinbase-wallet]]></category>
            <category><![CDATA[base]]></category>
            <category><![CDATA[wagmi]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Mon, 16 Oct 2023 19:25:54 GMT</pubDate>
            <atom:updated>2023-10-25T14:11:37.947Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWMB_zABt7EAAPTQUhdx3A.png" /><figcaption>Credits: Unsplash -&gt; <a href="https://unsplash.com/@dvlden">Nenad Novaković</a></figcaption></figure><p>In Ethereum and various other blockchain networks, engaging with smart contracts often proves to be both resource-intensive and expensive.</p><p>Every transaction or contract interaction results in a gas fee, and executing numerous calls individually can swiftly accumulate significant costs. Fortunately, the solution lies in the innovative concept of <strong>Multi Call.</strong></p><p>Multi Call stands as a strategic approach enabling the bundling of numerous contract calls into a single transaction. This method drastically curtails gas expenses, boosting the efficiency of our decentralized applications (dApps). By consolidating multiple calls, we eliminate the unnecessary overhead linked with executing each call independently. As a result, users can preserve substantial funds when utilizing our smart contracts, making their interactions with blockchain technology more cost-effective and user-friendly.</p><p>In this <strong>guide</strong>, we’ll explore the implementation of Multi Call in a Web3 dApp, utilizing a <a href="https://github.com/chefleo/multicallAddressBook"><strong>simple Address Book</strong></a><strong> </strong>project to effectively illustrate the concept.</p><p><em>This smart contract is for learning and entertainment purposes only. The address book solidity smart contract code has not been audited. Use at your own risk.</em></p><p>In this project we are going to use:</p><ul><li><a href="https://docs.walletconnect.com/web3modal/react/about"><strong>WalletConnect / WebModal V3</strong></a>: for wallet connectivity</li><li><a href="https://wagmi.sh/"><strong>Wagmi (Viem version)</strong></a>: for read and write call smart contract (which include multicall) from our front-end dApp</li></ul><h4>The smart contract</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Brox6CSyqHLIAEHt8AGBSw.png" /><figcaption>contract/AddressBook.sol</figcaption></figure><p>There is nothing special about this contract, it allows one to save a list of Ethereum account address’s to the blockchain with an alias name. However it also implemented the ability to be able to add multiple contacts with only a single transaction that save gas fees (multicall).</p><p>To implement multicall you can add this function in your smart contract:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zvikp0PMS8IYd4JHyOFCKw.png" /><figcaption>From: <a href="https://solidity-by-example.org/app/multi-delegatecall/">https://solidity-by-example.org/app/multi-delegatecall/</a></figcaption></figure><p>Or simply imported from Openzeppelin like in this case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TR9iCvUN_L0E8olDg57Htg.png" /></figure><h4>How multicall works?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_iJFOUHD02oFlx0DxIEEQQ.png" /></figure><p>Essentially, you provide the desired functions as an array of encoded data (bytes[] memory data). <br>A <strong>for</strong> loop iterates through each data element (in this project, likely invoking the <strong>addContacts</strong> function multiple times). Each iteration involves a <strong>delegatecall</strong> to the same address (in this case, the <strong>AddressBook</strong> smart contract). <br>This call returns two outputs: a boolean <strong>ok</strong> indicating the success or failure status of the function, and the result (bytes memory res) of the function call.</p><p>In Solidity, the <strong>delegatecall</strong> function is a low-level operation that enables a contract to delegate its invocation to another contract, essentially borrowing the functionality of the target contract. Importantly, this process maintains the calling contract&#39;s storage and context, allowing seamless interaction between contracts while preserving the integrity of their individual states.</p><h4>The front-end dApp</h4><p>To try the demo, navigate to: <a href="https://multicall-address-book.vercel.app/">https://multicall-address-book.vercel.app/</a></p><p>We’ll begin with a single addContacts transaction.</p><p>First and foremost, connect a wallet of your choice. <br>In this instance, I used Coinbase Wallet, but feel free to use MetaMask or any other compatible wallet. (1,2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*NkZRWWk-YAequyYZLAIAoA.png" /></figure><p>Next, fill the address input with an Ethereum address and provide a name of your choice (3). <br>Then, click on “Add Contact” and confirm the request (4,5).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o71j5UgQEvkpiTBdGJLAmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FoQ0KiGyNXczHu8LbRP16Q.png" /></figure><p>If everything is successful, you’ll be able to see the newly added contact displayed on the bottom left corner. (6)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPE7ZnrmIWrNwstgT2Ko5w.png" /></figure><p>Additionally, if you navigate to the <a href="https://goerli.basescan.org/address/0x41f01E98AE44C4b1DA0522377BDcF7A51F4deA0A"><strong>contract address on Goerli Etherscan</strong></a>, you can view your transaction record. (7)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hed-s5vs3RnxpuCw3KOLtA.png" /></figure><p>From a code perspective, this single write call is executed using the Wagmi hook, utilizing <strong>usePrepareContractWrite</strong> and <strong>useContractWrite</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_frvDllTFpeWXt3543OO1g.png" /><figcaption>src/App.tsx</figcaption></figure><p>To call the multicall function, we first need the bytecode of the desired functions to be called. In this case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSmcuEwaL0S9l0KeDGR_OQ.png" /></figure><ul><li>addContact(“<strong>0x033…f7D1</strong>”, “<strong>John</strong>”)</li><li>addContact(“<strong>0x04B…B17F</strong>”, “<strong>Tom</strong>”)</li></ul><p>To obtain the bytecode, we can use the <a href="https://viem.sh/docs/contract/encodeFunctionData.html#encodefunctiondata"><strong>encodeFunctionData</strong></a> function (from <strong>Viem</strong>), which encodes the function name and parameters into an ABI encoded value. This encoded value includes the 4-byte selector and the function arguments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L5PRRCuwDOjk__qMqBKkxg.png" /><figcaption>src/App.tsx</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j75vuRFEtLBZbtIGWob6ig.png" /><figcaption>If you console.log <strong>argsBytes</strong>, you can observe it in the browser’s console output.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iowkjRua0KY90bEkPVC9gA.png" /><figcaption>You can observe how the <strong>multicall</strong> will work in this specific scenario.</figcaption></figure><p>Now that we have everything, we can now prepare the contract write for the multicall and execute it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KXbq8kIWGC0Ih4OVm2_c6w.png" /><figcaption>src/App.tsx</figcaption></figure><p>And from app perspective will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lRh2w6BdxFccj7pmQA8sug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E_bBu6XrGU8QFUl-kPZx8g.png" /><figcaption>After you confirm the request for <strong>multicall</strong> addContact, you’ll see the contacts added in your addressBook.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4LEF8eKhj2-mScxn2xSPiw.png" /><figcaption>And if you navigate to the <a href="https://goerli.basescan.org/address/0x41f01E98AE44C4b1DA0522377BDcF7A51F4deA0A"><strong>Goerli Etherscan</strong></a>, you can view your <strong>Multicall</strong> transaction record.</figcaption></figure><h4>Conclusion</h4><p>Congratulations! You now know how to effectively use <strong>Multicall</strong> in your front-end dApp, this potent technique for optimizing contract interactions on the Ethereum blockchain. By consolidating multiple calls into a single transaction, you can dramatically slash gas costs, boost scalability, and elevate the overall user experience of your dApps.</p><p>Implementing <strong>Multicall</strong> demands a thoughtful strategy, a deep understanding of your dApp’s requirements, and meticulous design of the aggregation logic. However, the effort invested unquestionably pays off in the form of the benefits it delivers.</p><p><em>If you found the article valuable and wish to offer a gesture of encouragement:</em></p><ol><li><em>Clap 50 times for this article</em></li><li><em>Leave a comment telling me what you think</em></li><li><em>Highlight the parts in this article that you resonate with</em></li></ol><h4>Further Reading</h4><ul><li><a href="https://www.youtube.com/watch?v=NkTWU6tc9WU&amp;t=217s&amp;ab_channel=SmartContractProgrammer">Multi Delegatecall | Solidity 0.8</a><strong> </strong>by <br><a href="https://www.smartcontract.engineer/"><strong>Smart Contract Programmer</strong></a></li><li><a href="https://solidity-by-example.org/app/multi-delegatecall/">Multi Delegatecall</a> of Solidity by example by <a href="https://www.smartcontract.engineer/"><strong>Smart Contract Programmer</strong></a></li><li><a href="https://medium.com/@solidity101/100daysofsolidity-064-multi-call-in-solidity-efficient-contract-interaction-20e7202bc8c8">#100DaysOfSolidity #064 Multi Call in Solidity: Efficient Contract Interaction 🚀</a> by<strong> </strong><a href="https://medium.com/@solidity101"><strong>Solidity Academy</strong></a></li><li><a href="https://medium.com/@ajaotosinserah/mastering-delegatecall-in-solidity-a-comprehensive-guide-with-evm-walkthrough-6ddf027175c7">Mastering Delegatecall in Solidity: A Comprehensive Guide with EVM Walkthrough</a> by <a href="https://medium.com/@ajaotosinserah"><strong>Oluwatosin Serah</strong></a></li><li><a href="https://medium.com/coinmonks/delegatecall-calling-another-contract-function-in-solidity-b579f804178c">DelegateCall: Calling Another Contract Function in Solidity</a> by <a href="https://medium.com/@zerofruit-web3"><strong>zeroFruit</strong></a></li><li><a href="https://cryptomarketpool.com/address-book-solidity-smart-contract/"><strong>Crypto Market Pool</strong></a></li><li><a href="https://docs.walletconnect.com/2.0/web/web3modal/react/wagmi/installation"><strong>WalletConnect</strong></a> (docs)</li><li><a href="https://wagmi.sh/"><strong>Wagmi</strong></a><strong> </strong>(docs)</li><li><a href="https://viem.sh/"><strong>Viem</strong></a></li><li><a href="https://www.flaticon.com/free-icon/binary_1822940?term=binary&amp;page=1&amp;position=3&amp;origin=search&amp;related_id=1822940"><strong>Binary icon by freepik</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=936331156b57" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/optimizing-smart-contract-interactions-a-guide-to-multi-call-integration-in-web3-front-end-dapp-936331156b57">Optimizing Smart Contract Interactions: A Guide to Multi Call integration in Web3 Front-End DApp</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building on Base (Goerli) with CoinbaseWallet SDK and Wagmi (Viem version)]]></title>
            <link>https://coinsbench.com/building-on-base-goerli-with-coinbasewallet-sdk-and-wagmi-viem-version-6cf2a0f95dcf?source=rss-8bab071ce786------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cf2a0f95dcf</guid>
            <category><![CDATA[base]]></category>
            <category><![CDATA[wagmi]]></category>
            <category><![CDATA[onchain]]></category>
            <category><![CDATA[coinbase]]></category>
            <category><![CDATA[viem]]></category>
            <dc:creator><![CDATA[Leonardo Simone Digiorgio]]></dc:creator>
            <pubDate>Fri, 14 Jul 2023 08:05:10 GMT</pubDate>
            <atom:updated>2023-11-23T08:09:29.470Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UjW8OVwX_ZIuASb5HDNIhw.png" /></figure><ul><li><a href="#bb44"><strong>Introduction</strong></a></li><li><a href="#de2a"><strong>The Smart Contract</strong></a></li><li><a href="#4bc2"><strong>Deploying on Base Goerli</strong></a></li><li><a href="#bfcf"><strong>Front End: Configuration of WalletConnect and Wagmi</strong></a></li><li><a href="#84c3"><strong>Wagmi</strong></a></li><li><a href="#fcd5"><strong>useContractRead</strong></a></li><li><a href="#1f55"><strong>usePrepareContractWrite and useContractWrite</strong></a></li><li><a href="#d7cb"><strong>useWaitForTransaction</strong></a></li></ul><h4><strong>Introduction</strong></h4><p><em>Connecting applications to users and seamlessly connecting to Ethereum’s ecosystem is central to the ever-evolving decentralized applications.<br> This guide explores the powerful combination of </em><strong><em>Coinbase Wallet SDK</em></strong><em> and </em><strong><em>Wagmi</em></strong><em>, a collection of React Hooks, to simplify and enhance the development process.</em></p><p><strong>Base</strong> is a secure, low-cost, developer-friendly Ethereum L2 built to bring the next billion users to web3.<br>The <strong>Coinbase Wallet SDK</strong>, an open source software development kit (SDK), enables seamless integration with millions of related users. <br>Meanwhile, <strong>Wagmi</strong> provides a comprehensive set of React Hooks, which enable various Ethereum transactions such as wallet transactions, ENS and balance information exposure, message signing, contract transactions, and more. <br>This integration offers developers the convenience of caching, request deduplication, and persistence, empowering them to build on a solid foundation while expanding their reach in the Ethereum ecosystem.</p><p><em>This article offers a guide on how to deploy a smart contract on </em><strong><em>Base Goerli </em></strong><em>and how to incorporate </em><strong>Coinbase Wallet SDK<em> </em></strong><em>and</em><strong><em> Wagmi </em></strong><em>into a Next.js application.</em></p><p>In this article will be use as example my BuyMeACoffee project</p><ul><li>The <a href="https://github.com/chefleo/BuyMeACoffee_smart_contract/tree/main"><strong>Smart Contract</strong></a> used</li><li>The <a href="https://github.com/chefleo/BuyMeACoffee_front_end"><strong>Front-end</strong></a> where we will implement Coinbase Wallet SDK and Wagmi (on CoinbaseWallet branch)</li></ul><h3>The Smart Contract</h3><p>First, check out the smart contract used in this project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df7ee5ecb09e85360aab57a66229300c/href">https://medium.com/media/df7ee5ecb09e85360aab57a66229300c/href</a></iframe><p>In short, the <strong>BuyMeACoffee</strong> contract allows users to buy a coffee by sending Ether to the contract owner along with a personalized message. It stores the received memos and allows the owner to withdraw the accumulated funds.</p><h4>Deploying on Base Goerli</h4><p>Before deploying this smart contract, it is necessary to:</p><ul><li>Download <a href="https://chrome.google.com/webstore/detail/coinbase-wallet-extension/hnfanknocfeofbddgcijnmhnfnkdnaad?hl=en"><strong>Coinbase Wallet extension</strong></a> and create a wallet (if you don’t have a wallet)</li><li>Enable testnets in your wallet through <a href="https://docs.cloud.coinbase.com/wallet-sdk/docs/developer-settings"><strong>Developer Settings</strong></a></li><li>Get <a href="https://coinbase.com/faucets/base-ethereum-goerli-faucet"><strong>Base Goerli faucet</strong></a></li></ul><p><strong>Using Remix</strong> <a href="https://remix.ethereum.org/"><strong><br>Remix</strong></a> is an online IDE that you can use to rapidly develop and deploy smart contracts.</p><p><strong>Remix</strong> contains a simulation of a blockchain that you can use to rapidly deploy and test your contracts. This simulation only exists within your browser, so you can’t share it with others or use external tools or a front end to interact with it. However, you can also deploy to a variety of testnets from within Remix. Doing so will allow you to share your contract with others, at the cost of making it public.</p><p>First of all open <a href="https://remix.ethereum.org/"><strong>Remix</strong></a><strong> </strong>and create a new file called BuyMeACoffee.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*ol_G8TINbXr928W8GkH2jg.png" /></figure><p>Then copy the smart contract above (1), navigate to Solidity compile (2) and compile BuyMeACoffee.sol (3). Now you have access to the <a href="#fbba">ABI</a> which it’s useful later on when we are talking on the front-end part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOXiGZK2ZE_EBDNnx8YQUQ.png" /></figure><p>Then:</p><ul><li>Navigate to “Deploy and run transaction” (1) &gt; Environment (2).</li><li>Click on Injected Provider — Coinbase, which should prompt the Coinbase extension to appear (3).</li><li>Once connected, switch from the mainnet (to avoid using real Ethereum) to BASE Gorli. To do this, click on the second icon located at the top right (4), and then select Base Gorli (5).</li></ul><blockquote>⚠️ Note: During this stage, it is possible to encounter connectivity issues with Coinbase Wallet. You may experience difficulties connecting, or even if you manage to connect, the wallet might display that it is not connected. If that happened, please copy and save your <a href="https://help.coinbase.com/en/wallet/browser-extension/coinbase-wallet-extension">recovery phrase</a>. Then, sign out and sign in again using your recovery phrase, and attempt the process once more.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Fa9crZBlnnp6MWIQmLKXA.png" /></figure><p>In the end, if you see the screen displaying the network as 84531 (Base Gorli network) and you can identify your account, you can be assured that you are on the right track (6).</p><p>You can proceed with the deployment of your smart contract by clicking the “Deploy” button (7). Once you’ve done that, you should observe the following information displayed at the bottom (8).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*QJzoCieW7NyjpV4IPFW4sA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lxE0gCfSoMvL2GiT7QT77w.png" /></figure><p>Now you have:</p><ul><li>The <strong>address</strong> of smart contract (you can see in under Deployed Contracts)</li><li>The <strong>ABI</strong> of smart contract</li></ul><h4>Front End: Configuration of WalletConnect and Wagmi</h4><p><strong>Obtain Project ID</strong><br>To install <strong>Coinbase Wallet SDK</strong> and <strong>Wagmi</strong>, you need to obtain a <strong>Project ID</strong> from <a href="https://www.infura.io/">Infura</a> by signing in or signing up and creating (or using an existing) project.<br>Once you have the <strong>Project ID</strong>, you can add it to your <strong>.env</strong> file and <strong>next.config.js</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77SELswpIifH9MATlkmfXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyK22rXXKfxsUCYAk7iLbg.png" /></figure><p>Put the <strong>Project ID </strong>into<strong> </strong>.env</p><pre>INFURA_ID=&lt;YOUR_PROJECT_ID&gt;</pre><p>Configure the <strong>next.config.js<em> </em></strong>for get access to process.env.WALLET_CONNECT_PROJECT_ID in your code</p><pre>/** @type {import(&#39;next&#39;).NextConfig} */<br>const nextConfig = {<br>  reactStrictMode: true,<br>  env: {<br>    INFURA_ID: process.env.INFURA_ID,<br>  },<br>}<br><br>module.exports = nextConfig</pre><p><strong>Add Packages<br></strong>In your terminal, run the command below to add the needed packages:</p><pre>npm install wagmi viem</pre><p><strong>Change address contract with your deployed address contract<br></strong>In the utils/contractInfo.js file, you can modify the contractAddress variable with the address of your deployed contract. Additionally, if you have made any changes to the BuyMeACoffee.sol file, you need to copy the updated ABI from Remix and replace the existing BuyMeACoffeeCustomError.json file with the new ABI. However, if you haven&#39;t made any changes to BuyMeACoffee.sol, you can continue using the current ABI.</p><p><strong>Config Wagmi<br></strong>Lastly, prepare the WagmiConfig component, which handles the configuration for all hooks with CoinbaseWalletConnector that supports connecting with Coinbase Wallet using the <a href="https://docs.cloud.coinbase.com/wallet-sdk/docs">Coinbase Wallet SDK</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb4e576a455c5ff6bc198bfacee9da54/href">https://medium.com/media/bb4e576a455c5ff6bc198bfacee9da54/href</a></iframe><h3>Wagmi</h3><p><strong>Wagmi</strong> is a collection of React Hooks containing everything you need to start working with Ethereum.<br><strong>Wagmi</strong> makes it easy to “Connect Wallet,” display ENS and balance information, sign messages, interact with contracts, and much more.</p><h3>Wagmi Hooks used in the project BuyMeACoffee</h3><ul><li><strong>useConnect</strong></li><li><strong>useDisconnect</strong></li><li><strong>useAccount</strong></li><li><strong>useNetwork</strong></li><li><strong>useSwitchNetwork</strong></li><li><strong>useContractRead</strong></li><li><strong>usePrepareContractWrite</strong></li><li><strong>useContractWrite</strong></li><li><strong>useWaitForTransaction</strong></li></ul><h4><strong>useConnect and useDisconnect</strong></h4><p>We use <strong>useConnect</strong> hook for connecting to account with connectors and <strong>useDisconnect</strong> hook for disconnecting the connected account.</p><p>Here we are using the<strong> Coinbase SDK</strong> connector for connecting wallet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6338d3a1695dbee01137afc05f521518/href">https://medium.com/media/6338d3a1695dbee01137afc05f521518/href</a></iframe><h4>useAccount</h4><p>Hook for accessing account data. In this scenario, we utilize the “<strong>isConnected</strong>” value to determine the user’s login status. If the user is logged in, the form enables them to purchase a coffee by sending Ether to the contract owner, accompanied by a personalized message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sj3AEZftCB7lRJbXRqKW9Q.png" /><figcaption>Main.js</figcaption></figure><p>Here we used the useState variable connectionStat to avoid “<a href="https://stackoverflow.com/questions/71791251/in-nextjs-warning-expected-server-html-to-contain-a-matching-div-in-div">NEXTJS Warning: Expected server HTML to contain a matching &lt;div&gt; in &lt;div&gt;</a>”</p><h4>useNetwork and useSwitchNetwork</h4><p>we used <strong>useNetwork </strong>hook for accessing network data, such as current connected chain and <strong>useSwitchNetwork </strong>hook to switch network in case the user change the network (using useEffect).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a233ad7439069b868c287e642e188a25/href">https://medium.com/media/a233ad7439069b868c287e642e188a25/href</a></iframe><h4>useContractRead</h4><p>Hook for calling a read method on a Contract.</p><blockquote><em>A “read-only” function (constant function) on a Solidity contract is denoted by a </em><em>view or </em><em>pure keyword. They can only read the state of the contract, and cannot make any changes to it. Since read-only methods do not change the state of the contract, they do not require any gas to be executed, and can be called by any user without the need to pay for gas.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*trVIC5P116X2YgGKZy51tA.png" /><figcaption><strong>Typical usage of useContractRead</strong></figcaption></figure><p>Which <strong>address</strong> is the contract address, <strong>abi</strong> is the ABI of the contract (see below), <strong>functionName</strong> is the function <strong>view </strong>of the contract and lastly <strong>args</strong> (if necessary) are the arguments of the contract.</p><blockquote><em>An Application Binary Interface (</em><strong><em>ABI</em></strong><em>) for a smart contract is like a mediator that helps the contract communicate and work together with external applications and other smart contracts in the Web3 environment.</em></blockquote><p>In our scenario:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea0174052b34e4ae7622fb2611b9f2ef/href">https://medium.com/media/ea0174052b34e4ae7622fb2611b9f2ef/href</a></iframe><p>Here get the data that we rename <strong>memos</strong> through <strong>READ </strong>call method “getMemos” which retrieve all the memos received and stored on the blockchain.</p><p>The variable “<strong>isFetched</strong>” is initially set to false and becomes true once the <strong>READ</strong> operation is completed.<br>We use “<strong>isFetched</strong>” as a conditional statement, and when it evaluates to true, the following code will be rendered.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9514e71f6f78aa0d82f4f8f05375eb17/href">https://medium.com/media/9514e71f6f78aa0d82f4f8f05375eb17/href</a></iframe><p>The refetch function (renamed <strong>refetchMemos</strong>) is a function that simply re-run the <strong>READ </strong>call method “getMemos”<br>We will see <strong>refetchMemos </strong>later when on the section of <strong>useWaitForTransaction</strong></p><h4>usePrepareContractWrite and useContractWrite</h4><blockquote><em>The </em><strong><em>Prepare Hooks</em></strong><em> in Wagmi improve user experience by allowing asynchronous work to be performed ahead of time, before an event is initiated by the user.</em></blockquote><p>This reduces potential delays and helps avoid UX related issues.</p><p>The Prepare Hooks generate the necessary parameters for their paired hooks, such as <strong>useSendTransaction</strong> or <strong>useContractWrite</strong>, which previously performed long-running asynchronous tasks using the <strong>ethers signer.sendTransaction</strong> function.</p><h4>Slow TTOW (Time To Open Wallet)</h4><p>Slow TTOW (Time To Open Wallet) is a problem caused by performing long-running asynchronous tasks between a user interaction and opening the wallet.</p><p>This can lead to a delay and confuse the user, especially under slow network conditions.</p><p>Here the <a href="https://wagmi.sh/react/prepare-hooks#slow-ttow-time-to-open-wallet"><strong>link</strong></a> where you can find more details and a video demonstrating the difference between a slow TTOW and a fast TTOW.</p><h4>Usage of usePrepareContractWrite and useContractWrite</h4><p>The configuration needed for the hook useContractWrite is like useContractRead</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db8357bf96851cd40c0409da1dce082d/href">https://medium.com/media/db8357bf96851cd40c0409da1dce082d/href</a></iframe><p>Excluding the properties we already explained in the context of <strong>useContractRead</strong> (address, abi, and functionName), the remaining properties in the code are:</p><ol><li><strong>Args: </strong>Arguments to pass to function call, if you remember the smart contract the function is:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*Etr1zhgNWFVwTqvN2-EXSg.png" /></figure><p>2.<strong> Enabled</strong> is set to false to disable this query from automatically running and becomes true once the name and the message variables are NOT empty. <strong>Enabled</strong> property is used to avoid situation like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*QibE4YpXWr9EDUuaGsgkQg.png" /></figure><p>3.<strong> Value: </strong>Value in wei sent with this transaction (msg.value in Solidity)</p><p>3.<strong> onSuccess: </strong>It is a callback function that will be executed when the function call is successful. In this case, it logs a success message to the console, including the data parameter that contains any returned data from the successful function call.</p><blockquote><em>You can also find the </em><strong><em>onSuccess</em></strong><em> callback in various other hooks provided by Wagmi. This callback function allows you to perform specific actions or manipulate data when a function or action succeeds. Using the </em><strong><em>onSuccess</em></strong><em> callback allows you to modify the hook’s behavior and respond accordingly.</em></blockquote><p>After that, insert the config inside <strong>useContractWrite ​</strong>which is hook for calling a write method on a Contract (in this case the buyMeACoffee method).</p><blockquote><em>A “write” function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a </em><a href="https://viem.sh/docs/glossary/terms.html"><em>Transaction</em></a><em> is needed to be broadcast in order to change the state.</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de40b889ab6ed0f1c9d3d3a946c6b400/href">https://medium.com/media/de40b889ab6ed0f1c9d3d3a946c6b400/href</a></iframe><p>Which { write: <strong>buyMeACoffee</strong> } can be { write: <strong>&lt;name_of_the_function&gt;</strong> }.</p><p>One of the return values of the hook is <strong>write</strong>, which is a function that invokes the function of the smart contract.</p><p>{ data: <strong>dataBuyMeACoffee</strong> } represent the <a href="https://viem.sh/docs/glossary/terms.html#hash">Transaction Hash</a> (if is successful) of the <strong>write</strong> function.</p><p>And to activate the <strong>write</strong> function, it can be placed inside a button or another function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bca3466dfd73f8496c64b04a3c13d33/href">https://medium.com/media/6bca3466dfd73f8496c64b04a3c13d33/href</a></iframe><h4>useWaitForTransaction</h4><p>Waits for the <a href="https://viem.sh/docs/glossary/terms.html#transaction">Transaction</a> to be included on a <a href="https://viem.sh/docs/glossary/terms.html#block">Block</a> (one confirmation), and then returns the <a href="https://viem.sh/docs/glossary/terms.html#transaction-receipt">Transaction Receipt</a>. If the Transaction reverts, then the action will throw an error.</p><p>In this scenario, we utilize the <strong>useWaitForTransaction</strong> hook to update the memos displayed on the website. This is achieved by re-running the getMemos function from the useContractRead hook (when is successful).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5015e82c7f2574470f51ff6b07db4bc/href">https://medium.com/media/d5015e82c7f2574470f51ff6b07db4bc/href</a></iframe><p>We use the enabled parameter of the <strong>useWaitForTransaction</strong> hook to wait for the transaction hash generated by the <strong>useContractWrite</strong> hook. When the write function (in this case buyMeACoffee) is called and executed successfully, the <strong>useWaitForTransaction</strong> hook executes and waits for the transaction to be <strong>confirmed in a block</strong>.<br>Once confirmed, the <strong>refetchMemos</strong> function from the <strong>useContractRead</strong> hook is triggered to update the memos.</p><h3>Conclusion</h3><p>In summary, this article provides guidance on integrating <strong>Coinbase SDK</strong> and <strong>Wagmi</strong> into a Next.js application, using the BuyMeACoffee project as an example.</p><p>The seamless integration provided by the <strong>Coinbase Wallet SDK</strong> enables applications to connect with millions of Coinbase Wallet users effortlessly. With access to the <strong>Base Goerli</strong> network, developers can take advantage of a robust and reliable infrastructure for testing and deploying their Ethereum-based applications.</p><p><strong>Wagmi</strong> provides a collection of React Hooks that facilitate Ethereum-related development tasks. These hooks provide important functionality such as wallet integration, display of ENS and balance information, message signing, and contract negotiation.</p><p>Understanding the capabilities of <strong>Base Goerli,</strong> <strong>Coinbase SDK</strong> and <strong>Wagmi</strong>, developers can leverage their capabilities to create simple and efficient Web3 applications. These tools help grow and sustain Web3 development, and empower developers to make the most of blockchain technology.</p><p><em>If you found the article valuable and wish to offer a gesture of encouragement:</em></p><ol><li><em>Clap 50 times for this article</em></li><li><em>Leave a comment telling me what you think</em></li><li><em>Highlight the parts in this article that you resonate with</em></li></ol><h3>Further Reading</h3><ul><li><a href="https://wagmi.sh/"><strong>Wagmi</strong></a><strong> </strong>(docs)</li><li><a href="https://viem.sh/"><strong>Viem</strong></a></li><li><a href="https://docs.base.org/"><strong>Base</strong></a></li><li><a href="https://docs.cloud.coinbase.com/wallet-sdk/docs/welcome"><strong>CoinBase SDK</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cf2a0f95dcf" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/building-on-base-goerli-with-coinbasewallet-sdk-and-wagmi-viem-version-6cf2a0f95dcf">Building on Base (Goerli) with CoinbaseWallet SDK and Wagmi (Viem version)</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>