Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation updated #2644

Merged
merged 26 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/callbacks-promises-events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ we provide multiple ways to act on asynchronous functions.
Most web3.js objects allow a callback as the last parameter, as well as returning promises to chain functions.

Ethereum as a blockchain has different levels of finality and therefore needs to return multiple "stages" of an action.
To cope with requirement we return a "promiEvent" for functions like ``web3.eth.sendTransaction`` or contract methods.
This "promiEvent" is a promise combined with an event emitter to allow acting on different stages of action on the blockchain, like a transaction.
To cope with requirement we return a "PromiEvent" for functions like ``web3.eth.sendTransaction`` or contract methods.
This "PromiEvent" is a promise combined with an event emitter to allow acting on different stages of action on the blockchain, like a transaction.
nivida marked this conversation as resolved.
Show resolved Hide resolved

PromiEvents work like a normal promises with added ``on``, ``once`` and ``off`` functions.
This way developers can watch for additional events like on "receipt" or "transactionHash".
This way developers can watch for additional events like on ``receipt`` or ``transactionHash``.

.. code-block:: javascript

Expand Down
22 changes: 17 additions & 5 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.. include:: include_announcement.rst

===============
Expand Down Expand Up @@ -26,16 +25,29 @@ First you need to get web3.js into your project. This can be done using the foll

- npm: ``npm install web3``
- meteor: ``meteor add ethereum:web3``
- pure js: link the ``dist/web3.min.js``

After that you need to create a web3 instance and set a provider.
Ethereum supported Browsers like Mist or MetaMask will have a ``ethereumProvider`` or ``web3.currentProvider`` available. For web3.js, check ``Web3.givenProvider``.
If this property is ``null`` you should connect to a remote/local node.
Ethereum supported Browsers like Mist or MetaMask will have a ``ethereum`` or ``web3.currentProvider`` available.
For web3.js, check ``Web3.givenProvider``. If this property is ``null`` you should connect to your own local or remote node.
nivida marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: javascript

// in node.js use: const Web3 = require('web3');

const web3 = new Web3(Web3.givenProvider || "ws://localhost:8546");
// use the given Provider, e.g in Metamask, or instantiate a new websocket provider
const web3 = new Web3(Web3.givenProvider || 'ws://localhost:8546', null, {});

// or
const web3 = new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider('ws://localhost:8546'), null, {});

// Using the IPC provider in node.js
const net = require('net');

const web3 = new Web3('/Users/myuser/Library/Ethereum/geth.ipc', net, {}); // mac os path
// or
const web3 = new Web3(new Web3.providers.IpcProvider('/Users/myuser/Library/Ethereum/geth.ipc', net, {})); // mac os path
// on windows the path is: '\\\\.\\pipe\\geth.ipc'
// on linux the path is: '/users/myuser/.ethereum/geth.ipc'


That's it! now you can use the ``web3`` object.
14 changes: 7 additions & 7 deletions docs/include_package-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Will return the given provider by the (browser) environment, otherwise ``null``.
Returns
-------

``Object``: The given provider set or ``null``;
``Object``: The given provider set or ``false``.

-------
Example
Expand All @@ -396,22 +396,22 @@ currentProvider
web3.bzz.currentProvider
...

Will return the current provider, otherwise ``null``.
Will return the current provider.


-------
Returns
-------

``Object``: The current provider set or ``null``;
``Object``: The current provider set.

-------
Example
-------

.. code-block:: javascript

