<?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 Vansh Wassan on Medium]]></title>
        <description><![CDATA[Stories by Vansh Wassan on Medium]]></description>
        <link>https://medium.com/@vanshwassan?source=rss-82dd8c0acd3b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GDAM0vUPJf6epJPrHDjrUQ@2x.jpeg</url>
            <title>Stories by Vansh Wassan on Medium</title>
            <link>https://medium.com/@vanshwassan?source=rss-82dd8c0acd3b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:50:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vanshwassan/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[How to Use First-Party Data Feeds in Your Smart Contracts]]></title>
            <link>https://medium.com/api3/how-to-use-first-party-data-feeds-in-your-smart-contracts-257e187ffc7f?source=rss-82dd8c0acd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/257e187ffc7f</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Vansh Wassan]]></dc:creator>
            <pubDate>Tue, 22 Aug 2023 15:29:19 GMT</pubDate>
            <atom:updated>2023-08-22T15:29:19.652Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Using API3’s Managed and Self-funded dAPIs in your Solidity Smart Contracts</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tjluA8r9bDMdlk3lRUKXJQ.png" /></figure><p>It is crucial for dApps interacting with off-chain data to have access to secure oracles. With the coming new ZK chains like Polygon zkEVM and zkSync Era, it is extremely hard to find secure oracles serving off-chain data with complete transparency, especially for major DeFi protocols securing millions in TVL and serving a large user base 24/7.</p><p>Apart from availability and security, developers have long sought a straightforward, plug-and-play data feed solution for their smart contracts that is easy to integrate and natively supports multiple chains. With these goals in mind, API3 has built a first-party oracle solution that offers secure, transparent, and accurate data feeds on most major EVM chains, while being simple to integrate and use.</p><h3>Start Using Managed dAPIs in Your Smart Contracts</h3><p>Connecting smart contracts to price reference data is easy with API3’s decentralized first-party data feeds. <a href="https://docs.api3.org/reference/dapis/understand/managed.html">Managed dAPIs</a> are data feeds that are sourced directly from multiple first-party oracles and are then aggregated on-chain. They utilize <a href="https://docs.api3.org/explore/airnode/what-is-airnode.html">API3’s Airnode</a>, which is a first-party oracle node run by the API provider to serve price data on-chain to DeFi protocols. As a managed service, API3 manages the gas costs and monitoring, which is currently available on 11 EVM-compatible chains.</p><h3>Getting Started</h3><p>Head over to the <a href="https://market.api3.org/dapis">API3 Market</a> to browse through all the available dAPI services. You can select which dAPIs you want to use. You can also filter the list by chains and data providers. After selecting the dAPI, you can select what type of dAPI you want to subscribe to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*nYv3_EmtFEgkhB4d" /></figure><p>Managed dAPIs gives you the option to configure the dAPI according to the needs of your protocol. You get the option to configure the deviation threshold and heartbeat for the specified dAPI. Select the required configuration, review the price and time frame, and click on <strong>Add to Cart</strong>.</p><p>If your required dAPI configuration has already been purchased by someone else, you can check the remaining operational time for the dAPI and can start using it directly.</p><h3>Placing the Order</h3><p>Once you have added all desired dAPIs on the same chain, proceed to checkout. You will be presented with a summary of your order. Select <strong>Proceed to Payment</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*qtDv0Af1RLL4uD7X" /></figure><p>This will take you to the payment page where you can place the order for the selected feeds. You can see the order summary and the total price. If it looks fine, select <strong>Connect Wallet</strong>, and confirm the transaction on MetaMask.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jjjf5vvwy6H1A73o" /></figure><p>Now wait for the transaction to get confirmed. Once it’s done, you will be able to see the confirmation page.</p><p>After making the payment, you will have to wait for the dAPI to get updated to your requested configuration. It usually takes up to 5 business days for the API3 dAPI team to update the dAPI. Once the dAPI is updated, you can start using it.</p><h3>Reading the dAPI</h3><p>Each dAPI is represented by a proxy contract. Each proxy contract is linked to a single dAPI on a particular network. You can use the address of a proxy contract to read dAPIs with the <a href="https://docs.api3.org/reference/dapis/understand/iproxy.html">IProxy interface</a>.</p><p>The process to read from a dAPI remains the same for both Managed and Self-funded dAPIs.</p><ol><li>Head over to Remix IDE where you will code a simple contract that imports the IProxy interface and calls the read() function to read the latest value from a dAPI.</li><li><a href="https://remix.ethereum.org/#url=https://github.com/api3-ecosystem/remix-contracts/blob/master/contracts/DataFeedReader.sol&amp;optimize=false&amp;runs=200&amp;evmVersion=null&amp;version=soljson-v0.8.9+commit.e5eed63a.js&amp;lang=en"><strong>Click here to open the contract in Remix.</strong></a></li><li>Start by importing the Ownable from the @openzeppelin library and the IProxy interface from the @api3/contracts library.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7292b1cd8ed829b19d5c5eac7bf5c2a/href">https://medium.com/media/a7292b1cd8ed829b19d5c5eac7bf5c2a/href</a></iframe><ol><li>Next, define a public address proxyAddress which is the address of the proxy contract that will be used to access the desired dAPI via its proxy contract.</li><li>The setProxyAddress() function is a public function that allows the owner of the contract to update the proxy contract address.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3201c9fdce05d0be1d079e793bc14e41/href">https://medium.com/media/3201c9fdce05d0be1d079e793bc14e41/href</a></iframe><p>The only thing left now is to make a function to read the dAPI. The readDataFeed() function is a public function that reads from a dAPI through the IProxy interface. The function returns the latest value and timestamp of the dAPI that the proxy is reading from.</p><p>Here’s the full contract. You can copy and paste it into Remix IDE.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ebd29cfafa57f2de5f6ad5d99e084ca/href">https://medium.com/media/0ebd29cfafa57f2de5f6ad5d99e084ca/href</a></iframe><p>As Managed dAPIs are only available on mainnets, we’re going to use the <strong>ETH/USD</strong> Self-funded dAPI on Polygon Mumbai for this example. Reading from a dAPI Proxy Contract remains the same in both cases.</p><p>Click on the <strong>COMPILE</strong> tab on the left side of the dashboard and click on <strong>Compile DataFeedReader.sol</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/0*Bh4f26HxCMY7Xg6W" /></figure><p>Head to <strong>Deploy and Run Transactions </strong>tab and select <strong>Injected Provider — MetaMask</strong> option under Environment.</p><p>Connect your MetaMask. Make sure you’re on the Polygon Mumbai Testnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/0*nPQdqC-3w83tp8v_" /></figure><h3>Updating the Proxy Address</h3><p>Head over to the <strong>Deploy &amp; Run Transactions</strong> tab, click on the dropdown under Deployed Contracts.</p><p>Now select the setProxyAddress dropdown to see all the parameters you need to pass in order to set the Proxy contract address on-chain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*7qIfknmz_7tI6ilh" /></figure><p>If you placed an order for a managed dAPI service, you will have to wait for 4–5 days to get the dAPI updated with your requested configuration.</p><p>As we’re using Self-funded dAPI for this guide, head over to <a href="https://market.api3.org/">https://market.api3.org</a> and search for ETH/USD dAPI on Polygon Mumbai Testnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lmU7MrTlcw7xmEHQ" /></figure><p>Here, you can <strong>Connect Wallet</strong> and then fund the dAPI to cover gas costs.</p><p>In this case, the gas for this ETH/USD dAPI is already funded on Polygon Mumbai for now, so we can start using it directly. Copy the proxy contract address, paste it into Remix under setProxyAddress() function and click on <em>transact.</em></p><p>Confirm the transaction in your wallet.</p><p>After the transaction is complete, you can now select and call the <em>readDataFeed</em> function that will return the latest value and timestamp from the dAPI, i.e., ETH/USD in this case.</p><p>The value returned is the latest data feed value and the timestamp is when the value was last updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/0*ae5VbZQkh0_LTuPu" /></figure><p>So that’s how you can utilize secure first-party data feeds in your smart contracts. You can start using dAPIs in your smart contract now at the <a href="https://market.api3.org/dapis">API3 Market</a>. Head over to the API3 <a href="https://docs.api3.org/">technical documentation</a> and learn more about how dAPIs work.</p><p>Have questions? <a href="https://discord.com/invite/qnRrcfnm5W">Join our Discord and ask our community of developers.</a></p><p>Other Resources</p><ul><li><a href="https://docs.api3.org/">API3 Docs</a></li><li><a href="https://www.youtube.com/API3DAO">API3 YouTube Channel</a></li><li><a href="http://github.com/api3dao/">API3 Github Repo</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=257e187ffc7f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/api3/how-to-use-first-party-data-feeds-in-your-smart-contracts-257e187ffc7f">How to Use First-Party Data Feeds in Your Smart Contracts</a> was originally published in <a href="https://medium.com/api3">Api3</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build Your Own On-chain Roulette Game with API3’s QRNG Oracle Service]]></title>
            <link>https://medium.com/api3/build-your-own-on-chain-roulette-game-with-api3s-qrng-oracle-service-d06293e7e922?source=rss-82dd8c0acd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d06293e7e922</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[defi]]></category>
            <dc:creator><![CDATA[Vansh Wassan]]></dc:creator>
            <pubDate>Mon, 26 Jun 2023 03:14:09 GMT</pubDate>
            <atom:updated>2023-06-26T03:14:09.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TzcBS-FbWIluXbIb" /></figure><p><em>Our comprehensive developers tutorial provides a step-by-step guide for how to build a Solidity-coded roulette game powered by the public good API3 QRNG oracle service. With this tutorial you will be fully equipped to explore the frontier of blockchain gaming, where quantum unpredictability becomes the standard for fair online games of chance.</em></p><h3>Introduction to Quantum-RNG for True Randomness</h3><p>In the evolving landscape of blockchain-based gaming, the key to success lies in creating verifiably fair, unbiased, and secure user experiences. The unique challenge for blockchain-based games is the generation of truly random numbers on-chain, a critical factor in creating unpredictable and engaging games.</p><p>The API3 QRNG (Quantum-Random Number Generation) oracle service provides developers with the tools needed to achieve a quantum level of randomness within smart contracts, building trust and fairness into a multitude of dApps. This randomness is enabled through the provision of entropy from the measurement of quantum fluctuations, providing what is commonly known as ‘true’ random number generation.</p><p>The element of randomness inherent in roulette creates an exciting game of chance. With each spin being independent of the last, predicting the outcome becomes an exciting challenge. This unpredictability underscores the importance of true randomness in games and it’s this principle that we’ll be exploring in the following tutorial.</p><h3>Learn How To Integrate Entropy Into Your Smart Contract</h3><p>In order to demonstrate how to use QRNG in a smart contract, we created a developer’s tutorial that brings to life the classic game of roulette. Named after the French term for “little wheel,” in the game roulette players place bets on a single number, various groupings of numbers, the colors red or black, or whether the number is odd or even. A small ball spun around a rotating wheel ultimately determines the outcome as it gradually loses momentum and falls into one of the numbered slots.</p><p>API3 is committed to helping developers learn how to use Web3 technologies. Through this tutorial, developers can learn how to integrate an oracle requester contract into a smart contract, then how to utilize off-chain data within execution. While this demo will provide an end-to-end learning experience on how to use QRNG, this principle can be applied to a host of data types and will help you understand the principles of using oracles in smart contracts.</p><p>Starting with an extensive overview of roulette mechanics and the various betting options, the tutorial utilizes Remix IDE to code and deploy the roulette contract. As you code your own game, you will learn how QRNG guarantees unpredictability and fairness.</p><h4><a href="https://docs.api3.org/guides/qrng/roulette-guide/">Access Developer’s Tutorial: Coding an On-chain Roulette Game Using QRNG</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0uOIYM8IyHxk0Or7.png" /></figure><h3>Get started</h3><p>We’re pleased to provide the developer community with this demo project to support those looking to progress their Web3 development skills. The API3 Ecosystem is a flourishing community of builders and we welcome those that complete the project to join the API3 Discord and submit your completed demo. Likewise, if you require any help from the team we are on hand to help!</p><ul><li>Access the <a href="https://docs.api3.org/guides/qrng/roulette-guide/">developer’s tutorial</a>.</li><li><a href="https://learnweb3.io/bounties/qrng-roulette-wheel-bounty-challenge/">LearnWeb3 Bounty Challenge</a>: Learn how to build a roulette wheel and deploy a working dApp.</li><li>Learn more about <a href="https://medium.com/api3/exploring-api3-qrng-the-gold-standard-for-truly-random-numbers-8da07f144f5">QRNG and its potential uses</a>.</li><li>Visit our <a href="https://docs.api3.org/reference/qrng/">technical documentation</a> for more information.</li></ul><p>Let us know if you have any questions.</p><p><a href="https://discord.com/invite/qnRrcfnm5W">Click here</a> to join the <a href="https://discord.com/invite/qnRrcfnm5W">API3 Discord</a> server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d06293e7e922" width="1" height="1" alt=""><hr><p><a href="https://medium.com/api3/build-your-own-on-chain-roulette-game-with-api3s-qrng-oracle-service-d06293e7e922">Build Your Own On-chain Roulette Game with API3’s QRNG Oracle Service</a> was originally published in <a href="https://medium.com/api3">Api3</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making an on-chain Payment and Minting an NFT Receipt with Permissionless Price Oracles]]></title>
            <link>https://vanshwassan.medium.com/making-an-on-chain-payment-and-minting-an-nft-receipt-with-permissionless-price-oracles-a7339f7b8c3e?source=rss-82dd8c0acd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7339f7b8c3e</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[dapi]]></category>
            <category><![CDATA[hard-hat]]></category>
            <category><![CDATA[api3]]></category>
            <dc:creator><![CDATA[Vansh Wassan]]></dc:creator>
            <pubDate>Tue, 02 May 2023 21:19:52 GMT</pubDate>
            <atom:updated>2023-05-11T05:07:26.658Z</atom:updated>
            <content:encoded><![CDATA[<h4>dApp to accept ERC20 token payments and mint an NFT receipt with the USD value to the user.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xseXMMG6UZFTj0yc" /><figcaption>Photo by <a href="https://unsplash.com/@theshubhamdhage?utm_source=medium&amp;utm_medium=referral">Shubham Dhage</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>In my <a href="https://vanshwassan.medium.com/using-dapis-on-zksync-era-testnet-30f12efdd95f">previous guide</a> I explained how to request the latest price data on-chain. In this guide, I’m going to explain how to code a smart contract that accepts any ERC20 token as payment, and mints the payment receipt as an NFT that includes how much you paid to the contract in USD value at the time of payment. For this tutorial, I’m going to use a mock ERC20 token (Mock WETH) and set it to the ETH/USD dAPI for calculating the USD value for each payment.</p><p><a href="https://medium.com/@vanshwassan/using-dapis-on-zksync-era-testnet-30f12efdd95f"><em>To know more about dAPIs, check out this previous guide</em></a></p><h3>API3 Market: Activating self-funded dAPIs</h3><p>Developers can use the <a href="https://market.api3.org/dapis">API3 Market</a> to search for dAPIs, obtain dAPI proxy contract addresses, and monitor dAPIs. To access self-funded dAPIs, you can head to the <a href="https://market.api3.org/">API3 Market</a> to fund and access a data feed so that a smart contract can utilize the value in a dApp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u-NU_DB3Dqo18IUV3OZaAQ.png" /><figcaption><a href="https://market.api3.org/dapis">https://market.api3.org/dapis</a></figcaption></figure><h4>Funding a feed</h4><p>To use the self-funded dAPIs, the user is required to fund the respective dAPI sponsor wallet with gas to activate it. The amount of gas supplied will determine how long your dAPI will be available for use. If the dAPI runs out of gas, it can be funded again to keep it available for use.</p><p>If the feed is not already funded, users need to provide chain native collateral to the sponsor address of the required feed. This process happens through the API3 Market UI, where there is functionality to understand the estimated gas remaining and the time that the feed will be active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*SKfmZpACV7OvZN056nuhog.png" /></figure><h4>Deploying the proxy contract</h4><p>After ensuring the dAPIs are funded, you can deploy the proxy contract using the Market to access the dAPI.</p><ul><li>For ETH/USD on Polygon Mumbai — <a href="https://market.api3.org/dapis/polygon-testnet/ETH-USD">ETH/USD dAPI</a></li><li>For MATIC/USD on Polygon Mumbai — <a href="https://market.api3.org/dapis/polygon-testnet/MATIC-USD">MATIC/USD dAPI</a></li></ul><p>If the proxy contract for a dAPI is already deployed, you can just start using it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*iYWp5VFUMa4RRs8SI2HtLQ.png" /></figure><h3>Getting Started</h3><p>Before starting, make sure you have the following installed:</p><ul><li><em>nodejs</em></li><li><em>yarn</em></li><li><em>git</em></li></ul><p>We assume Javascript &amp; Solidity basics are understood when reading this.</p><p>To get started, clone this repo:</p><pre>$ git clone https://github.com/vanshwassan/dAPI-payments.git</pre><p>To install the dependencies,</p><pre>$ yarn</pre><h4>Coding the Contracts</h4><p>There are 3 main contracts that we’ve used in this project.</p><ul><li><em>Payments.sol</em></li><li><em>WETH.sol</em></li><li><em>WMATIC.sol</em></li></ul><p>The Payments contract has many functions. Using the contract, any user can:</p><ul><li>Send any ERC20 (Mock WETH, Mock WMATIC) payments to the contract and mint a Payment Receipt Token(PRT) NFT with the USD value of the assets at the time of payment.</li><li>Check the USD value of the assets using your NFT’s tokenId.</li></ul><p>Similarly, the Owner (the address that deployed the contract) can:</p><ul><li>Set the dAPI Proxies for the ERC20 tokens using the <a href="https://market.api3.org/dapis">API3 Market</a>.</li><li>Withdraw the total funds sent to the contract.</li></ul><p><em>Payments.sol</em> has all the functions required for collecting the ERC20 funds and calculating its USD value.</p><p>setDapiProxy() will be used to map and set the dAPI Proxy for the ERC20 tokens which the user will be required to pay. You can see a list of available dAPIs <a href="http://market.api3.org/">here</a>.</p><pre>function setDapiProxy(address token, address _proxy)<br>        public<br>        onlyOwner<br>    {<br>        tokenProxyMapping[token] = _proxy;<br>    }</pre><p>getTokenPrice() function calls the dAPI and takes in the token address mapped to its dAPI Proxy obtained from the API3 Market and returns the latest price of the requested asset.</p><pre>function getTokenPrice(address token) public view returns (uint256 tokenPriceUint256) {<br>        address proxy = tokenProxyMapping[token];<br>        int224 value;<br>        uint256 timestamp;<br>        (value, timestamp) = IProxy(proxy).read();<br>        uint224 tokenPriceUint224 = uint224(value);<br>        tokenPriceUint256 = tokenPriceUint224;<br>    }</pre><p>The Payment() function takes in the address of the token and the total amount that the user wants to pay. It then calls the getTokenPrice() function to get the latest price and mints an NFT Receipt with a tokenId and the total USD value the user paid.</p><pre>function Payment(address token, uint256 _tokenAmount) public returns(uint256) {<br>        require(_tokenAmount &gt; 0, &quot;amount cannot be 0&quot;);<br>        require(tokenIsAllowed(token), &quot;token not allowed&quot;);<br>        if (tokenIsAllowed(token)) {<br>            uint256 tokenId = _tokenIdCounter.current();<br>            _tokenIdCounter.increment();<br>            uint256 decimals = ERC20(token).decimals();<br>            uint256 tokenPriceUint256 = getTokenPrice(token);<br>            uint256 _usdValue = (tokenPriceUint256 * _tokenAmount)/10**decimals;<br>            ERC20(token).transferFrom(msg.sender, address(this), _tokenAmount);<br>            _safeMint(msg.sender, tokenId);<br>            uint256 receipt = makeReceipt(tokenId, _usdValue);<br>            return receipt;<br>    }<br>    }</pre><p>The checkReceipt() function is a view function that returns the total USD value of the ERC20 asset paid by the user by taking in the tokenId minted with the NFT Receipt at the time of payment.</p><pre>function checkReceipt(uint256 tokenId) public view returns (uint256) {<br>        return (TokenIDtoPrice[tokenId]);<br>    }</pre><p>The ownerWithdrawFunds() function that the owner of the contract can call to withdraw all the funds from the contract to his wallet.</p><pre>function ownerWithdrawFunds() public onlyOwner {<br>        for (uint256 i = 0; i &lt; allowedTokens.length; i++) {<br>            ERC20(allowedTokens[i]).transfer(msg.sender, ERC20(allowedTokens[i]).balanceOf(address(this)));<br>        }<br>    }</pre><p>Here’s the full contract:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58859096a3a1c32396d4d88902ef9434/href">https://medium.com/media/58859096a3a1c32396d4d88902ef9434/href</a></iframe><p>You can find the repository with contract code <a href="https://github.com/vanshwassan/dAPI-payments">here</a>.</p><h4>Deploying the Contracts</h4><p>Before moving forward, enter your mnemonic in <em>credentials.json</em> to deploy and interact with the contracts.</p><pre>$ cp credentials.example.json credentials.json</pre><p>Now go to <em>credentials.json</em> and enter your credentials. As we’re testing this on Mumbai Testnet, you can just add your mnemonic under Mumbai. Make sure you fund your wallet with testnet MATIC before moving forward. You can request <a href="https://mumbaifaucet.com/">testnet MATIC here</a></p><p>Now compile the contracts:</p><pre>$ yarn compile</pre><p>To deploy the contracts and set the dAPI Proxies:</p><pre>$ yarn deploy</pre><p>This will deploy the <strong>Mock WETH</strong> and <strong>Mock WMATIC</strong> token contracts alongside the <strong>Payments Contract</strong>. It will also set the dAPI proxy contract addresses mapped to their respective ERC20 tokens. Head on to deploy/<a href="https://github.com/vanshwassan/dAPI-payments/blob/master/deploy/3_deploy_Payments.js">3_deploy_Payments.js</a> If you want to make changes to the dAPI Proxy/use another ERC20 token.</p><h4>Using the dApp</h4><p>Import the Mock WETH contract address in your account’s Metamask. This token is just a mock token, a simple implementation of an openzeppelin ERC20 contract. As it’s a testnet, <strong>I’m going to call it WETH and map its value to the ETH/USD dAPI.</strong></p><p>This token will be used to make payments to the contract.</p><p>Similarly, for the <strong>Mock WMATIC token, the value can be mapped to the MATIC/USD dAPI</strong>.</p><p>To use the scripts I made to interact with the contracts, head back to the <a href="https://github.com/vanshwassan/dAPI-payments">Project</a> and use the following commands.</p><ul><li>Use the below command to send a payment to the contract. This will <strong>send 2.5 Mock WETH and 2.5 Mock WMATIC</strong> to the contract and will mint the <strong>Payments Receipt Tokens(PRT)</strong> to the user’s address as a digital proof of payment with the USD value of the token(s) at the time of payment. You can edit the amounts in scripts/<a href="https://github.com/vanshwassan/dAPI-payments/blob/master/scripts/sendPayment.js">sendPayments.js</a></li></ul><pre>$ yarn sendPayment</pre><ul><li>Use the below command to check your Payments Receipt Token(PRT). It takes in the tokenId and returns the USD value of how much the user paid. Edit the tokenId value in scripts/<a href="https://github.com/vanshwassan/dAPI-payments/blob/master/scripts/checkReceipt.js">checkReceipt.js</a></li></ul><pre>$ yarn checkReceipt</pre><ul><li>Use the below command to check the USD value of all the funds that the contract holds.</li></ul><pre>$ yarn checkContractBalance</pre><ul><li>Use the below command to withdraw all the funds stored in Contract. Only the owner of the contract can call this.</li></ul><pre>$ yarn withdraw</pre><h3>Conclusion</h3><p>In this tutorial, you learned how to code a simple, usable dApp and how we can utilize dAPIs within a smart contract.</p><p>Check out the repository for this guide <a href="https://github.com/vanshwassan/dAPI-payments">here</a>.</p><p>Read more about dAPIs <a href="https://docs.api3.org/guides/dapis/subscribing-self-funded-dapis/">here</a>.</p><p>Developers can get started with dAPIs now through the API3 Market. If you have any questions, you can join the <a href="https://discord.com/invite/qnRrcfnm5W">API3 Discord</a> server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7339f7b8c3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using dAPIs on zkSync Era Testnet]]></title>
            <link>https://medium.com/api3/using-dapis-on-zksync-era-testnet-30f12efdd95f?source=rss-82dd8c0acd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/30f12efdd95f</guid>
            <category><![CDATA[api3-ecosystem]]></category>
            <category><![CDATA[dapi]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[api3]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Vansh Wassan]]></dc:creator>
            <pubDate>Sat, 15 Apr 2023 05:32:17 GMT</pubDate>
            <atom:updated>2023-05-11T05:08:25.084Z</atom:updated>
            <content:encoded><![CDATA[<h4>Integrate API3’s first-party data feeds in your smart contracts</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2QHd70zTEIH7pJAx" /><figcaption>Photo by <a href="https://unsplash.com/@sandrokatalina?utm_source=medium&amp;utm_medium=referral">Sandro Katalina</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://docs.api3.org/explore/dapis/what-are-dapis.html">dAPIs</a> are continuously updated streams of off-chain data, such as the latest cryptocurrency, stock, and commodity prices. As such they play a crucial role in the infrastructure of DeFi.</p><p><a href="https://api3.org/">API3</a> uses first-party oracles to power decentralized APIs (dAPIs). dAPIs are secure, transparent, and cost-efficient data feeds that connect smart contracts directly to first-party data sources.</p><p>Over 100 forex &amp; crypto data feeds are available to builders on zkSync Era Testnet. These can be <a href="https://market.api3.org/dapis?chains=zksync-goerli-testnet"><em>viewed here</em></a>.</p><h3>API3 data feeds: dAPIs</h3><p><a href="https://docs.api3.org/guides/dapis/read-self-funded-dapi/">Self-funded dAPIs</a> give DeFi builders access to real-time market data through first-party oracles. Users do this by funding a dAPI to be used for oracle transactions, thus activating the feed in a permissionless format.</p><p>To ensure accuracy and reliability, the data feeds are continuously updated by first-party oracles using signed data, which provides cryptographic proof of their authenticity. As a result, smart contracts can read the on-chain value of any dAPI in real-time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*T-VoTbkWanABxvJQ" /></figure><p>In the coming months, multi-source data feeds will be usable that see beacon sets (aggregated first-party feeds) consumable through a dAPI. The API3 DAO configures a dAPI mapping as requested, also enabling OEV to be captured later in the year.</p><h3>API3 Market</h3><p>The<a href="https://market.api3.org/"> API3 Market➚</a> is a user-friendly interface to seamlessly access dAPI services. For self-funded dAPIs, this end-to-end process consists of:</p><ul><li>Browsing and selecting your dAPI</li><li>Funding the dAPI</li><li>Deploying a proxy contract to access the data feed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v-PcKvCDkQDcKkptZF8gBQ.png" /></figure><h3>Using dAPIs in your Smart Contracts</h3><h4>Before you start</h4><p>Users need to make sure they have:</p><ul><li>Metamask connected to zkSync Era Testnet.</li><li>Testnet Goerli Eth on zkSync Era Testnet. <em>To bridge your Goerli ETH to zkSync Era Testnet, </em><a href="https://goerli.bridge.zksync.io/"><em>click here</em></a><em>.</em></li></ul><p>Or you can also refer to this repository to get started.</p><ul><li><a href="https://github.com/api3dao/data-feed-reader-example">https://github.com/api3dao/data-feed-reader-example</a></li></ul><h3>Funding the dAPIs and Deploying a Proxy</h3><p>To integrate self-funded dAPIs in your smart contracts, head to the API3 Market and select the dAPIs you would like to use. Make sure you’re on the same network where you want to use the dAPI.</p><p>For this tutorial, we’ll use the ETH/USD dAPI on zkSync Era.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nzVL-u77sq9ZmOhEae_ZXQ.png" /></figure><p>With self-funded dAPIs, you can fund the dAPI with your funds. The amount of gas you supply will determine how long your dAPI will be available for use. If you run out of gas, you can fund the dAPI again to keep it available for use.</p><p>The API3 Market has an estimation tool that helps you manage this.</p><p>If the dAPI is already funded for your required time, you can click on <strong>Get Proxy</strong> and start using it.</p><p>To fund a dAPI, click on the <strong>Fund Gas</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*rlCPM_E3RxCv6q40OHGghA.png" /></figure><p>Use the gas estimator to select how much gas is needed by the dAPI. Click on <strong>Send ETH</strong> to send the entered amount to the sponsor wallet of the respective dAPI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*q5tK5sPfKCbswkDzhgVmYg.png" /></figure><p>Once the transaction is broadcasted and confirmed on the blockchain a transaction confirmation screen will appear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIQ6EsHWLeMhwkrz2mvl6Q.png" /></figure><p>You can now click on the <strong>Get Proxy</strong> button to deploy the proxy contract to read from the dAPI. If the proxy contract for a dAPI is already deployed, it will show you its address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*LwKRJ2nO-5gYtjWXSdS_bg.png" /></figure><p>You now press ‘Get Proxy’ where you read the most recent value of the data feed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*J2U-9qtsHdXrdkN3XifTdQ.png" /></figure><p>The dashboard will look similar to the below with the last updated value visible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BSFtabzPC7xMe896xzlZYQ.png" /></figure><h3>Coding and Deploying the Contract</h3><p>Now we will code a simple contract that returns the price of Ethereum using the ETH/USD dAPI.</p><p>First, import the required contracts. After importing, we can make the contract and inherit from <em>Ownabe</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ef80b6c8f385367df974c0f9816de74/href">https://medium.com/media/6ef80b6c8f385367df974c0f9816de74/href</a></iframe><ul><li>setProxy() is used to set the address of the dAPI Proxy Contract.</li><li>The readDataFeed() function will call the read() function from the IProxy interface. This will return the data feed value and timestamp on-chain.</li></ul><p>Users can now use the data feed value returned in any way they want.</p><p>You can refer to this <a href="https://github.com/vanshwassan/DataFeedReader-zkSync">example project</a> on how to deploy and read the DataFeedReader contract on zkSync Era Testnet.</p><pre>$ git clone https://github.com/vanshwassan/DataFeedReader-zkSync.git</pre><ul><li>Install all the packages:</li></ul><pre>$ yarn</pre><ul><li>Make a .env file similar to example.env and add your private key:</li></ul><pre>$ echo &#39;PRIVATE_KEY=&#39; &gt; .env</pre><ul><li>To compile the DataFeedReader contract:</li></ul><pre>$ yarn compile</pre><ul><li>To deploy the DataFeedReader contract:</li></ul><pre>$ yarn deploy</pre><ul><li>To read the data feed value:</li></ul><pre>$ yarn readDapi</pre><p>You can also refer to <a href="https://github.com/api3dao/data-feed-reader-example">this Repo</a> for a more detailed example.</p><p>Check out the <a href="https://docs.api3.org/">API3 Docs</a> for more guides.</p><h3>Conclusion</h3><p>dAPIs have been designed to abstract away the technical implementation of data feeds with a modular design approach made possible by first-party oracles. Once a dAPI has been imported to oracle contracts, the API3 DAO can redirect the dAPI mapping upon user requests to other API3 data feeds or services.</p><p>This means once the straight forward steps above have been followed you can utilize first-party oracles. To learn more or get started with dAPIs head to the <a href="https://docs.api3.org/explore/dapis/what-are-dapis.html">API3 Docs</a>.</p><p>You can also check <a href="https://medium.com/@ashar2shahid/developers-guide-on-switching-your-oracle-migrating-to-dapis-eb53e673c793">this guide on how to switch your oracle from Chainlink and start using dAPIs.</a></p><p><a href="https://discord.gg/qnRrcfnm5W">Click here</a> to join our Discord if you have any questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30f12efdd95f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/api3/using-dapis-on-zksync-era-testnet-30f12efdd95f">Using dAPIs on zkSync Era Testnet</a> was originally published in <a href="https://medium.com/api3">Api3</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Switching from Chainlink VRF to API3 QRNG]]></title>
            <link>https://medium.com/coinmonks/switching-from-chainlink-vrf-to-api3-qrng-b7939c5a4760?source=rss-82dd8c0acd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7939c5a4760</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[api3]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[vrf]]></category>
            <category><![CDATA[nft]]></category>
            <dc:creator><![CDATA[Vansh Wassan]]></dc:creator>
            <pubDate>Thu, 27 Oct 2022 13:44:50 GMT</pubDate>
            <atom:updated>2023-05-11T05:15:37.077Z</atom:updated>
            <content:encoded><![CDATA[<h4>Switching from Chainlink VRFs to API3 QRNG to generate NFTs and utilizing true quantum randomness in your mints.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R8WocxYVyHB7TGe0" /><figcaption>Photo by <a href="https://unsplash.com/@yassine_khalfalli?utm_source=medium&amp;utm_medium=referral">Yassine Khalfalli</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>I’ve already discussed the problem of generating true randomness in a smart contract in my previous article. This is going to be a more advanced version of that. You can read it <a href="https://vanshwassan.medium.com/a-guide-to-using-anus-quantum-random-number-generator-in-your-smart-contracts-21be5bed5aba">here</a>.</blockquote><h3>Introduction</h3><p>In this tutorial, we’ll be making a simple mint contract and minting an NFT for a random Dungeons and Dragons character giving it attributes/statistics to show its strength, mana, intelligence and experience utilizing API3’s Quantum Random Number Generation (QRNG). I got this idea while I was going through <a href="https://blog.chain.link/random-numbers-nft-erc721/">Patrick Collins’s tutorial</a> on making the same but instead of using Chainlink’s VRFs to generate and set random attributes, we are going to utilize API3’s QRNG.</p><p>To read more about what QRNG is and how it works, click <a href="https://docs.api3.org/explore/qrng/">here</a>.</p><blockquote><a href="https://docs.api3.org/qrng/reference/chains.html">The API3 QRNG Service is free and live on all major EVM Compatible Testnets.</a></blockquote><p>The <a href="https://blog.chain.link/random-numbers-nft-erc721/">guide</a> that Patrick Collins wrote uses Chainlink VRF to generate random attributes for the Character. I’ve already discussed the shortcomings of using a third-party oracle network in my previous article, and I also find it somewhat complicated in setting up LINK token spending limits within your smart contract (It’s not a free service). However, API3 QRNG is completely free and is much easier to integrate. You don’t need to set any spending limits in your smart contracts, instead just fund a simple sponsor wallet that uses the native gas token for the chain to cover all the gas costs.</p><h3>Coding the NFT Contract</h3><p>Let’s start with creating a basic character which has five main attributes:</p><p>strength, intelligence, mana, experience and name. We are going to store all these attributes under a Character struct. Whenever we will make a new Character, these attributes will be set randomly.</p><p>We then define a Character array that defines all the characters which exist within the contract.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ed4fc3e5f91c89352b24238e9e2af22/href">https://medium.com/media/8ed4fc3e5f91c89352b24238e9e2af22/href</a></iframe><p>We’ve imported the <em>RrpRequesterV0.sol</em> which is the on-chain <a href="https://docs.api3.org/reference/airnode/latest/concepts/">RRP protocol contract</a> <em>(</em><a href="https://docs.api3.org/reference/airnode/latest/concepts/#airnoderrpv0-sol"><em>AirnodeRrpV0.sol</em></a><em>)</em>. It is responsible for making the actual full request to the QRNG Airnode. The off-chain Airnode then fetches the event logs after the request has been made and gets the requested random number and performs a callback to the requester.</p><p>We’ve also imported the <em>ERC721.sol </em>and <em>Ownable.sol </em>from OpenZeppelin to make and mint an NFT.</p><p>The airnode is the address for the QRNG Airnode, endpointIdUint256 specifies the endpoint of the QRNG API path and sponsorWallet will be the wallet that will make the actual request. We’ll need to fund this wallet later.</p><p>The expectingRequestWithIdToBeFulfilled mapping will keep a track of our request and check if it has been fulfilled or not.</p><p>The requestToCharacterName mapping keeps a track of each request for randomness as it is tied to the Character’s name.</p><p>Each character has a unique ID that represents it which is mapped to requestToTokenId. requestToSender is tied to the address that mints the NFT.</p><p>The constructor will accept the _airnodeRrp address as an argument.</p><p><em>ERC721</em> takes 2 arguments, the name for the token and the symbol for it. Here, the name is DungeonsAndDragonsCharacter and the symbol is D&amp;D .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61d22f4e487322a15a406a64625213c4/href">https://medium.com/media/61d22f4e487322a15a406a64625213c4/href</a></iframe><p>The <em>setRequestParameters</em> function will set the request parameters.</p><p>The <em>requestNewRandomCharacter </em>function will request for randomness to the Airnode. It takes the name of the character as input. It then calls the <em>makeFullRequest</em> function of the <a href="https://docs.api3.org/reference/airnode/latest/concepts/#airnoderrpv0-sol">AirnodeRrpV0.sol</a> protocol contract which adds the request to its storage and returns a requestId.The requestId will then be used to set all the mappings in the function.</p><p>Once the request has been made to the Airnode, we now wait for it to be fulfilled, which will be done through the <em>fulfillRandomness </em>function.</p><p>The targeted off-chain QRNG Airnode gathers the request and performs a callback to the requester (using the <em>fulfillRandomness </em>function) with the random number (qrngUint256).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b356ae95e122b788d726eb6cfd315363/href">https://medium.com/media/b356ae95e122b788d726eb6cfd315363/href</a></iframe><p>Using the qrngUint256 , we can now set the attributes for our character and push the character to the array.</p><p>Finally, we will mint the token and send it to the address that made the randomness request along with its <em>Id</em>.</p><p>The <em>getCharacterStats </em>is a view function that will get back the character stats. It takes in tokenId .</p><p>We can now move forward and deploy and compile the Smart Contract.</p><h3>Compiling and Deploying the NFT Contract</h3><p>Head to <a href="https://remix.ethereum.org/">Remix IDE</a>, make a contract and paste in the <a href="https://gist.github.com/vanshwassan/48baa25995ef3c556ebf208c725f7a86"><em>API3</em>QRNG</a> code. Now hit compile on the right side of the dashboard and compile the Smart Contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*yvwsN04zZT8IplHVdcKYAg.png" /></figure><p>We are going to deploy it on the Goerli Testnet. Make sure you have enough testnet ETH in your wallet to deploy the contract and fund the sponsorWallet later. You can get some from <a href="https://goerlifaucet.com/">here</a>.</p><p>Head to Deploy and run Transactions and select Injected Provider — MetaMask option under Environment. Connect your MetaMask. Make sure you’re on Goerli Testnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*qJPTWT4F1Sze8HTxwpepMQ.png" /></figure><p>The _rrpAddress is the main <em>airnodeRrpAddress. </em>The RRP Contracts have already been deployed on-chain. You can check for your specific chain <a href="https://docs.api3.org/qrng/reference/chains.html">here</a>.</p><p>Fill in the _rrpAddress and click on Deploy. Confirm the transaction on your MetaMask and wait for it to deploy the requester Contract.</p><h3>Calling the Contract</h3><p>When your <em>API3QRNG</em> gets deployed, head to Deploy &amp; run transactions and click on the dropdown for your requester under Deployed Contracts.</p><p>Now select the <em>setRequestParameters</em> dropdown to set all the parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*i-8w300dh7xw0n7TFJCWEw.png" /></figure><p>You can find <em>_airnode</em> (QRNG Provider Airnode Address) and <em>_endpointIdUint256</em> <a href="https://docs.api3.org/reference/qrng/providers.html">here</a>.</p><p><em>_sponsortWallet</em> is your wallet that is derived from the requester contract address, the Airnode address and the Airnode xpub. The wallet is used to pay gas costs to acquire a random number. A sponsor wallet must be derived using the command <a href="https://docs.api3.org/reference/airnode/latest/packages/admin-cli.html#derive-sponsor-wallet-address">derive-sponsor-wallet-address</a> from the Admin CLI. Use the value of the <em>sponsor wallet address</em> that the command outputs. Make sure you fund this wallet with enough test ETH as it’s gonna make the actual request.</p><p>Click on transact button and confirm the transaction to set the parameters.</p><p>Now we can move forward and request a random character. To do that, click on <em>requestNewRandomCharacter </em>and give your character a name. Click on transact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*L0gr-z58yM_twMRafrKUnA.png" /></figure><p>Now you can head over to <a href="https://goerli.etherscan.io/">https://goerli.etherscan.io</a> and check your <em>sponsorWallet</em> for any new transactions.</p><blockquote>You might need to wait for a while as the Airnode calls the fulfill() function in AirnodeRrpV0.sol that will in turn call back the requester contract at fulfillAddress using function fulfillFunctionId to deliver data(the random number).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ef2XWtbxdClyd7_hTuXfNQ.png" /></figure><p>Here, we can see the latest <em>Fulfill</em> transaction. You can click on it and see the D&amp;D NFT has been minted and sent to your address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0xkrQlN25d1XdHGnk-MYXA.png" /></figure><p>To check your Character stats, go back to Remix, click on <em>getCharcterStats</em> and input your tokenId (0 in this case)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*SLyqHTJ003aUaTsYmTgP0Q.png" /></figure><p>Here, these are the Character Stats/Attributes for our Character.</p><p>So we requested and minted a new Character NFT using Quantum Randomness.</p><p>Check the <a href="https://github.com/vanshwassan/QRNG-NFT-Mint">Github repo</a> for all the code used in this guide.</p><p>Read more about <a href="https://docs.api3.org/qrng/">API3 QRNG</a>.</p><pre><strong>Any questions?<br></strong>Check out <a href="https://discord.com/invite/qnRrcfnm5W"><strong>API3’s Discord Server</strong></a> and drop your queries there!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7939c5a4760" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/switching-from-chainlink-vrf-to-api3-qrng-b7939c5a4760">Switching from Chainlink VRF to API3 QRNG</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide to Using ANU’s Quantum Random Number Generator in Your Smart Contracts]]></title>
            <link>https://medium.com/better-programming/a-guide-to-using-anus-quantum-random-number-generator-in-your-smart-contracts-21be5bed5aba?source=rss-82dd8c0acd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/21be5bed5aba</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Vansh Wassan]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 21:46:50 GMT</pubDate>
            <atom:updated>2023-05-11T05:24:02.590Z</atom:updated>
            <content:encoded><![CDATA[<h4>Create your contracts with truly random numbers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rjYmsGDM5hrddc2f" /><figcaption>Photo by <a href="https://unsplash.com/@flyd2069?utm_source=medium&amp;utm_medium=referral">FLY:D</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Random number generation (RNG) has always been one of the biggest problems when working with smart contracts. A deterministic virtual machine is incapable of generating ‘true’ randomness. Due to this, RNG needs to be provided as an oracle service.</p><p>To fulfill the need for randomness in smart contracts, decentralized pseudorandom RNG has been a common way. One of the most used methods is Chainlink’s VRF or verifiable random function, which provides cryptographically provable random numbers on-chain. It generates a random number off-chain with cryptographic proof that’s used to verify the result.</p><blockquote>However, this configuration suffers from the same issues as any other third-party oracle network. Setting up an oracle node that can provide PRNG exposes potential attack vectors like<a href="https://en.wikipedia.org/wiki/Sybil_attack"> Sybil attacks</a>, but also lacks source transparency and decentralization. For example, one needs to trust the governing entity to select the network participants, which means decentralized PRNG is only as secure and decentralized as the governing entity.</blockquote><h3>Quantum Random Number Generation</h3><p><a href="https://docs.api3.org/explore/qrng/">QRNG</a> generates randomness via quantum phenomena. It uses a ‘true’ source of entropy using unique properties of quantum physics to generate true randomness.</p><p>There are different methods of implementing QRNG with varying levels of practicality, yet the common point is that the resulting numbers will be truly random because the outcome of a quantum event is theoretically uncertain with well-defined characteristics. Therefore, QRNG is the gold standard for random number generation.</p><h3>Australian National University’s QRNG Airnode</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sm4Eo5c6GcDTwkIU" /><figcaption>Dr Aaron Tranter of <a href="https://quantumnumbers.anu.edu.au/">ANU</a></figcaption></figure><p>As we already discussed, providing RNG through a third-party oracle network opens space for attack vectors. But first-party oracles (<a href="https://docs.api3.org/airnode/v0.8/">Airnodes</a>) that are directly operated by the <a href="https://docs.api3.org/reference/qrng/providers.html">QRNG API</a> Providers optimally counter the Sybil attack risk.</p><p><a href="https://docs.api3.org/explore/qrng/">API3 QRNG</a> is a public utility offered through the Australian National University (ANU). It is powered by an Airnode hosted by ANU Quantum Random Numbers, meaning that it is a first-party service. <a href="https://www.anu.edu.au/">Australian National University</a>’s Quantum Optics Division is one of the worlds leading research institutions in the field. The division also operates a REST API,<a href="https://quantumnumbers.anu.edu.au/"> Quantum Random Numbers API</a>, to serve QRNG in Web2.</p><p><a href="https://quantumnumbers.anu.edu.au/">Read more about how ANU Generates random numbers in real time by measuring the quantum fluctuations of the vacuum</a></p><p>It is served as a public good and is free of charge (apart from the gas costs), and it provides ‘true’ quantum randomness via an easy-to-use solution when requiring RNG on-chain.</p><h3>How Airnode and API3 QRNG works</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vDXkbKS5MSHUbFL1.png" /><figcaption><a href="https://docs.api3.org/reference/qrng/">https://docs.api3.org/reference/qrng/</a></figcaption></figure><p>To begin, we need to deploy and sponsor the QrngRequester with a matching sponsor wallet. The QrngRequester will be the primary contract that retrieves the random number.</p><p>The QrngRequester submits a request for a random number to AirnodeRrpV0. Airnode gathers the request from the AirnodeRrpV0 protocol contract, retrieves the random number off-chain, and sends it back to AirnodeRrpV0. Once received, it performs a callback to the requester with the random number.</p><p>You can read more about how API3 QRNG uses the request-response protocol <a href="https://docs.api3.org/reference/qrng/">here</a>.</p><h3>Coding QrngRequester.sol</h3><h4>Getting started</h4><p>Make sure you have the following installed:</p><ul><li>node.js</li><li>yarn/npm</li></ul><p>Also, make sure you’ve already cloned and installed the <a href="https://github.com/api3dao/airnode">Airnode Monorepo</a>. If you haven’t, clone the Airnode Monorepo with this command:</p><pre>$ git clone <a href="https://github.com/api3dao/airnode.git">https://github.com/api3dao/airnode.git</a> .</pre><p>To install the dependencies, do the following:</p><pre>$ yarn run bootstrap</pre><p>To build all the packages, use this command:</p><pre>$ yarn run build</pre><h3>Compiling the Contract</h3><p>To compile the QrngRequester contract, we are going to use <a href="https://remix.ethereum.org/">Remix IDE</a>. It’s an online IDE that allows the developing, deploying, and administering of smart contracts for EVM-compatible blockchains.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/858a8d5b49bad4df03f146e9927ff63d/href">https://medium.com/media/858a8d5b49bad4df03f146e9927ff63d/href</a></iframe><p>The QrngRequester will have three main functions: setRequestParameters(), makeRequestUint256(), and fulfillUint256().</p><ol><li>The setRequestParameters() takes in airnode, endpointIdUint256, sponsorWallet and sets these parameters.</li><li>The makeRequestUint256() function calls the airnodeRrp.makeFullRequest() function of the <a href="https://docs.api3.org/reference/airnode/latest/concepts/#airnoderrpv0-sol">AirnodeRrpV0.sol</a> protocol contract which adds the request to its storage and returns a requestId.</li><li>The targeted off-chain ANU Airnode gathers the request and performs a callback to the requester with the random number.</li></ol><h3>Request Parameters</h3><p>The makeRequestUint256() function expects the following parameters to make a valid request.</p><ul><li>airnode (address) and endpointIdUint256specify the endpoint. Get these from <a href="https://docs.api3.org/reference/qrng/providers.html">here</a>.</li><li><a href="https://docs.api3.org/reference/airnode/latest/concepts/sponsor.html#sponsorwallet">sponsorWallet</a> specifies which wallet will be used to fulfill the request.</li></ul><h3>Response Parameters</h3><p>The callback to the QrngRequester contains two parameters:</p><ul><li>requestId: First acquired when making the request and passed here as a reference to identify the request for which the response is intended.</li><li>data: In case of a successful response, this is the requested data that has been encoded and contains a <a href="https://docs.api3.org/ois/v1.1/reserved-parameters.html#timestamp-encoded-to-uint256-on-chain">timestamp</a> in addition to other response data. Decode it using the function decode() from the abi object to get your random number.</li></ul><p>Head to Remix IDE, make a contract, and paste it in the <a href="https://gist.github.com/vanshwassan/0b50c7b36b1e7ebed85549754578ed79#file-qrngrequester-sol">QrngRequester</a> code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xqIXsrezF-oEibrUXUCHBA.png" /></figure><p>Now, hit compile on the right side of the dashboard and compile the smart contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*NC2OnVs_WbJyQ1x92IWNWg.png" /></figure><h3>Deploying the Contract</h3><p>We are going to deploy our QrngRequester to Goerli. Make sure you have enough testnet ETH in your wallet to deploy the contract and fund the sponsorWallet later. You can get some testnet Goerli <a href="https://goerlifaucet.com/">here</a>.</p><p>Head to deploy, run Transactions, and select the “Injected Provider — MetaMask” option under Environment. Connect your MetaMask. Make sure you’re on Goerli.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*egGwfeoxm80f14aLRGPIgg.png" /></figure><p>The _rrpAddressis the main airnodeRrpAddress. The RRP contracts have already been deployed on-chain. You can check for your specific chain <a href="https://docs.api3.org/reference/qrng/chains.html">here</a>.</p><p>Once the _rrpAddress is populated, click on “Deploy.” Confirm the transaction on your MetaMask and wait for it to deploy the Requester contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*tBUez1T4eti5tznbrtg6Ew.png" /><figcaption>Make sure you’re on the Goerli Testnet</figcaption></figure><h3>Calling the Contract</h3><p>When your QrngRequester gets deployed, head to Deploy, run transactions, and click on the dropdown for your Requester under Deployed Contracts.</p><p>Now select the setRequestParameters dropdown to set all the parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*rbdNJXXxCsbS0YIEKhTppw.png" /></figure><p>Add the following to the corresponding fields for the function.</p><ul><li>_airnode: The airnode address of the desired QRNG service provider. See its value from the list of <a href="https://docs.api3.org/reference/qrng/providers.html">QRNG providers</a>.</li><li>_endpointIdUint256: The Airnode endpoint ID will return a single random number.</li><li>_sponsorWallet: A wallet derived from the requester contract address, the Airnode address, and the Airnode xpub. The wallet is used to pay gas costs to acquire a random number. A sponsor wallet must be derived using the command <a href="https://docs.api3.org/reference/airnode/latest/packages/admin-cli.html#derive-sponsor-wallet-address">derive-sponsor-wallet-address</a> from the Admin CLI. Use the value of the sponsor wallet address that the command outputs.</li></ul><p>After you’ve set up the Airnode CLI, installed and built all the dependencies and packages, run the following command to derive your _sponsorWallet:</p><h3>Linux</h3><pre>npx @api3/airnode-admin derive-sponsor-wallet-address \<br>  --airnode-xpub xpub6CUGRUo... \<br>  --airnode-address 0xe1...dF05s \<br>  --sponsor-address 0xF4...dDyu9</pre><h3>Windows</h3><pre>npx @api3/airnode-admin derive-sponsor-wallet-address ^<br>  --airnode-xpub xpub6CUGRUo... ^<br>  --airnode-address 0xe1...dF05s ^<br>  --sponsor-address 0xF4...dDyu9</pre><p>ANU’s airnode-addressand airnode-xpub can be found <a href="https://docs.api3.org/reference/qrng/providers.html">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*xYnxZk6fRmb5iNFtu5qGhg.png" /></figure><p>Fund the sponsorWallet with some test ETH. Click on transact button and confirm the transaction to set the parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*Tycn4l0Yqv5LWSmAcdjDrg.png" /></figure><p>To make the request, click on the makeRequestUint256 button to call the function and make a full request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*G6p3_QX0wYCvjRAMO_5G2Q.png" /></figure><p>Now you can head over to<a href="https://rinkeby.etherscan.io/"> </a><a href="https://goerli.etherscan.io/">https://goerli.etherscan.io/</a> and check your sponsorWallet for any new transactions.</p><p>You might need to wait for a while as the Airnode calls the fulfill() function in AirnodeRrpV0.sol that will in turn call back the requester contract at fulfillAddress using function fulfillFunctionId to deliver data(the random number).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMjxVn2BUXZeX3-KWGCS9A.png" /></figure><p>Here, we can see the latest Fulfill transaction.</p><p>Now go back to Remix and click on latestRequest button to check the response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*BcTgivXIHUHUxj6cmkQObQ.png" /></figure><p>If the callback has been successfully completed, the randomNumber will be present. The value of waitingFulfillment will be false.</p><p>If you want to learn more about it, check out the <a href="https://github.com/api3dao/qrng-example">QRNG Example Project</a>.</p><p>Read more about <a href="https://docs.api3.org/guides/qrng/">API3 QRNG</a>.</p><pre><strong>Want to Connect?</strong></pre><pre>Check out <a href="https://discord.com/invite/qnRrcfnm5W">API3’s Discord Server</a> and drop your queries there!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21be5bed5aba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/a-guide-to-using-anus-quantum-random-number-generator-in-your-smart-contracts-21be5bed5aba">A Guide to Using ANU’s Quantum Random Number Generator in Your Smart Contracts</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Call Any API From a Solidity Smart Contract, Part 2]]></title>
            <link>https://medium.com/better-programming/how-to-call-any-api-from-a-solidity-smart-contract-part-2-6552b6e2e174?source=rss-82dd8c0acd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6552b6e2e174</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Vansh Wassan]]></dc:creator>
            <pubDate>Wed, 14 Sep 2022 17:37:46 GMT</pubDate>
            <atom:updated>2023-05-11T11:07:00.328Z</atom:updated>
            <content:encoded><![CDATA[<h4>Making and deploying a Requester contract to request data from the Airnode</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*crNHRAgjWh9LoIFX" /><figcaption>Photo by <a href="https://unsplash.com/@theshubhamdhage?utm_source=medium&amp;utm_medium=referral">GuerrillaBuzz Crypto PR</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is the second part of the tutorial where we deploy the Requester Contract and request data from the <a href="https://docs.api3.org/explore/airnode/what-is-airnode.html">Airnode</a>. Check out the first part <a href="https://betterprogramming.pub/how-to-call-any-api-from-a-solidity-smart-contract-part-i-d1d2f34461b6">here</a>.</p><p>In Part I, we successfully integrated and deployed an Airnode through ChainAPI. Now we will code a simple Requester Contract to call and read data from our Airnode.</p><p>Before starting, make sure you set up the <a href="https://github.com/api3dao/airnode">Airnode Monorepo</a> on your system. Follow through the Readme to install and build all the dependencies and packages to be able to access the Airnode CLI.</p><p>Clone the Airnode Monorepo.</p><pre>$ git clone <a href="https://github.com/api3dao/airnode.git">https://github.com/api3dao/airnode.git</a> .</pre><p>To install the dependencies,</p><pre>$ yarn run bootstrap</pre><p>To build all the packages,</p><pre>$ yarn run build</pre><p><em>An Airnode is a first-party oracle that pushes off-chain API data to your on-chain contract. It makes a request to the on-chain </em><a href="https://docs.api3.org/reference/airnode/latest/concepts/"><em>RRP protocol contract</em></a><em> (</em><a href="https://docs.api3.org/reference/airnode/latest/concepts/#airnoderrpv0-sol"><em>AirnodeRrpV0.sol</em></a><em>) that adds the request to the event logs. The off-chain Airnode then accesses the event logs, gets the API data and performs a callback to the requester.</em></p><figure><img alt="https://docs.api3.org/airnode/v0.8/grp-developers/" src="https://cdn-images-1.medium.com/max/1024/0*JDASappLaTk5nA9p.png" /><figcaption><a href="https://docs.api3.org/airnode/v0.8/grp-developers/">https://docs.api3.org/airnode/v0.8/grp-developers/</a></figcaption></figure><p>A <a href="https://docs.api3.org/reference/airnode/latest/concepts/requester.html"><em>Requester</em></a><em> </em>is a contract that triggers an Airnode request. To do so, the requester needs to be sponsored and make the request using a matching sponsor wallet.</p><p>The Requester then calls the protocol contract, which emits a blockchain event with the request parameters. Airnode listens to the events emitted by the <em>AirnodeRrpV0</em> contract. During the next run cycle, Airnode gets the request parameters from the emitted event.</p><h3>Coding Requester.sol</h3><p>The Requester Contract will have two main functions, makeRequest() and fulfill(). The makeRequest() function will call the makeFullRequest() function of the AirnodeRrpV0.sol protocol contract which adds the request to its storage. The targeted off-chain Airnode gathers the request from <em>AirnodeRrpV0.sol</em>’s storage and responds using the fulFill() function of <em>AirnodeRrpV0.sol</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f514a1fde5cfcb63220f0a496304d8a9/href">https://medium.com/media/f514a1fde5cfcb63220f0a496304d8a9/href</a></iframe><h3>Request Parameters</h3><p>The makeRequest() function expects the following parameters to make a valid request.</p><ul><li>airnode (address) and endpointId specify the endpoint.</li><li>sponsor and sponsorWallet (addresses) specify which wallet will be used to fulfill the request.</li><li>parameters specify the API and <a href="https://docs.api3.org/reference/ois/latest/reserved-parameters.html">Reserved Parameters</a> (see Airnode ABI <a href="https://docs.api3.org/reference/ois/latest/specification.html">specifications</a> for how these are encoded) We will encode the parameters off-chain using @airnode-abi library.</li></ul><h3>Response Parameters</h3><p>The callback to the <em>Requester </em>contains two parameters:</p><ul><li><strong>requestId</strong>: First acquired when making the request and passed here as a reference to identify the request for which the response is intended.</li><li><strong>data</strong>: In case of a successful response, this is the requested data which has been encoded and contains a timestamp in addition to other response data. Decode it using the function decode() from the abi object.</li></ul><h3>Compiling the Contract</h3><p>To deploy the Requester Contract, we are going to use <a href="https://remix.ethereum.org/">Remix IDE</a>. It’s an online IDE that allows developing, deploying and administering smart contracts for EVM Compatible Blockchains.</p><p>Make a contract and paste in the <a href="https://github.com/vanshwassan/AirnodeTutorials/blob/master/Contracts/Requester.sol">Requester.sol</a> code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iOh6xK45pBF8MX9YvXBt1A.png" /></figure><p>Now hit compile on the right side of the dashboard and compile the Smart Contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*A0SBboW_fTyAC45ws65O2Q.png" /></figure><p>Now we are all set to deploy our Requester.</p><h3>Deploying the Requester</h3><p>As we are going to deploy the contract on Polygon Mumbai Testnet, make sure you have enough MATIC in your wallet to deploy the Requester and then fund the sponsorWallet later. You can get some from the <a href="https://mumbaifaucet.com/">Mumbai Faucet</a>.</p><p>Head to Deploy and run Transactions and select Injected Provider — MetaMask option under Environment. Connect your MetaMask. Make sure you’re on Mumbai Testnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*h34LOQkc5WIAt5l_cWbJ-A.png" /></figure><p>The _rrpAddressis the main <em>airnodeRrpAddress. </em>The RRP Contracts have already been deployed on-chain. You can check for your specific chain <a href="https://docs.api3.org/reference/airnode/latest/">here</a>.</p><p>Fill in the _rrpAddress and click on Deploy. Confirm the transaction on your MetaMask and wait for it to deploy the Requester Contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*WMB8sP2JDG6XF4XrrTFWog.png" /><figcaption>Make sure you’re on the Polygon Mumbai Testnet</figcaption></figure><h3>Calling the Requester</h3><p>When your Contract gets deployed, head to Deploy &amp; run transactions and click on the dropdown for your Requester under Deployed Contracts.</p><p>Now select the makeRequest dropdown to see all the parameters you need to pass in order to make a full request to the Airnode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*3uaFU21-HM1n8EZVXKxU4A.png" /></figure><p>Here, you need to pass in your airnode(Airnode address), endpointID, sponsor(The Requester itself),sponsorWalletand parameters in order to call the makeRequest() function.</p><p>We can find the airnode in the receipt.json under the output directory obtained when we deployed our Airnode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-k9a8EhOFqTbusum7DxMPA.png" /></figure><p>The endpointID can be found under the config.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ha0EzXURgRHKFK74vnLvPA.png" /></figure><p>We need to derive the sponsorWallet through the Airnode CLI command that will make the actual call. We also need to fund it with some MATIC to cover the gas cost.</p><p>After you’ve setup the Airnode CLI and installed and built all the dependencies and packages, run the following command to derive your sponsorWallet :</p><h4>Linux:</h4><pre>npx @api3/airnode-admin derive-sponsor-wallet-address \<br>  --airnode-xpub xpub6CUGRUo... \<br>  --airnode-address 0xe1...dF05s \<br>  --sponsor-address 0xF4...dDyu9</pre><h4>Windows:</h4><pre>npx @api3/airnode-admin derive-sponsor-wallet-address ^<br>  --airnode-xpub xpub6CUGRUo... ^<br>  --airnode-address 0xe1...dF05s ^<br>  --sponsor-address 0xF4...dDyu9</pre><p>Your airnode-addressand airnode-xpub (The <em>Airnode’s</em> extended public key) can be found in the same receipt.json. The sponsor-address will be the address of the Requester contract itself (the one that you just deployed).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*Tl_4usi_XHOZSH65lrdJew.png" /></figure><p>Run the command to obtain your sponsorWallet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*cMWyikM8lIAxGk6YEGtd-g.png" /></figure><p>Fund the sponsorWallet with some test MATIC.</p><p>The parameters are required to be encoded in bytes32 before you send it. We are going to use the @airnode-abi library for encoding the parameters off-chain and then sending it to the Requester.</p><p>You can set it up by cloning <a href="https://github.com/vanshwassan/AirnodeTutorials">this tutorial’s repository</a>.</p><p>Run the following command to get your encoded parameters :</p><pre>node .\src\encodeParams.js</pre><p>Now you have all the parameters that you require to run the makeRequest function. Populate all the fields and click on Transact.</p><p><em>Note: The </em><em>sponsor here will be the address of the Requester Contract that you just deployed.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*buQhbSCE-pq9hAibHbIOmA.png" /></figure><p>Click on transact, confirm the transaction on MetaMask and wait for the transaction to complete.</p><p>Now you can head over to <a href="https://mumbai.polygonscan.com/">https://mumbai.polygonscan.com</a> and check your sponsorWallet for any new transactions.</p><p><em>You might need to wait for a while as the Airnode calls the </em><em>fulfill() function in AirnodeRrpV0.sol that will in turn call back the requester contract at </em><em>fulfillAddress using function </em><em>fulfillFunctionId to deliver </em><em>data.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NnNht40SsIYsKEkNW45DvA.png" /></figure><p>Here, we can see the latest <em>Fulfill</em> transaction.</p><p>Now go back on Remix and check for requestId under logs for the latest transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Km2hDmwINDqShb1PlnXXug.png" /></figure><p>You can also find your requestId under logs in the Polygon Mumbai Block Explorer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ula12KPb0Ykl1NjhhD3z_A.png" /></figure><p>Copy your requestId and paste it on under the fulfilledData method to decode the response. Click on call and you will see the API response. Here, we requested Tesla’s Stock price.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*dgVH5M1HlJb-AAwfTao9Hw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*AZ3OgEd9QKtVnPql1hifXA.png" /></figure><p>Now you successfully deployed an Airnode and made a Requester Contract to read data from it. You can also refer to <a href="https://github.com/vanshwassan/AirnodeTutorials">this Repo</a> for all the code that I’ve used for this tutorial.</p><p>Thanks for reading.</p><pre><strong>Any questions? </strong></pre><pre>Check out <a href="https://discord.com/invite/qnRrcfnm5W"><strong>API3’s Discord Server</strong></a> and drop your queries there!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6552b6e2e174" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-call-any-api-from-a-solidity-smart-contract-part-2-6552b6e2e174">How to Call Any API From a Solidity Smart Contract, Part 2</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Call Any API From a Solidity Smart Contract, Part I]]></title>
            <link>https://medium.com/better-programming/how-to-call-any-api-from-a-solidity-smart-contract-part-i-d1d2f34461b6?source=rss-82dd8c0acd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1d2f34461b6</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Vansh Wassan]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 12:40:43 GMT</pubDate>
            <atom:updated>2023-05-11T04:47:10.782Z</atom:updated>
            <content:encoded><![CDATA[<h4>Deploying an Airnode to get off-chain data in your Smart Contract</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2d5gcBSZlu3F6ICJ" /><figcaption>Photo by <a href="https://unsplash.com/@deepmind?utm_source=medium&amp;utm_medium=referral">DeepMind</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As we all know that it is not possible by a Smart Contract to directly access external APIs outside of a blockchain. Interacting with off-chain data while working with Smart Contracts is a real problem for a lot of dApps.</p><blockquote>The Ethereum blockchain was designed to be entirely deterministic while the Internet was not. Calling an API directly sounds easy but on a blockchain, it would require all the nodes to call the same endpoint at the same time and expect to get the same data in order to come to a consensus. Plus, the core concept of a blockchain is its security, that is derived from a decentralized network of independent validators that purposefully limit their connection to the outside world.</blockquote><p>However, with <a href="https://api3.org/">API3</a>, you can have first-party oracles that are directly operated by the API Providers, called <a href="https://docs.api3.org/explore/airnode/what-is-airnode.html">Airnodes</a> that provides data to any on-chain dApp<em>. </em>As a result, you can easily make any REST API accessible to a Smart Contract.</p><h3>Say Hello to ChainAPI</h3><p><a href="https://bit.ly/Va-Part1-Polygon-ChainAPI">ChainAPI</a> is a platform that enables you to integrate and deploy the open-source Airnode with its step-by-step integration and deployment tools.</p><p>To get started, go to <a href="https://bit.ly/Va-Part1-Polygon-ChainAPI">ChainAPI</a> and log in by connecting your MetaMask.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/0*135nPlhwqamY3-zY" /></figure><p>You will be prompted to confirm and sign the transaction through your MetaMask extension.</p><p>Make sure you’re using a new MetaMask Wallet with a fresh mnemonic. Your mnemonic will later be used to deploy the Airnode. You need to keep it extremely safe as this will serve as the “private key” of your deployed Airnode.</p><p><em>Each time you return to ChainAPI you will connect again, using MetaMask, to identify yourself by signing a message for the same account.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*-v8l867Nje8Fgb9wgcIHzw.png" /></figure><p>Complete the signup process and name your workspace.</p><p><em>Workspaces provides you with a way to invite other users to help or collaborate with integrations and deployments. This makes it easy to manage your Airnodes as a team or to outsource the process while still maintaining control over your integrations and deployments.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/0*D9FbnKKEeM3U82vb" /></figure><p><em>To change the name of your workspace in the future, click on name on the top-left of the dashboard</em></p><p>Within ChainAPI you will be able to create and manage your integrations or Airnode deployments by navigating to the “Integrations” or “Deploy” dashboards on the left hand navigation panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xEsNLFmPTUO7ULPQ" /></figure><h4>Integrating your Airnode</h4><p>For this tutorial, I am going to use <a href="https://bit.ly/3TwKnQI">dxFeed’s public REST API</a> endpoints to retrieve stock data.</p><p>To get started select the “Integrate API” option in the top right hand of the dashboard.</p><p>Enter the details about the API you want to Integrate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/0*UUoWo8dgZX4UdjWj" /></figure><p>You need to enter the base URL of your API along with all the endpoints that you want to integrate. If your API requires any security scheme (API Key, Basic HTTP Auth) you have the option to add that too.</p><p>As it’s a public API, it doesn’t have any security schemes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/0*GrYQa8tGB8PisfDM" /></figure><p>You can now start by adding all your endpoints.</p><p>Here, the dxFeed REST API has one GET endpoint /events.json with some query parameters. You can add all the parameters that your API requires.</p><p>The parameters that are required by dxFeed’s API are:</p><ul><li>events — Query Parameter — Takes in the market event. It will be user defined.</li><li>symbols — Query Parameter — Takes in the stock ticker symbol. It will be user defined.</li></ul><p>For more information about dxFeed’s API and how it works, <a href="https://tools.dxfeed.com/webservice/rest-demo.jsp">click here</a> to test out their API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*PnjLKrxFdcerKRlIzPFY_g.png" /></figure><p>Now you need to add all the parameters and define where they go (query/header/path/cookie). You can also decide if you want their values fixed or not.</p><p>Here, the dxFeed REST API has one GET endpoint /events.json with some query parameters. You can add all the parameters that your API requires.</p><p><a href="https://docs.api3.org/reference/ois/latest/reserved-parameters.html">Reserved parameters</a> define what part of the response is to be picked and encoded before fulfillment. It can be defined by the requester but we can also hardcode it in the Airnode configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ax-C3u0OzPQSgOs8" /></figure><p>You can also add <a href="https://docs.api3.org/reference/ois/latest/processing.html">pre and post-processing snippets</a> for your Airnode. Although we won’t be using this feature with this integration.</p><ul><li><a href="https://docs.api3.org/reference/ois/latest/specification.html#_5-9-preprocessingspecifications">Pre-processing</a> snippets are executed before making the request to the Airnode.</li><li><a href="https://docs.api3.org/reference/ois/latest/specification.html#_5-10-postprocessingspecifications">Post-processing</a> snippets are executed after receiving the response from the Airnode.</li></ul><p>After adding all the required endpoints, you can now press finish and get ready to deploy your Airnode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/0*9AF-rwD_ud2kAf75" /></figure><h4>Deploying your Airnode</h4><p>To deploy the Airnode, go to the deploy section on the menu. Name your deployment and select the integration that you want to use with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/0*ZgK_WRkE_XQRtgGJ" /></figure><p>Select your Cloud Provider where you want your Airnode to be deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sr-ngqDgK2wxN9B_JaLoxQ.png" /></figure><p>Now select the Chains for your deployment. You can also select multiple networks and providers if you want it on multiple Chains.</p><p>Here, we are going to have our Airnode on the Polygon Mumbai Testnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFdzGEys6RIw6AZAp2JYqQ.png" /></figure><p><a href="https://docs.api3.org/reference/airnode/latest/concepts/authorizers.html">Authorizer</a> contracts allow you to specify which smart contracts can make requests to your Airnode’s endpoints. For this tutorial, we are just going to set it as Public.</p><p>When an Airnode receives a request, it can use on-chain authorizer contracts to verify if a response is warranted. This allows the Airnode to implement a wide variety of policies and to authorize requester contract access to its underlying API.</p><ul><li>Public Authorizers will allow any smart contract to make requests to your Airnode.</li><li>Restricted Authorizers will only allow smart contract addresses that have been granted access to make requests to your Airnode.</li></ul><p><a href="https://docs.api3.org/reference/airnode/latest/concepts/authorizers.html">Click here to learn more about Authorizations.</a></p><p>Review your configuration for one final time. If everything seems correct, click on next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*YYS4QaLfdWI8RuyJ" /></figure><p>Download all the Airnode configuration files and extract them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*GDIIGLavatCbh33I" /></figure><p>This is what your Airnode config directory should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*SqysW0CmYa_8azbB" /></figure><p>config<em> </em>contains config.json and secrets.env.</p><ul><li>The config.json file is used during the deployment/redeployment of an Airnode to configure its behavior and to provide mappings of API operations.</li><li>The secrets.env file holds values for config.json that must be kept secret.</li></ul><p>The output directory will have the receipt.json that will be generated after you successfully deploy the Airnode.</p><p>The aws.env file holds AWS credentials for deployments targeted to AWS.</p><p><em>As we are using AWS as our cloud provider, we need to add our AWS IAM Access Keys with the Administrator Access policy. You can refer to this </em><a href="https://www.youtube.com/watch?v=KngM5bfpttA"><em>video</em></a><em> if you are not sure how to obtain them.</em></p><p>The README.md contains all the steps to deploy the Airnode provided in a markdown format.</p><p>Open aws.env and add your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY that you just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*4KWNLu2t-JEvJugQcTb4Mw.png" /></figure><p>Open config/secrets.env<em> </em>and add your wallet mnemonic. Make sure you keep it extremely safe as this will serve as the “private key” of your deployed Airnode. From the mnemonic phrase, Airnode is able to assign wallet addresses to both the Airnode instance and its users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*StjSe291ojNheWeotTBfPg.png" /></figure><p>You also need to add your Blockchain Provider URL. Here, we are going to use Alchemy for a free Polygon Mumbai Testnet Provider URL. You can use any blockchain provider that supports your network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*LwibimEzWAdfwAWz5lUY5A.png" /></figure><p>You can also set-up your <a href="https://docs.api3.org/reference/airnode/latest/understand/http-gateways.html"><em>HttpGateway</em></a><em> </em>credentials. It’s an optional service that allows authenticated users to make HTTP requests to your deployed Airnode instance for testing. ChainAPI has already generated these keys for you but you can change them if you want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*wJNFvs_UmCfd1vfL1wpL3A.png" /></figure><p>One final step before deploying your Airnode is to set <a href="https://docs.api3.org/reference/airnode/latest/concepts/authorizers.html">Authorizers</a> in the <em>config.json</em> file.</p><p><em>When an Airnode receives a request, it can use on-chain authorizer contracts to verify if a response is warranted. This allows the Airnode to implement a wide variety of policies and to authorize requester contract access to its underlying API.</em></p><p>For the scope of this tutorial, we can set the authorizer array empty in <em>config.json</em> so that any requester contract can access the Airnode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*a9kG6ZyESgSdbqw5uyZaJg.png" /></figure><p>Now you’re ready to deploy your Airnode. Make sure you have <a href="https://www.docker.com/">Docker</a> installed on your system.</p><p>Copy and paste the commands below to your terminal at the root directory of your deployment package.</p><p>Windows</p><pre>docker run -it --rm ^<br>      --env-file aws.env ^<br>      -v &quot;%cd%/config:/app/config&quot; ^<br>      -v &quot;%cd%/output:/app/output&quot; ^<br>      api3/airnode-deployer:0.7.3 deploy</pre><p>OSX</p><pre>docker run -it --rm \<br>      --env-file aws.env \<br>      -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) \<br>      -v &quot;$(pwd)/config:/app/config&quot; \<br>      -v &quot;$(pwd)/output:/app/output&quot; \<br>      api3/airnode-deployer:0.7.3 deploy</pre><p>Linux</p><pre>docker run -it --rm \<br>      --env-file aws.env \<br>      -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) \<br>      -v &quot;$(pwd)/config:/app/config&quot; \<br>      -v &quot;$(pwd)/output:/app/output&quot; \<br>      api3/airnode-deployer:0.7.3 deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/0*KZ8A_iw2ws-5Duig" /></figure><p>Your Airnode should now be deployed. You can check its status in the deployment section.</p><p>Check out the GitHub Repo for this guide <a href="https://github.com/vanshwassan/AirnodeTutorials/">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KtPyklodLfrFv-IW" /></figure><p>In the <a href="https://betterprogramming.pub/how-to-call-any-api-from-a-solidity-smart-contract-part-2-6552b6e2e174">part 2</a>, we will show you how to code a Requester contract to call and read the data from the Airnode.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1d2f34461b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-call-any-api-from-a-solidity-smart-contract-part-i-d1d2f34461b6">How to Call Any API From a Solidity Smart Contract, Part I</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>