{"id":3892,"date":"2020-04-04T12:57:00","date_gmt":"2020-04-04T10:57:00","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=3892"},"modified":"2022-06-09T18:01:38","modified_gmt":"2022-06-09T16:01:38","slug":"web3-js-ethereum-blockchain-javascript-api","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/","title":{"rendered":"Web3.js: the Ethereum Blockchain JavaScript API"},"content":{"rendered":"\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-08a70dec      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#introduction\" class=\"uagb-toc-link__trigger\">Introduction<\/a><li class=\"uagb-toc__list\"><a href=\"#building-the-bridge-with-web3js\" class=\"uagb-toc-link__trigger\">Building the bridge with Web3.js<\/a><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<h2 class=\"eplus-yrcpoE wp-block-heading\" id=\"h-introduction\">Introduction<\/h2>\n\n\n\n<p class=\"eplus-8FIEgu\">In previous articles in this series, we have learned how a basic smart contract is made, and discovered that Ethereum Studio is a simple and easy way to develop and deploy on a testnet before going into the Ethereum network. <\/p>\n\n\n\n<p class=\"eplus-8FIEgu\">Next we learned to build a simple web page in order to handle <span id=\"urn:enhancement-e91b9c7f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">user<\/span> <span id=\"urn:enhancement-ec612c87\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interaction\">interactions<\/span> via <span id=\"urn:enhancement-fe17e58a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_browser\">web browser<\/span>. <\/p>\n\n\n\n<p class=\"eplus-8FIEgu\">In this article we\u2019ll learn how to use <strong><span id=\"urn:local-annotation-72\" class=\"textannotation disambiguated\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web3-js\">Web3.js<\/span><\/strong>, a <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/javascript\/javascript-ultimate-guide\/\" class=\"ek-link\"><span id=\"urn:enhancement-3b3bf731\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/javascript\">JavaScript<\/span> <\/a>library, in our project to interact with the <span id=\"urn:enhancement-3e6d02f4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/ethereum\">Ethereum<\/span> Blockchain, enabling the Ethereum smart contract to be operational at the same time as <span id=\"urn:enhancement-c03f93df\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interaction\">interaction<\/span> is taking place on the browser.<\/p>\n\n\n\n<p class=\"eplus-koSBIM\"> This is part five of a series on how to create an ERC-20 token. If you want to begin from scratch, please read <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/what-is-an-erc-20-token-an-overview\/\">part one<\/a>, <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/solidity-hello-world-blockchain\/\">part two<\/a>, <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/simple-contract-solidity-blockchain\/\">part three<\/a> and <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/smart-contract-create-interface-token-blockchain\/\" class=\"ek-link\">part four<\/a> of this series first.<\/p>\n\n\n\n<h2 class=\"eplus-1VSfCX wp-block-heading\" id=\"h-building-the-bridge-with-web3-js\">Building the bridge with Web3.js<\/h2>\n\n\n\n<p class=\"eplus-EBPFVn\">Renaming the JS file using the same name as the <span id=\"urn:enhancement-c7ac61b5\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/html\">HTML file<\/span> and (optionally) the <span id=\"urn:enhancement-e505cf2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/cascading_style_sheets\">CSS<\/span> file is recommended. We then have an \u2018app\u2019 folder containing all the <span id=\"urn:enhancement-947a2aa\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/computer_file\">files<\/span> that handle <span id=\"urn:enhancement-93b0ed27\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">user<\/span> interaction, and a \u2018contracts\u2019 folder that gathers all the token logic <span id=\"urn:enhancement-c428e617\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/computer_file\">files<\/span> (the <em>Coin.sol<\/em> file we saw in <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/simple-contract-solidity-blockchain\/\" class=\"ek-link\">part three<\/a>). <\/p>\n\n\n\n<p class=\"eplus-EBPFVn\">If we follow the <span id=\"urn:enhancement-9b683297\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/model-view-controller\">Model-View-Controller<\/span> architecture, we would notice that the Model is in the \u2018contracts\u2019 folder, whilst the View (the HTML and <span id=\"urn:enhancement-fcf0cb23\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/cascading_style_sheets\">CSS<\/span> <span id=\"urn:enhancement-4bf88534\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/computer_file\">files<\/span>) and the Controller (the JS file) are in the \u2018app\u2019 folder.<\/p>\n\n\n\n<p class=\"eplus-yF9arZ\">To bind the token logic with the <span id=\"urn:enhancement-1b2615dd\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/subroutine\">functions<\/span> that will be <span id=\"urn:enhancement-990bddaa\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/execution_computing\">executed<\/span> when an action is made on the interface, the first step is to declare the address on which the smart contract will be located, along with the ABI and the endpoint.<\/p>\n\n\n\n<p class=\"eplus-yF9arZ\">All this information can be created by starting a local Ethereum node (with <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/geth.ethereum.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" class=\"ek-link\">geth<\/a>, for example) or a public service (<a aria-label=\" (opens in a new tab)\" href=\"http:\/\/infura.io\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" class=\"ek-link\">infura.io<\/a> is one of the most widely known and used, to date).<\/p>\n\n\n<pre class=\"wp-block-code eplus-sz8wao\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Contracts&#91;<span class=\"hljs-string\">'HelloWorld'<\/span>] = {\n<span class=\"hljs-attr\">abi<\/span>: &#91;],\n<span class=\"hljs-attr\">address<\/span>: <span class=\"hljs-string\">\"0x..\"<\/span>,\n<span class=\"hljs-attr\">endpoint<\/span>: <span class=\"hljs-string\">\"http:\/\/....\"<\/span>\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\n\n<p class=\"eplus-yFl0Tu\">The next step involves the need to create a Web3 <span id=\"urn:enhancement-1732c502\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/instance_computer_science\">instance<\/span> of the smart contract, passing it as a property, allowing Web3.js to interact with it.<\/p>\n\n\n<pre class=\"wp-block-code eplus-iv61FI\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">Coin<\/span>(<span class=\"hljs-params\">Contract<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">this<\/span>.web3 = <span class=\"hljs-literal\">null<\/span>;\n    <span class=\"hljs-keyword\">this<\/span>.instance = <span class=\"hljs-literal\">null<\/span>;\n    <span class=\"hljs-keyword\">this<\/span>.Contract = Contract;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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\n\n<p class=\"eplus-6HVlsh\">Next, initialize the <code><span id=\"urn:enhancement-2d13a166\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/coin\">Coin<\/span><\/code> object and create an <span id=\"urn:enhancement-916c6d4e\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/instance_computer_science\">instance<\/span> of the web3js library. The initialization <span id=\"urn:enhancement-ee7303ec\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/subroutine\">function<\/span> first defines the interface for the contract using the web3js contract object (a Web3 object), then defines the address of the <span id=\"urn:enhancement-36b6bf25\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/instance_computer_science\">instance<\/span> of the contract for the <code>Coin<\/code> object.<\/p>\n\n\n\n<p class=\"eplus-9ArEnv\">The <em>web3 <\/em>variable creates a new Web3 <span id=\"urn:enhancement-5f28af12\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/instance_computer_science\">instance<\/span> using either the Metamask provider or an independent Web 3 provider created as the endpoint configured for the contract. <\/p>\n\n\n\n<p class=\"eplus-9ArEnv\">The <em>contract_interface<\/em> <span id=\"urn:enhancement-424f102e\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">variable<\/span> creates the contract interface using the ABI provided in the configuration and the <em><span id=\"urn:enhancement-881337be\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/instance_computer_science\">instance<\/span> <\/em>variable creates the contract <span id=\"urn:enhancement-123b64a8\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/instance_computer_science\">instance<\/span> for the specific Ethereum address provided in the configuration. Refer to the code below.<\/p>\n\n\n<pre class=\"wp-block-code eplus-9MjG0w\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Coin.prototype.init = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n    <span class=\"hljs-keyword\">this<\/span>.web3 = <span class=\"hljs-keyword\">new<\/span> Web3(\n        (<span class=\"hljs-built_in\">window<\/span>.web3 &amp;&amp; <span class=\"hljs-built_in\">window<\/span>.web3.currentProvider) ||\n        <span class=\"hljs-keyword\">new<\/span> Web3.providers.HttpProvider(<span class=\"hljs-keyword\">this<\/span>.Contract.endpoint));\n\n    <span class=\"hljs-keyword\">var<\/span> contract_interface = <span class=\"hljs-keyword\">this<\/span>.web3.eth.contract(<span class=\"hljs-keyword\">this<\/span>.Contract.abi);\n\n    <span class=\"hljs-keyword\">this<\/span>.instance = contract_interface.at(<span class=\"hljs-keyword\">this<\/span>.Contract.address);\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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\n\n<p class=\"eplus-WRdyev\">We begin writing the <em>showAddressBalance <\/em>function triggered by the &#8220;Check Balance&#8221; button to display the account balance: we need to store the input value of the address in an <em>address <\/em>variable, validate it using the <em>isValidAddress <\/em>function, check the amount relative to it and display it in the returned <em>message<\/em>.<\/p>\n\n\n<pre class=\"wp-block-code eplus-PdZBSe\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Coin.prototype.showAddressBalance = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\">hash, cb<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">var<\/span> that = <span class=\"hljs-keyword\">this<\/span>;\n    <span class=\"hljs-keyword\">var<\/span> address = $(<span class=\"hljs-string\">\"#balance-address\"<\/span>).val();\n\n    <span class=\"hljs-keyword\">if<\/span>(!isValidAddress(address)) {\n        <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"Invalid address\"<\/span>);\n        <span class=\"hljs-keyword\">return<\/span>;\n    }\n\n    <span class=\"hljs-keyword\">this<\/span>.getBalance(address, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\">error, balance<\/span>) <\/span>{\n        <span class=\"hljs-keyword\">if<\/span>(error) {\n            <span class=\"hljs-built_in\">console<\/span>.log(error)\n        }\n        <span class=\"hljs-keyword\">else<\/span> {\n            <span class=\"hljs-built_in\">console<\/span>.log(balance.toNumber());\n                $(<span class=\"hljs-string\">\"#message\"<\/span>).text(balance.toNumber());\n}\n})\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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\n\n<p class=\"eplus-TBKVIB\">With the <em>getBalance <\/em>function, we get the balance of tokens found at the address of the contract:<\/p>\n\n\n<pre class=\"wp-block-code eplus-ungRsG\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Coin.prototype.getBalance = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\">address, cb<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">this<\/span>.instance.balances(address, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\">error, result<\/span>) <\/span>{\n        cb(error, result);\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\n\n<p class=\"eplus-USEIw8\">Next, we create the action code to send tokens to another address when the &#8220;send&#8221; button is clicked (the <em>createTokens <\/em>function) by getting input values for address and amount, validating those addresses and the relative amount using the <em>isValidAddress <\/em>and <em>isValidAmount<\/em> <span id=\"urn:enhancement-476b9dbe\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/subroutine\">function<\/span>. <\/p>\n\n\n\n<p class=\"eplus-USEIw8\">Then, we transfer the amount to other address and use the public mint <span id=\"urn:enhancement-1e8648a1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/subroutine\">function<\/span> from the smart contract: if there&#8217;s an error, we log it, otherwise we wait for the confirmation of transaction from the <em>waitForReceipt <\/em>function and clear form values while waiting:<\/p>\n\n\n<pre class=\"wp-block-code eplus-SSR2HS\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Coin.prototype.createTokens = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n    <span class=\"hljs-keyword\">var<\/span> that = <span class=\"hljs-keyword\">this<\/span>;\n    \n    <span class=\"hljs-keyword\">var<\/span> address = $(<span class=\"hljs-string\">\"#create-address\"<\/span>).val();\n    <span class=\"hljs-keyword\">var<\/span> amount = $(<span class=\"hljs-string\">\"#create-amount\"<\/span>).val();\n    <span class=\"hljs-built_in\">console<\/span>.log(amount);\n\n    <span class=\"hljs-keyword\">if<\/span>(!isValidAddress(address)) {\n        <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"Invalid address\"<\/span>);\n        <span class=\"hljs-keyword\">return<\/span>;\n    }\n\n    <span class=\"hljs-keyword\">if<\/span>(!isValidAmount(amount)) {\n        <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"Invalid amount\"<\/span>);\n        <span class=\"hljs-keyword\">return<\/span>;\n    }\n\n    <span class=\"hljs-keyword\">this<\/span>.instance.mint(address, amount, { <span class=\"hljs-attr\">from<\/span>:\n<span class=\"hljs-built_in\">window<\/span>.web3.eth.accounts&#91;<span class=\"hljs-number\">0<\/span>], <span class=\"hljs-attr\">gas<\/span>: <span class=\"hljs-number\">100000<\/span>, <span class=\"hljs-attr\">gasPrice<\/span>: <span class=\"hljs-number\">100000<\/span>, <span class=\"hljs-attr\">gasLimit<\/span>: <span class=\"hljs-number\">100000<\/span> }, \n                <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\">error, txHash<\/span>) <\/span>{\n            <span class=\"hljs-keyword\">if<\/span>(error) {\n                <span class=\"hljs-built_in\">console<\/span>.log(error);\n            }\n            <span class=\"hljs-keyword\">else<\/span> {\n                that.waitForReceipt(txHash, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\">receipt<\/span>) <\/span>{\n                    <span class=\"hljs-keyword\">if<\/span>(receipt.status) {\n                        $(<span class=\"hljs-string\">\"#create-address\"<\/span>).val(<span class=\"hljs-string\">\"\"<\/span>);\n                        $(<span class=\"hljs-string\">\"#create-amount\"<\/span>).val(<span class=\"hljs-string\">\"\"<\/span>);\n                    }\n                    <span class=\"hljs-keyword\">else<\/span> {\n                        <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"error\"<\/span>);\n                    }\n                });\n            }\n        }\n    )\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\n\n<p class=\"eplus-V7eevv\">The <em>waitForReceipt <\/em>function waits for receipt of transaction, checking for the transaction receipt using the web3 library <span id=\"urn:enhancement-bbeb0de0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span>, and trying again every 2 seconds (2000 ms):<\/p>\n\n\n<pre class=\"wp-block-code eplus-jQWWG2\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Coin.prototype.waitForReceipt = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\">hash, cb<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">var<\/span> that = <span class=\"hljs-keyword\">this<\/span>;\n\n    <span class=\"hljs-keyword\">this<\/span>.web3.eth.getTransactionReceipt(hash, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\">err, receipt<\/span>) <\/span>{\n        <span class=\"hljs-keyword\">if<\/span> (err) {\n            error(err);\n        }\n        <span class=\"hljs-keyword\">if<\/span> (receipt !== <span class=\"hljs-literal\">null<\/span>) {\n           Transaction went through\n            <span class=\"hljs-keyword\">if<\/span> (cb) {\n                cb(receipt);\n            }\n        } <span class=\"hljs-keyword\">else<\/span> {\n            <span class=\"hljs-built_in\">window<\/span>.setTimeout(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n                that.waitForReceipt(hash, cb);\n            }, <span class=\"hljs-number\">2000<\/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\n\n<p class=\"eplus-NgC1J2\">With the <em>isValidAddress<\/em> function, called in the <span id=\"urn:enhancement-5148ac7c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/subroutine\">functions<\/span> above, we check if the address meets the basic requirements (<em>i.e.<\/em> it follows the <span id=\"urn:enhancement-8e93c3bd\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/ethereum\">Ethereum<\/span> standard), by doing a basic validation of amount, which must be bigger than 0 and a number type. Use the code below:<\/p>\n\n\n<pre class=\"wp-block-code eplus-6UNoIF\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">isValidAddress<\/span>(<span class=\"hljs-params\">address<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-regexp\">\/^(0x)?&#91;0-9a-f]{40}$\/i<\/span>.test(address);\n}\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">isValidAmount<\/span>(<span class=\"hljs-params\">amount<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">return<\/span> amount &gt; <span class=\"hljs-number\">0<\/span> &amp;&amp; <span class=\"hljs-keyword\">typeof<\/span> <span class=\"hljs-built_in\">Number<\/span>(amount) == <span class=\"hljs-string\">'number'<\/span>;    \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\n\n<p class=\"eplus-Wv2hQz\"> Then, we bind <span id=\"urn:enhancement-11ee0a67\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/subroutine\">functions<\/span> to the buttons defined in app.html:<\/p>\n\n\n<pre class=\"wp-block-code eplus-BdngPp\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Coin.prototype.bindButtons = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n    <span class=\"hljs-keyword\">var<\/span> that = <span class=\"hljs-keyword\">this<\/span>;\n\n    $(<span class=\"hljs-built_in\">document<\/span>).on(<span class=\"hljs-string\">\"click\"<\/span>, <span class=\"hljs-string\">\"#button-create\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n        that.createTokens();\n    });\n\n    $(<span class=\"hljs-built_in\">document<\/span>).on(<span class=\"hljs-string\">\"click\"<\/span>, <span class=\"hljs-string\">\"#button-check\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n        that.showAddressBalance();\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\n\n<p class=\"eplus-fqQudB\">This last <span id=\"urn:enhancement-61e13f3b\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/bit\">bit<\/span> of code binds all the buttons defined in the <span id=\"urn:enhancement-133b0877\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/subroutine\">functions<\/span> above and initialized the contract.<\/p>\n\n\n<pre class=\"wp-block-code eplus-q2D6NN\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Coin.prototype.onReady = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n    <span class=\"hljs-keyword\">this<\/span>.bindButtons();\n    <span class=\"hljs-keyword\">this<\/span>.init();\n};\n\n<span class=\"hljs-keyword\">if<\/span>(<span class=\"hljs-keyword\">typeof<\/span>(Contracts) === <span class=\"hljs-string\">\"undefined\"<\/span>) <span class=\"hljs-keyword\">var<\/span> Contracts={ <span class=\"hljs-attr\">Coin<\/span>: { <span class=\"hljs-attr\">abi<\/span>: &#91;] }};\n<span class=\"hljs-keyword\">var<\/span> coin = <span class=\"hljs-keyword\">new<\/span> Coin(Contracts&#91;<span class=\"hljs-string\">'Coin'<\/span>]);\n\n$(<span class=\"hljs-built_in\">document<\/span>).ready(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n    coin.onReady();\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\n\n<p class=\"eplus-a5N4JO\">Web3.js is one of the frameworks most frequently used to design decentralised <span id=\"urn:enhancement-6b9e821a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_software\">applications<\/span>. Of course, this is just a little <span id=\"urn:enhancement-f876fe6c\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_software\">application<\/span> that does very few things. A list of the <span id=\"urn:enhancement-af339385\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/subroutine\">functions<\/span>, along with a complete guide of web3js framework, is available in the <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/web3js.readthedocs.io\/en\/v1.2.6\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" class=\"ek-link\">official documentation<\/a> website.<\/p>\n\n\n\n\n\n<p>Interested in Web3? Read: <a href=\"https:\/\/www.codemotion.com\/magazine\/backend-dev\/blockchain-dev\/what-is-web3-and-what-new-capabilities-does-it-bring\/\" class=\"ek-link\">What is Web3 and What New Capabilities Does it Bring?<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In previous articles in this series, we have learned how a basic smart contract is made, and discovered that Ethereum Studio is a simple and easy way to develop and deploy on a testnet before going into the Ethereum network. Next we learned to build a simple web page in order to handle user&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/\">Read more<\/a><\/p>\n","protected":false},"author":86,"featured_media":3893,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":3,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[13],"tags":[4240,4244],"collections":[],"class_list":{"0":"post-3892","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-blockchain","8":"tag-ethereum","9":"tag-smart-contract","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Web3.js: the Ethereum Blockchain JavaScript API - Codemotion<\/title>\n<meta name=\"description\" content=\"Learn how to make an interactive web interface by means of a web3.js, in order to tweak the token attributes of Smart Contracts.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Web3.js: the Ethereum Blockchain JavaScript API\" \/>\n<meta property=\"og:description\" content=\"Learn how to make an interactive web interface by means of a web3.js, in order to tweak the token attributes of Smart Contracts.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/ijaack94\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-04T10:57:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-09T16:01:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Giacomo Barbieri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ijaack94\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Giacomo Barbieri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/\"},\"author\":{\"name\":\"Giacomo Barbieri\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/ace6a459089546835d3262bb7aef87bf\"},\"headline\":\"Web3.js: the Ethereum Blockchain JavaScript API\",\"datePublished\":\"2020-04-04T10:57:00+00:00\",\"dateModified\":\"2022-06-09T16:01:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/\"},\"wordCount\":763,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg\",\"keywords\":[\"Ethereum\",\"Smart Contracts\"],\"articleSection\":[\"Blockchain\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/\",\"name\":\"Web3.js: the Ethereum Blockchain JavaScript API - Codemotion\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg\",\"datePublished\":\"2020-04-04T10:57:00+00:00\",\"dateModified\":\"2022-06-09T16:01:38+00:00\",\"description\":\"Learn how to make an interactive web interface by means of a web3.js, in order to tweak the token attributes of Smart Contracts.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg\",\"width\":1200,\"height\":675,\"caption\":\"javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Backend\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/backend\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Blockchain\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Web3.js: the Ethereum Blockchain JavaScript API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Codemotion.Italy\/\",\"https:\/\/x.com\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/ace6a459089546835d3262bb7aef87bf\",\"name\":\"Giacomo Barbieri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8381a47a5414b1154179659f56400e3eb72c3a592355c40b184a4f8a6a991c87?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8381a47a5414b1154179659f56400e3eb72c3a592355c40b184a4f8a6a991c87?s=96&d=mm&r=g\",\"caption\":\"Giacomo Barbieri\"},\"description\":\"Blogger with over 6 years of experience in blogs and newspapers, passionate about AI, 5G and blockchain. Never-ending learner of new technologies and approaches, I believe in the decentralized government and in the Internet of Money.\",\"sameAs\":[\"https:\/\/facebook.com\/ijaack94\",\"https:\/\/instagram.com\/ijaack94\/\",\"https:\/\/linkedin.com\/in\/giacomobarbieri94\",\"https:\/\/x.com\/ijaack94\"],\"url\":\"https:\/\/www.codemotion.com\/magazine\/author\/giacomo-barbieri\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Web3.js: the Ethereum Blockchain JavaScript API - Codemotion","description":"Learn how to make an interactive web interface by means of a web3.js, in order to tweak the token attributes of Smart Contracts.","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:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/","og_locale":"en_US","og_type":"article","og_title":"Web3.js: the Ethereum Blockchain JavaScript API","og_description":"Learn how to make an interactive web interface by means of a web3.js, in order to tweak the token attributes of Smart Contracts.","og_url":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_author":"https:\/\/facebook.com\/ijaack94","article_published_time":"2020-04-04T10:57:00+00:00","article_modified_time":"2022-06-09T16:01:38+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg","type":"image\/jpeg"}],"author":"Giacomo Barbieri","twitter_card":"summary_large_image","twitter_creator":"@ijaack94","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Giacomo Barbieri","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/"},"author":{"name":"Giacomo Barbieri","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/ace6a459089546835d3262bb7aef87bf"},"headline":"Web3.js: the Ethereum Blockchain JavaScript API","datePublished":"2020-04-04T10:57:00+00:00","dateModified":"2022-06-09T16:01:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/"},"wordCount":763,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg","keywords":["Ethereum","Smart Contracts"],"articleSection":["Blockchain"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/","url":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/","name":"Web3.js: the Ethereum Blockchain JavaScript API - Codemotion","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg","datePublished":"2020-04-04T10:57:00+00:00","dateModified":"2022-06-09T16:01:38+00:00","description":"Learn how to make an interactive web interface by means of a web3.js, in order to tweak the token attributes of Smart Contracts.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg","width":1200,"height":675,"caption":"javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/web3-js-ethereum-blockchain-javascript-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Backend","item":"https:\/\/www.codemotion.com\/magazine\/backend\/"},{"@type":"ListItem","position":3,"name":"Blockchain","item":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/"},{"@type":"ListItem","position":4,"name":"Web3.js: the Ethereum Blockchain JavaScript API"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/ace6a459089546835d3262bb7aef87bf","name":"Giacomo Barbieri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8381a47a5414b1154179659f56400e3eb72c3a592355c40b184a4f8a6a991c87?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8381a47a5414b1154179659f56400e3eb72c3a592355c40b184a4f8a6a991c87?s=96&d=mm&r=g","caption":"Giacomo Barbieri"},"description":"Blogger with over 6 years of experience in blogs and newspapers, passionate about AI, 5G and blockchain. Never-ending learner of new technologies and approaches, I believe in the decentralized government and in the Internet of Money.","sameAs":["https:\/\/facebook.com\/ijaack94","https:\/\/instagram.com\/ijaack94\/","https:\/\/linkedin.com\/in\/giacomobarbieri94","https:\/\/x.com\/ijaack94"],"url":"https:\/\/www.codemotion.com\/magazine\/author\/giacomo-barbieri\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-600x600.jpg","author_info":{"display_name":"Giacomo Barbieri","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/giacomo-barbieri\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg",1200,675,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-768x432.jpg",768,432,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg",1200,675,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg",1200,675,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280.jpg",100,56,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/04\/code-3337044_1280-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Giacomo Barbieri","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/giacomo-barbieri\/"},"uagb_comment_info":0,"uagb_excerpt":"Introduction In previous articles in this series, we have learned how a basic smart contract is made, and discovered that Ethereum Studio is a simple and easy way to develop and deploy on a testnet before going into the Ethereum network. Next we learned to build a simple web page in order to handle user&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/86"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=3892"}],"version-history":[{"count":13,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3892\/revisions"}],"predecessor-version":[{"id":17981,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3892\/revisions\/17981"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/3893"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=3892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=3892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=3892"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=3892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}