if(!web3.currentProvider) {
if (!web3.currentProvider) {
web3.setProvider('http://localhost:8545');
}

Expand Down Expand Up @@ -453,6 +453,6 @@ Example
const contract = new web3.eth.Contract(abi, address);

const batch = new web3.BatchRequest();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
batch.add(contract.methods.balance(address).call.request({from: '0x0000000000000000000000000000000000000000'}, callback2));
batch.execute();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest'));
batch.add(contract.methods.balance(address).call.request({from: '0x0000000000000000000000000000000000000000'}));
batch.execute().then(...);
9 changes: 3 additions & 6 deletions docs/include_package-net.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ Example

.. code-block:: javascript

web3.eth.net.getId()
.then(console.log);
web3.eth.net.getId().then(console.log);
> 1

------------------------------------------------------------------------------
Expand Down Expand Up @@ -65,8 +64,7 @@ Example

.. code-block:: javascript

web3.eth.isListening()
.then(console.log);
web3.eth.isListening().then(console.log);
> true

------------------------------------------------------------------------------
Expand Down Expand Up @@ -100,6 +98,5 @@ Example

.. code-block:: javascript

web3.eth.getPeerCount()
.then(console.log);
web3.eth.getPeerCount().then(console.log);
> 25
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ web3.js - Ethereum JavaScript API
=================================

web3.js is a collection of libraries which allow you to interact with a local or remote ethereum node,
using a HTTP or IPC connection.
using an HTTP, WebSocket or IPC connection.

The following documentation will guide you through :ref:`installing and running web3.js <adding-web3>`,
as well as providing a :ref:`API reference documentation <#id1>` with examples.
Expand Down
4 changes: 2 additions & 2 deletions docs/web3-eth-abi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ This will be used for function calls to the EVM (Ethereum Virtual Machine).
// or using the web3 umbrella package


import {Web3} from 'web3';
import Web3 from 'web3';

const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options);
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);
// -> web3.eth.abi


Expand Down
2 changes: 1 addition & 1 deletion docs/web3-eth-accounts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To use this package standalone use:

// Passing in the eth or web3 package is necessary to allow retrieving chainId, gasPrice and nonce automatically
// for accounts.signTransaction().
const accounts = new Accounts('ws://localhost:8546', options);
const accounts = new Accounts('ws://localhost:8546', null, options);



Expand Down
5 changes: 3 additions & 2 deletions docs/web3-eth-ens.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ The ``web3.eth.ens`` functions let you interacting with Ens.
// "Web3.givenProvider" will be set if in an Ethereum supported browser.
const eth = new Ens(
Web3.givenProvider || 'ws://some.local-or-remote.node:8546',
new Accounts(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options),
net,
options
new Accounts(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options)
);


// or using the web3 umbrella package

const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options);
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);

// -> web3.eth.ens

Expand Down
4 changes: 2 additions & 2 deletions docs/web3-eth-personal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ The ``web3-eth-personal`` package allows you to interact with the Ethereum node'
import {Personal} from 'web3-eth-personal';

// "Web3.givenProvider" will be set if in an Ethereum supported browser.
const personal = new Personal(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options);
const personal = new Personal(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);


// or using the web3 umbrella package
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options);
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);

// -> web3.eth.personal

Expand Down
32 changes: 13 additions & 19 deletions docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Property
--------


``String`` - 20 Bytes: Any ethereum address. You should have the private key for that address in your node or keystore. (Default is ``undefined``)
``String`` - 20 Bytes: Any Ethereum address. You should have the private key for that address in your node or keystore. (Default is ``undefined``)
nivida marked this conversation as resolved.
Show resolved Hide resolved


-------
Expand Down Expand Up @@ -219,7 +219,7 @@ getProtocolVersion

web3.eth.getProtocolVersion([callback])

Returns the ethereum protocol version of the node.
Returns the Ethereum protocol version of the node.

-------
Returns
Expand Down Expand Up @@ -419,8 +419,8 @@ getAccounts

web3.eth.getAccounts([callback])

Returns a list of accounts the node controls by using the provider and calling the RPC method ``eth_accounts``.
If there are unlocked local accounts then it will return them instead of sending a request to the node.
Will return a list of locally unlocked accounts or it will return the unlocked accounts from the currently connected node.
nivida marked this conversation as resolved.
Show resolved Hide resolved

This means you can add accounts with :ref:`web3.eth.accounts.create() <accounts-create>` and you will get them returned here.

-------
Expand All @@ -437,8 +437,7 @@ Example

.. code-block:: javascript

web3.eth.getAccounts()
.then(console.log);
web3.eth.getAccounts().then(console.log);
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"]


Expand Down Expand Up @@ -466,8 +465,7 @@ Example

