-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ | |
== web3.js Tutorial | ||
|
||
=== Description | ||
This tutorial is based on [email protected] web3.js. It is intended as an introduction to web3.js. | ||
((("web3.js","tutorial", id="ix_appdx-web3js-tutorial-asciidoc0", range="startofrange")))This tutorial is based on [email protected] web3.js. It is intended as an introduction to web3.js. | ||
|
||
The web3.js JavaScript library is a collection of modules that contain specific functionality for the Ethereum ecosystem, together with an Ethereum-compatible JavaScript API which implements the Generic JSON RPC spec. | ||
|
||
To run this script you don’t need to run your own local node, because it uses the https://infura.io[Infura services]. | ||
|
||
=== web3.js Contract Basic Interaction in a Nonblocked (Async) Fashion | ||
|
||
Check you have a valid +npm+ version: | ||
((("web3.js","contract basic interaction in nonblocked (Async) fashion")))Check you have a valid +npm+ version: | ||
|
||
++++ | ||
<pre data-type="programlisting"> | ||
|
@@ -42,7 +42,7 @@ This will update your _package.json_ configuration file with your new dependence | |
|
||
==== Node.js Script Execution | ||
|
||
Basic execution: | ||
((("web3.js","node.js script execution")))Basic execution: | ||
|
||
++++ | ||
<pre data-type="programlisting"> | ||
|
@@ -72,7 +72,7 @@ This will read the file with your own token and pass it in as a command-line arg | |
|
||
=== Reviewing the Demo Script | ||
|
||
Next, let's review our demo script, _web3-contract-basic-interaction_. | ||
((("web3.js","reviewing demo script")))Next, let's review our demo script, _web3-contract-basic-interaction_. | ||
|
||
We use the +Web3+ object to obtain a basic web3 provider: | ||
|
||
|
@@ -110,7 +110,7 @@ web3.eth.getBlockNumber().then(function(blockNumber) { | |
|
||
=== Contract Interaction | ||
|
||
Now let's try some basic interactions with a contract. For these examples, we'll use the https://bit.ly/2MPZZLx[+WETH9_+ contract] on the Kovan testnet. | ||
((("web3.js","contract interaction", id="ix_appdx-web3js-tutorial-asciidoc1", range="startofrange")))Now let's try some basic interactions with a contract. For these examples, we'll use the https://bit.ly/2MPZZLx[+WETH9_+ contract] on the Kovan testnet. | ||
|
||
First, let's initialize our contract address: | ||
|
||
|
@@ -231,7 +231,7 @@ our_contract.methods.totalSupply().call(function(err, totalSupply) { | |
}); | ||
---- | ||
|
||
Or we can use the returned promise instead of passing in the callback: | ||
Or we can use the returned promise instead of passing in the callback:(((range="endofrange", startref="ix_appdx-web3js-tutorial-asciidoc1"))) | ||
|
||
[source,solidity] | ||
---- | ||
|
@@ -244,4 +244,4 @@ our_contract.methods.totalSupply().call().then(function(totalSupply){ | |
|
||
=== Asynchronous Operation with Await | ||
|
||
Now that you've seen the basic tutorial, you can try the same interactions using an asynchronous +await+ construct. Review the _web3-contract-basic-interaction-async-await.js_ script in https://github.com/ethereumbook/ethereumbook/tree/develop/code/web3js[_code/web3js_] and compare it to this tutorial to see how they differ. Async-await is easier to read, as it makes the asynchronous interaction behave more like a sequence of blocking calls. | ||
((("await construct")))((("web3.js","asynchronous operation with await")))Now that you've seen the basic tutorial, you can try the same interactions using an asynchronous +await+ construct. Review the _web3-contract-basic-interaction-async-await.js_ script in https://github.com/ethereumbook/ethereumbook/tree/develop/code/web3js[_code/web3js_] and compare it to this tutorial to see how they differ. Async-await is easier to read, as it makes the asynchronous interaction behave more like a sequence of blocking calls.(((range="endofrange", startref="ix_appdx-web3js-tutorial-asciidoc0"))) |