{"id":27884,"date":"2022-03-23T22:37:18","date_gmt":"2022-03-23T22:37:18","guid":{"rendered":"http:\/\/Handling-Orders-using-Web3-and-Ethereum"},"modified":"2022-03-23T22:37:18","modified_gmt":"2022-03-23T22:37:18","slug":"handling-orders-using-web3-and-ethereum","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/","title":{"rendered":"Handling Orders using Web3 and Ethereum"},"content":{"rendered":"<div class=\"wp-block-cloudinary-markdown \"><p>One of the big draws to blockchain is that you can execute large financial transactions in minutes instead of days or weeks. One day, you could be able to sell your house in 15 minutes and all of the ownership information will be stored securely on the blockchain.<\/p>\n<p>That\u2019s why we\u2019re going to build a small ordering Dapp to show how this concept works. We\u2019ll create a Dapp that lets users create orders on the blockchain, including payments. All of this will be neatly wrapped in a Redwood app and use Cloudinary for our image hosting.<\/p>\n<h2>Setting up the Tools<\/h2>\n<p>There are a few things we need to install before we touch the code. First, you\u2019ll need to install <a href=\"https:\/\/www.trufflesuite.com\/ganache\">Ganache<\/a>. This is a free app that lets us develop smart contracts and Dapps against a local Ethereum network. That way we don\u2019t have to worry about paying for transactions on the blockchain.<\/p>\n<p>Next, we\u2019ll actually create the Redwood app we\u2019ll use for our Dapp. In a terminal, run the following command:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">$ yarn create redwood-app order-dapp\n<\/code><\/span><\/pre>\n<p>This will generate the front-end code in the <code>web<\/code> directory and back-end code in the <code>api<\/code> directory we\u2019ll need to make this app. There are just a couple more things we need to install. In your terminal, go to the <code>web<\/code> directory and install these packages.<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">$ yarn add truffle truffle-contract web3\n<\/code><\/span><\/pre>\n<p>These three packages are going to help us interact with the local Ethereum network with our smart contract and also the front-end. Now we have everything installed and set up so we can dive into writing a smart contract.<\/p>\n<h2>Writing a Smart Contract with Solidity<\/h2>\n<p>We\u2019re going to use Truffle to set up our smart contract. So in your terminal go to the <code>web<\/code> directory and run the following command:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">$ truffle init\n<\/code><\/span><\/pre>\n<p>This will create a new <code>contracts<\/code> folder inside the <code>web<\/code> directory. If you take a look in the <code>contracts<\/code> folder, you\u2019ll see an initial smart contract called <code>Migrations.sol<\/code>.<\/p>\n<p>It sets the owner of the smart contract to the address that deploys it and gives us access to some restricted functionality for the smart contract.<\/p>\n<p>Now we\u2019ll be making our own smart contract with the functionality to handle the orders users want to make. That way you\u2019ll see some of the differences in blockchain development instead of back-end development.<\/p>\n<p>We need to make a config file to handle the connections to the local EVM. In the <code>web<\/code> directory add or update the <code>truffle-config.js<\/code> file. In this file, add the following code:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-attr\">networks<\/span>: {\n    <span class=\"hljs-attr\">development<\/span>: {\n      <span class=\"hljs-attr\">host<\/span>: <span class=\"hljs-string\">\"127.0.0.1\"<\/span>,\n      <span class=\"hljs-attr\">port<\/span>: <span class=\"hljs-number\">7545<\/span>,\n      <span class=\"hljs-attr\">network_id<\/span>: <span class=\"hljs-string\">\"*\"<\/span>,\n    },\n  },\n  <span class=\"hljs-attr\">compilers<\/span>: {\n    <span class=\"hljs-attr\">solc<\/span>: {\n      <span class=\"hljs-attr\">optimizer<\/span>: {\n        <span class=\"hljs-attr\">enabled<\/span>: <span class=\"hljs-literal\">true<\/span>,\n        <span class=\"hljs-attr\">runs<\/span>: <span class=\"hljs-number\">200<\/span>\n      },\n    }\n  },\n};\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>The <code>networks<\/code> object defines the connection to the local EVM network. You can get all of this info from the server settings in Ganache, but these are the default values. We have enabled the optimizer for the compiler to make our smart contract run smoother.<\/p>\n<p>That\u2019s all we need to connect to the network!<\/p>\n<h2>Working with a smart contract on the Ethereum network<\/h2>\n<p>In the <code>contracts<\/code> folder, add a new file called <code>OrderMaker.sol<\/code>. This is where we\u2019ll define the function to add orders to the blockchain and make orders accessible to our Dapp.<\/p>\n<p>Open this file and add the following line:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-tag\">pragma<\/span> <span class=\"hljs-selector-tag\">solidity<\/span> ^0<span class=\"hljs-selector-class\">.5<\/span><span class=\"hljs-selector-class\">.0<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Every smart contract starts with the version we\u2019re using for the compiler. Then we\u2019ll define the contract itself.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-tag\">contract<\/span> <span class=\"hljs-selector-tag\">OrderMaker<\/span> {\n\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>There are some similarities between Solidity and JavaScript and a little C++. You\u2019ll see them as we fill in this contract. Inside the contract, let\u2019s add a struct that defines the order.<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">struct Order {\n  string itemName;\n  uint256 price;\n  uint256 quantity;\n}\n<\/code><\/span><\/pre>\n<p>This is very similar to an interface in TypeScript. It\u2019s a type that defines the data we expect in an order. Next, we\u2019ll initialize a global array that holds all of the orders for the smart contract.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-tag\">Order<\/span><span class=\"hljs-selector-attr\">&#91;]<\/span> <span class=\"hljs-selector-tag\">private<\/span> <span class=\"hljs-selector-tag\">orders<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>This is a <code>private<\/code> variable which means it can\u2019t be accessed outside of the contract. Then we\u2019ll add a constructor that creates an initial order on the blockchain.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">constructor<\/span>() public {\n  _createOrder(<span class=\"hljs-string\">'Jalapeno'<\/span>, <span class=\"hljs-number\">9<\/span>, <span class=\"hljs-number\">3<\/span>);\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>A constructor in a smart contract only gets executed one time, when the contract is deployed to the network. There are a few things that we\u2019ll define before we get to the <code>_createOrder<\/code>, but it\u2019s coming up.<\/p>\n<p>For now, let\u2019s define a couple of mappings for the orders that can be accessed outside of the contract like in our Dapp.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">mapping(<span class=\"hljs-function\"><span class=\"hljs-params\">address<\/span> =&gt;<\/span> Order) public ordersByUser;\nmapping(<span class=\"hljs-function\"><span class=\"hljs-params\">uint256<\/span> =&gt;<\/span> Order) public ordersById;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>A mapping in Solidity is like an object in JavaScript. An example of the <code>ordersById<\/code> mapping would look like this in JavaScript.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">let<\/span> ordersById = {\n  <span class=\"hljs-number\">1<\/span>: {\n    <span class=\"hljs-attr\">itemName<\/span>: <span class=\"hljs-string\">'Jalapeno'<\/span>,\n    <span class=\"hljs-attr\">price<\/span>: <span class=\"hljs-number\">9<\/span>,\n    <span class=\"hljs-attr\">quantity<\/span>: <span class=\"hljs-number\">4<\/span>\n  },\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>After these mappings, we need to make a helper function to get the price of the items in the orders users make. This will introduce an interesting thing with Solidity.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">_lookupPrice<\/span>(<span class=\"hljs-params\">string memory _itemName<\/span>)\n  <span class=\"hljs-title\">private<\/span>\n  <span class=\"hljs-title\">pure<\/span>\n  <span class=\"hljs-title\">returns<\/span> (<span class=\"hljs-params\">uint256 price<\/span>)\n<\/span>{\n  <span class=\"hljs-keyword\">if<\/span> (\n    keccak256(abi.encodePacked(_itemName)) ==\n    keccak256(abi.encodePacked(<span class=\"hljs-string\">'Jalapeno'<\/span>))\n  ) {\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">9<\/span>;\n  } <span class=\"hljs-keyword\">else<\/span> <span class=\"hljs-keyword\">if<\/span> (\n    keccak256(abi.encodePacked(_itemName)) ==\n    keccak256(abi.encodePacked(<span class=\"hljs-string\">'Feta'<\/span>))\n  ) {\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">12<\/span>;\n  } <span class=\"hljs-keyword\">else<\/span> <span class=\"hljs-keyword\">if<\/span> (\n    keccak256(abi.encodePacked(_itemName)) ==\n    keccak256(abi.encodePacked(<span class=\"hljs-string\">'Water'<\/span>))\n  ) {\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">18<\/span>;\n  } <span class=\"hljs-keyword\">else<\/span> <span class=\"hljs-keyword\">if<\/span> (\n    keccak256(abi.encodePacked(_itemName)) ==\n    keccak256(abi.encodePacked(<span class=\"hljs-string\">'Lemon'<\/span>))\n  ) {\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">15<\/span>;\n  } <span class=\"hljs-keyword\">else<\/span> {\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">5<\/span>;\n  }\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>If you take a look, we\u2019re comparing strings to decide what price to return. In Solidity, there\u2019s no direct way to handle string comparison. That\u2019s why we have all of the <code>keccak256(abi.encodePacked(_itemName)) == keccak256(abi.encodePacked('Jalapeno'))<\/code> statements. It compares the hashes of the strings and is how we handle string comparison in Solidity smart contracts.<\/p>\n<p><em>Now<\/em> we can define that function we called in the constructor to add an initial order.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">_createOrder<\/span>(<span class=\"hljs-params\">\n  string memory _itemName,\n  uint256 _quantity,\n  uint256 _price\n<\/span>) <span class=\"hljs-title\">internal<\/span> <\/span>{\n  orders.push(Order(_itemName, _price, _quantity));\n\n  uint256 id = orders.length;\n\n  ordersByUser&#91;msg.sender] = orders&#91;id - <span class=\"hljs-number\">1<\/span>];\n\n  ordersById&#91;id] = orders&#91;id - <span class=\"hljs-number\">1<\/span>];\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>This is an internal function which means only this contract and contracts that inherit this one can call this <code>_createOrder<\/code> function. We pass in the three inputs needed to make a new order. Then we add the new order to the private <code>orders<\/code> array, get an id, and add the order to our public mappings.<\/p>\n<p>The last thing to add is the function that lets users create orders from our Dapp.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">createOrder<\/span>(<span class=\"hljs-params\">string memory _itemName, uint256 _quantity<\/span>) <span class=\"hljs-title\">public<\/span> <span class=\"hljs-title\">payable<\/span> <\/span>{\n  <span class=\"hljs-built_in\">require<\/span>(msg.value == <span class=\"hljs-number\">0.001<\/span> ether);\n  uint256 itemPrice = _lookupPrice(_itemName);\n  _createOrder(_itemName, _quantity, itemPrice);\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>One important thing to note is that this function has the <code>payable<\/code> modifier. That means a user is able to send a payment along with their request. This is part of what makes blockchain technology so interesting. It\u2019s the only way to securely send money with online transactions.<\/p>\n<p>Can you imagine trying to send money along with an API request? That\u2019s one of the problems blockchain solves.<\/p>\n<h3>Deploying the Smart Contract to the Local EVM<\/h3>\n<p>We have the <code>truffle-config.js<\/code> file in <code>web<\/code> which sets up the connection to the local Ethereum network. If you\u2019re running Ganache like we set up earlier, these are the network defaults. This is also where you would define connections to test networks or the real Ethereum network.<\/p>\n<p>With this config file updated and the smart contracts written, we can deploy these contracts to the local EVM. In your terminal in the <code>web<\/code> directory, run this command:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">$ truffle migrate\n<\/code><\/span><\/pre>\n<p>You should see some output in your terminal that tells you about the smart contracts you just deployed. Make sure that you get the <code>contract address<\/code> for the <code>OrderMaker<\/code> contract. We\u2019ll need that to connect the Dapp to this smart contract.<\/p>\n<p>You\u2019ve deployed a smart contract to the EVM! All that\u2019s left is creating the front-end code and giving users access to the functionality of the smart contract.<\/p>\n<h2>Building the Front-end<\/h2>\n<p>In your terminal, go to the root of the project and run the following command:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">$ yarn redwood generate page order\n<\/code><\/span><\/pre>\n<p>This will create a new directory called <code>OrderPage<\/code> in <code>web &gt; src &gt; pages<\/code>. In this new folder, you\u2019ll see several files: a test file, a <a href=\"https:\/\/storybook.js.org\/\">Storybook<\/a> story, and the component file. Open the <code>OrderPage.tsx<\/code> file. This is where we\u2019ll make the user interface.<\/p>\n<p>Before we do that, there\u2019s one more config file we need to set up to access the smart contract on our local Ethereum network.<\/p>\n<h3>Adding the Config File<\/h3>\n<p>In the <code>web &gt; src<\/code> directory, add a new file called <code>config.tsx<\/code>. We\u2019ll have two variables in this file. The first will be the address for the smart contract we deployed. At the top of your file, add the following code but be sure to use your contract address:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">const<\/span> ORDER_MAKER_ADDRESS = <span class=\"hljs-string\">'0x369B41C6951B712e0Cb9c3e13E2737999Ef202c2'<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>The next variable we need to add is the ABI (application binary interface) for the smart contract. When you deployed the smart contract a couple of steps back, the <code>web &gt; build &gt; contracts<\/code> directory was added. In this directory, you\u2019ll find <code>OrderMaker.json<\/code>.<\/p>\n<p>Open that file and copy the <code>abi<\/code> value and add it to the <code>config.tsx<\/code> file with our address. The code will look like this:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">const<\/span> ORDER_MAKER_ABI: any = &#91;\n  {\n    <span class=\"hljs-string\">\"constant\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\n    <span class=\"hljs-string\">\"inputs\"<\/span>: &#91;\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"uint256\"<\/span>\n      }\n    ],\n    <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"ordersById\"<\/span>,\n    <span class=\"hljs-string\">\"outputs\"<\/span>: &#91;\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"itemName\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"string\"<\/span>\n      },\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"price\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"uint256\"<\/span>\n      },\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"quantity\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"uint256\"<\/span>\n      }\n    ],\n    <span class=\"hljs-string\">\"payable\"<\/span>: <span class=\"hljs-literal\">false<\/span>,\n    <span class=\"hljs-string\">\"stateMutability\"<\/span>: <span class=\"hljs-string\">\"view\"<\/span>,\n    <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"function\"<\/span>,\n    <span class=\"hljs-string\">\"signature\"<\/span>: <span class=\"hljs-string\">\"0x2c4cb11a\"<\/span>\n  },\n  {\n    <span class=\"hljs-string\">\"constant\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\n    <span class=\"hljs-string\">\"inputs\"<\/span>: &#91;\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"address\"<\/span>\n      }\n    ],\n    <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"ordersByUser\"<\/span>,\n    <span class=\"hljs-string\">\"outputs\"<\/span>: &#91;\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"itemName\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"string\"<\/span>\n      },\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"price\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"uint256\"<\/span>\n      },\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"quantity\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"uint256\"<\/span>\n      }\n    ],\n    <span class=\"hljs-string\">\"payable\"<\/span>: <span class=\"hljs-literal\">false<\/span>,\n    <span class=\"hljs-string\">\"stateMutability\"<\/span>: <span class=\"hljs-string\">\"view\"<\/span>,\n    <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"function\"<\/span>,\n    <span class=\"hljs-string\">\"signature\"<\/span>: <span class=\"hljs-string\">\"0x933f7ae8\"<\/span>\n  },\n  {\n    <span class=\"hljs-string\">\"inputs\"<\/span>: &#91;],\n    <span class=\"hljs-string\">\"payable\"<\/span>: <span class=\"hljs-literal\">false<\/span>,\n    <span class=\"hljs-string\">\"stateMutability\"<\/span>: <span class=\"hljs-string\">\"nonpayable\"<\/span>,\n    <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"constructor\"<\/span>,\n    <span class=\"hljs-string\">\"signature\"<\/span>: <span class=\"hljs-string\">\"constructor\"<\/span>\n  },\n  {\n    <span class=\"hljs-string\">\"constant\"<\/span>: <span class=\"hljs-literal\">false<\/span>,\n    <span class=\"hljs-string\">\"inputs\"<\/span>: &#91;\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"_itemName\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"string\"<\/span>\n      },\n      {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"_quantity\"<\/span>,\n        <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"uint256\"<\/span>\n      }\n    ],\n    <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"createOrder\"<\/span>,\n    <span class=\"hljs-string\">\"outputs\"<\/span>: &#91;],\n    <span class=\"hljs-string\">\"payable\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\n    <span class=\"hljs-string\">\"stateMutability\"<\/span>: <span class=\"hljs-string\">\"payable\"<\/span>,\n    <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"function\"<\/span>,\n    <span class=\"hljs-string\">\"signature\"<\/span>: <span class=\"hljs-string\">\"0x97de706f\"<\/span>\n  }\n]\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Think of the contract address as the API we would connect to and the ABI is like the definition for the functions and parameters we\u2019re able to interact with. Now we can work on the <code>OrderPage<\/code> component.<\/p>\n<h2>Making the Order Page<\/h2>\n<p>We generated our page earlier so you can open the <code>OrderPage.tsx<\/code> file and delete all of the existing code. We\u2019ll start fresh by adding the imports we\u2019ll need to make this Dapp work. At the top of your file, add the following code:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">import<\/span> { useEffect, useState } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'react'<\/span>\n<span class=\"hljs-keyword\">import<\/span> Web3 <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'web3'<\/span>\n\n<span class=\"hljs-keyword\">import<\/span> { ORDER_MAKER_ABI, ORDER_MAKER_ADDRESS } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'..\/..\/config'<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Then we can add the shell for the <code>OrderPage<\/code> component. Add this code to your file:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">const<\/span> OrderPage = <span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n\n}\n\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> OrderPage\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Now we can start filling in this component to finish the logic and UI for users to work with.<\/p>\n<h3>Adding the Blockchain Calls<\/h3>\n<p>We\u2019ll add the states that we need to handle rendering. Inside the component, add this code:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">const<\/span> &#91;account, setAccount] = useState&lt;string&gt;(<span class=\"hljs-string\">''<\/span>)\n<span class=\"hljs-keyword\">const<\/span> &#91;order, setOrder] = useState(<span class=\"hljs-literal\">null<\/span>)\n<span class=\"hljs-keyword\">const<\/span> &#91;orderMaker, setOrderMaker] = useState(<span class=\"hljs-literal\">null<\/span>)\n\n<span class=\"hljs-keyword\">const<\/span> web3 = <span class=\"hljs-keyword\">new<\/span> Web3(<span class=\"hljs-string\">'http:\/\/localhost:7545'<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>The main thing to note is that we\u2019re creating a new instance of <code>Web3<\/code> that connects to the local EVM. This is similar to how you might define a connection to an API.<\/p>\n<p>Then we need to set the states for our component based on the data we get from our blockchain connection. To do that, add this code below the EVM connection.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">useEffect(<span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n  loadData()\n}, &#91;])\n\n<span class=\"hljs-keyword\">const<\/span> loadData = <span class=\"hljs-keyword\">async<\/span> () =&gt; {\n  <span class=\"hljs-keyword\">const<\/span> accounts = <span class=\"hljs-keyword\">await<\/span> web3.eth?.getAccounts()\n  setAccount(accounts&#91;<span class=\"hljs-number\">0<\/span>])\n\n  <span class=\"hljs-keyword\">const<\/span> orderMaker = <span class=\"hljs-keyword\">new<\/span> web3.eth.Contract(\n    ORDER_MAKER_ABI,\n    ORDER_MAKER_ADDRESS\n  )\n  setOrderMaker(orderMaker)\n\n  <span class=\"hljs-keyword\">const<\/span> order = <span class=\"hljs-keyword\">await<\/span> orderMaker.methods.ordersById(<span class=\"hljs-number\">1<\/span>).call()\n  setOrder(order)\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>We\u2019re calling this <code>loadData<\/code> function in the <code>useEffect<\/code> hook one time when the component is loaded to get the values we need from the EVM.<\/p>\n<p>Then we define the <code>loadData<\/code> function. This starts by getting all of the account addresses that are on the network and we\u2019re taking the first one to work with. In a production Dapp, you\u2019d have a more sophisticated way to work with addresses.<\/p>\n<p>Next, we create an object that lets us access the methods and parameters available from the <code>OrderMaker<\/code> smart contract we deployed. We do that by using the contract address and ABI from our configs to connect to this specific smart contract on the network. This is like calling a specific endpoint on an API.<\/p>\n<p>After that, we get the first order from the smart contract. This was created in the constructor function so we\u2019d have something to read from the blockchain initially. We call the <code>ordersById<\/code> mapping with an id value.<\/p>\n<p>One thing to note is that we use the <code>call<\/code> method for read requests from the blockchain. This will be an important difference when you see what it looks like to create a new order. We\u2019ll add the function to handle this below the <code>loadData<\/code> function.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">const<\/span> createOrder = <span class=\"hljs-keyword\">async<\/span> (event) =&gt; {\n  event.preventDefault()\n\n  <span class=\"hljs-keyword\">const<\/span> { itemName, quantity } = event.target.elements\n\n  <span class=\"hljs-keyword\">await<\/span> orderMaker.methods.createOrder(itemName.value, quantity.value).send({\n    <span class=\"hljs-attr\">from<\/span>: account,\n    <span class=\"hljs-attr\">gas<\/span>: <span class=\"hljs-number\">4712388<\/span>,\n    <span class=\"hljs-attr\">value<\/span>: web3.utils.toWei(<span class=\"hljs-string\">\"0.001\"<\/span>)\n  })\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>This <code>createOrder<\/code> function will take the values from a form submission and store the user\u2019s order on the blockchain. The main thing to note is how we make this call to the smart contract.<\/p>\n<p>We\u2019re passing the values from the form as the parameters. Then we call the <code>send<\/code> method to execute this transaction on the blockchain. The user\u2019s account address is passed into the <code>send<\/code> method so we know who executed the request.<\/p>\n<p>Since this is a write request, we need to send some gas with the request. That\u2019s why we\u2019re working with a local EVM so that we do have to spend real Ether.<\/p>\n<p>We also need to send a payment with the request because we are calling the <code>payable<\/code> function from the smart contract. We\u2019re using <code>toWei<\/code> because this smallest Ether unit and is the standard for working with payments.<\/p>\n<p>All that\u2019s left is adding the UI. You are welcome to make something far nicer than what we\u2019re about to create, but all of the core functionality will be in place.<\/p>\n<h3>Making the Interface<\/h3>\n<p>We\u2019ll finish this component by adding the return statement with the elements we want to show the user. Add this code below the <code>createOrder<\/code> function.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\">return (\n  <span class=\"hljs-tag\">&lt;&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>Order from EVM<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n    {order &amp;&amp;\n      <span class=\"hljs-tag\">&lt;&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>Item: {order.itemName}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>Price: {order.price}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>Quantity: {order.quantity}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;\/&gt;<\/span>\n    }\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">form<\/span> <span class=\"hljs-attr\">onSubmit<\/span>=<span class=\"hljs-string\">{createOrder}<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">label<\/span> <span class=\"hljs-attr\">htmlFor<\/span>=<span class=\"hljs-string\">'itemName'<\/span>&gt;<\/span>Item Name:<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">label<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">'itemName'<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">'text'<\/span> \/&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">label<\/span> <span class=\"hljs-attr\">htmlFor<\/span>=<span class=\"hljs-string\">'quantity'<\/span>&gt;<\/span>Amount:<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">label<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">'quantity'<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">'number'<\/span> \/&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">button<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">'submit'<\/span>&gt;<\/span>Submit<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">button<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">form<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;\/&gt;<\/span>\n)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>If we have an <code>order<\/code> set in the component, it\u2019ll render the info directly from the blockchain. We also have a form that will allow us to make new orders on the blockchain by calling the function from our smart contract.<\/p>\n<p>Here\u2019s what that page should look like when you run your app. In a terminal, go to the root of your project and run the following command:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">$ yarn redwood dev\n<\/code><\/span><\/pre>\n<p>This will start the dev server and you should see something like this in your browser.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/jesse-thisdot\/image\/upload\/c_limit,w_2000\/f_auto\/q_auto\/v1635994382\/e-603fc55d218a650069f5228b\/kugywnhoieswruaefjwb.png\" alt=\"order from the EVM and the form to make new orders\" loading=\"lazy\" class=\"c-transformed-asset\"  width=\"1246\" height=\"908\"\/><\/p>\n<p>Now you have a fully functional Dapp that stores new info on the blockchain and reads existing info into the browser for your users to see!<\/p>\n<h2>Finished Code<\/h2>\n<p>You can find the complete code in <a href=\"https:\/\/github.com\/flippedcoder\/blog-examples\/tree\/main\/order-dapp\">the <code>order-dapp<\/code> folder of this repo<\/a>.<\/p>\n<p>You can also check out the front-end code in this <a href=\"https:\/\/codesandbox.io\/s\/bold-dust-fyxjm\">Code Sandbox<\/a>.<\/p>\n<\/div>\n  \n  <div class=\"wp-block-cloudinary-code-sandbox \">\n    <iframe\n      src=\"https:\/\/codesandbox.io\/embed\/bold-dust-fyxjm?theme=dark&amp;codemirror=1&amp;highlights=&amp;editorsize=50&amp;fontsize=14&amp;expanddevtools=0&amp;hidedevtools=0&amp;eslint=0&amp;forcerefresh=0&amp;hidenavigation=0&amp;initialpath=%2F&amp;module=&amp;moduleview=0&amp;previewwindow=&amp;view=&amp;runonclick=1\"\n      height=\"500\"\n      style=\"width: 100%;\"\n      title=\"bold-dust-fyxjm\"\n      loading=\"lazy\"\n      allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n    ><\/iframe>\n  <\/div>\n\n  <div class=\"wp-block-cloudinary-markdown \"><h2>Conclusion<\/h2>\n<p>Blockchain technology is just starting to gain traction so there are a lot of differences in jargon and programming workflows that will take time to adjust to. Now is a great time to start learning so that you can be one of the early developers!<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":41,"featured_media":27885,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[134,177,246,371],"class_list":["post-27884","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-guest-post","tag-javascript","tag-react","tag-under-review"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Handling Orders using Web3 and Ethereum<\/title>\n<meta name=\"description\" content=\"Learning how to work with smart contracts using tech stacks that you already know is a great way to get started. As long as you&#039;re familiar with the concepts of front-end development and how API work, you can pick up the specifics of working with the blockchain. In this tutorial, we&#039;ll walk through making a distributed app that lets users pay for orders with one request to the blockchain.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Handling Orders using Web3 and Ethereum\" \/>\n<meta property=\"og:description\" content=\"Learning how to work with smart contracts using tech stacks that you already know is a great way to get started. As long as you&#039;re familiar with the concepts of front-end development and how API work, you can pick up the specifics of working with the blockchain. In this tutorial, we&#039;ll walk through making a distributed app that lets users pay for orders with one request to the blockchain.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-23T22:37:18+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Handling Orders using Web3 and Ethereum\",\"datePublished\":\"2022-03-23T22:37:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/\"},\"wordCount\":6,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA\",\"keywords\":[\"Guest Post\",\"Javascript\",\"React\",\"Under Review\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/\",\"url\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/\",\"name\":\"Handling Orders using Web3 and Ethereum\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA\",\"datePublished\":\"2022-03-23T22:37:18+00:00\",\"description\":\"Learning how to work with smart contracts using tech stacks that you already know is a great way to get started. As long as you're familiar with the concepts of front-end development and how API work, you can pick up the specifics of working with the blockchain. In this tutorial, we'll walk through making a distributed app that lets users pay for orders with one request to the blockchain.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA\",\"width\":6000,\"height\":4000},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Handling Orders using Web3 and Ethereum\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudinary.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Handling Orders using Web3 and Ethereum","description":"Learning how to work with smart contracts using tech stacks that you already know is a great way to get started. As long as you're familiar with the concepts of front-end development and how API work, you can pick up the specifics of working with the blockchain. In this tutorial, we'll walk through making a distributed app that lets users pay for orders with one request to the blockchain.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/","og_locale":"en_US","og_type":"article","og_title":"Handling Orders using Web3 and Ethereum","og_description":"Learning how to work with smart contracts using tech stacks that you already know is a great way to get started. As long as you're familiar with the concepts of front-end development and how API work, you can pick up the specifics of working with the blockchain. In this tutorial, we'll walk through making a distributed app that lets users pay for orders with one request to the blockchain.","og_url":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/","og_site_name":"Cloudinary Blog","article_published_time":"2022-03-23T22:37:18+00:00","twitter_card":"summary_large_image","twitter_image":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/"},"author":{"name":"","@id":""},"headline":"Handling Orders using Web3 and Ethereum","datePublished":"2022-03-23T22:37:18+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/"},"wordCount":6,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA","keywords":["Guest Post","Javascript","React","Under Review"],"inLanguage":"en-US","copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/","url":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/","name":"Handling Orders using Web3 and Ethereum","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA","datePublished":"2022-03-23T22:37:18+00:00","description":"Learning how to work with smart contracts using tech stacks that you already know is a great way to get started. As long as you're familiar with the concepts of front-end development and how API work, you can pick up the specifics of working with the blockchain. In this tutorial, we'll walk through making a distributed app that lets users pay for orders with one request to the blockchain.","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA","width":6000,"height":4000},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/handling-orders-using-web3-and-ethereum\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Handling Orders using Web3 and Ethereum"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":""}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925998\/Web_Assets\/blog\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4\/7a1fb0ccd538abe8e409492878fdc400e3f6de91-6000x4000-1_27885121e4.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/27884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=27884"}],"version-history":[{"count":0,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/27884\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/27885"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=27884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=27884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=27884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}