.. code-block:: javascript

web3.eth.getBlockNumber()
.then(console.log);
web3.eth.getBlockNumber().then(console.log);
> 2744


Expand Down Expand Up @@ -508,8 +506,7 @@ Example

.. code-block:: javascript

web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1")
.then(console.log);
web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
> "1000000000000"


Expand Down Expand Up @@ -549,8 +546,7 @@ Example

.. code-block:: javascript

web3.eth.getStorageAt("0x407d73d8a49eeb85d32cf465507dd71d507100c1", 0)
.then(console.log);
web3.eth.getStorageAt("0x407d73d8a49eeb85d32cf465507dd71d507100c1", 0).then(console.log);
> "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"


Expand Down Expand Up @@ -589,8 +585,7 @@ Example

.. code-block:: javascript

web3.eth.getCode("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8")
.then(console.log);
web3.eth.getCode("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8").then(console.log);
> "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"


Expand Down Expand Up @@ -648,9 +643,7 @@ Example

.. code-block:: javascript

web3.eth.getBlock(3150)
.then(console.log);

web3.eth.getBlock(3150).then(console.log);
> {
"number": 3,
"hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
Expand Down Expand Up @@ -1168,17 +1161,18 @@ signTransaction

.. code-block:: javascript

web3.eth.signTransaction(transactionObject [, callback])
web3.eth.signTransaction(transactionObject [, address,] [, callback])

The method ``signTransaction`` signs a transaction with the private key of the given address.
This method does only work if you're connected to a Parity node.
It will sign the transaction locally if a local unlocked account with the given address is existing.
nivida marked this conversation as resolved.
Show resolved Hide resolved

----------
Parameters
----------


1. ``Object`` - The transaction data to sign :ref:`web3.eth.sendTransaction() <eth-sendtransaction>` for more.
1. ``string`` - The address of the account.
3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.


Expand Down
4 changes: 2 additions & 2 deletions docs/web3-net.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ The ``web3-net`` package allows you to interact with the Ethereum nodes network
import {Net} from 'web3-net';

// "Personal.providers.givenProvider" will be set if in an Ethereum supported browser.
const net = new Net(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options);
const net = new Net(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);


// or using the web3 umbrella package
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options);
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);

// -> web3.eth.net
// -> web3.bzz.net
Expand Down
4 changes: 2 additions & 2 deletions docs/web3-shh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ For more see `Whisper Overview <https://github.com/ethereum/go-ethereum/wiki/Wh
import {Shh} import 'web3-shh';

// "Web3.givenProvider" will be set if in an Ethereum supported browser.
const shh = new Shh(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options);
const shh = new Shh(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);


// or using the web3 umbrella package
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options;
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options;

// -> web3.shh

Expand Down
32 changes: 24 additions & 8 deletions docs/web3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,27 @@ Web3

.. code-block:: javascript

import {Web3} from 'web3';
new Web3(provider, net, options);

----------
Parameters
----------

1. ``provider`` - ``string|object``: A URL or one of the internally provided provider classes.
2. ``net`` - ``net.Socket`` (optional): The net NodeJS package.
3. ``options`` - ``object`` (optional)


-------
Example
-------

.. code-block:: javascript

import Web3 from 'web3';

// "Web3.providers.givenProvider" will be set if in an Ethereum supported browser.
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546');
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', net, options);

> web3.eth
> web3.shh
Expand Down Expand Up @@ -52,11 +69,11 @@ Example

Web3.modules
> {
Eth: Eth function(provider, options?, net?),
Net: Net function(provider, options?, net?),
Personal: Personal function(provider, options?, net?),
Shh: Shh function(provider, options?, net?),
Bzz: Bzz function(provider, options?, net?),
Eth(provider, net?, options?),
Net(provider, net?, options?),
Personal(provider, net?, options?),
Shh(provider, net?, options?),
Bzz(provider, net?, options?),
}


Expand All @@ -73,7 +90,6 @@ version

.. code-block:: javascript

Web3.version
web3.version

Contains the version of the ``web3`` wrapper class.
Expand Down