Skip to content

Commit

Permalink
solution: include JSRE docs from wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
whilei committed May 19, 2018
1 parent e750f1a commit cf22a08
Show file tree
Hide file tree
Showing 63 changed files with 907 additions and 0 deletions.
70 changes: 70 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,73 @@
+ [uninstallFilter](./json-rpc/methods/shh/uninstallFilter.md)
+ [getFilterChanges](./json-rpc/methods/shh/getFilterChanges.md)
+ [getMessages](./json-rpc/methods/shh/getMessages.md)

## Javascript Console (JSRE)
- [About](./jsre.md)
- [Interactive Use](./jsre/interactive-use.md)
- [Non-interactive Use](./jsre/non-interactive-use.md)
- [Caveats](./jsre/caveats.md)
- [Timers](./jsre/timers.md)
- [Management Apis](./jsre/management-apis.md)
- [How To](./jsre/how-to.md)
- [Integration](./jsre/integration.md)
- Methods
+ [admin](./jsre/methods/admin/admin.md)
+ [nodeInfo](./jsre/methods/admin/nodeInfo.md)
+ [addPeer](./jsre/methods/admin/addPeer.md)
+ [peers](./jsre/methods/admin/peers.md)
+ [importChain](./jsre/methods/admin/importChain.md)
+ [exportChain](./jsre/methods/admin/exportChain.md)
+ [startRPC](./jsre/methods/admin/startRPC.md)
+ [stopRPC](./jsre/methods/admin/stopRPC.md)
+ [startWS](./jsre/methods/admin/startWS.md)
+ [stopWS](./jsre/methods/admin/stopWS.md)
+ [sleep](./jsre/methods/admin/sleep.md)
+ [sleepBlocks](./jsre/methods/admin/sleepBlocks.md)
+ [datadir](./jsre/methods/admin/datadir.md)
+ [setSolc](./jsre/methods/admin/setSolc.md)
+ [startNatSpec](./jsre/methods/admin/startNatSpec.md)
+ [stopNatSpec](./jsre/methods/admin/stopNatSpec.md)
+ [getContractInfo](./jsre/methods/admin/getContractInfo.md)
+ [saveInfo](./jsre/methods/admin/saveInfo.md)
+ [register](./jsre/methods/admin/register.md)
+ [registerUrl](./jsre/methods/admin/registerUrl.md)
- [personal](./jsre/methods/personal/personal.md)
+ [listAccounts](./jsre/methods/personal/listAccounts.md)
+ [newAccount](./jsre/methods/personal/newAccount.md)
+ [unlockAccount](./jsre/methods/personal/unlockAccount.md)
- [geth](./jsre/methods/geth/geth.md)
+ [getAddressTransactions](./jsre/methods/geth/getAddressTransactions.md)
- [txpool](./jsre/methods/txpool/txpool.md)
+ [status](./jsre/methods/txpool/status.md)
- [miner](./jsre/methods/miner/miner.md)
+ [start](./jsre/methods/miner/start.md)
+ [stop](./jsre/methods/miner/stop.md)
+ [startAutoDAG](./jsre/methods/miner/startAutoDAG.md)
+ [stopAutoDAG](./jsre/methods/miner/stopAutoDAG.md)
+ [makeDAG](./jsre/methods/miner/makeDAG.md)
+ [setExtra](./jsre/methods/miner/setExtra.md)
+ [setGasPrice](./jsre/methods/miner/setGasPrice.md)
+ [setEtherbase](./jsre/methods/miner/setEtherbase.md)
- [debug](./jsre/methods/debug/debug.md)
+ [setHead](./jsre/methods/debug/setHead.md)
+ [seedHash](./jsre/methods/debug/seedHash.md)
+ [getBlockRlp](./jsre/methods/debug/getBlockRlp.md)
+ [printBlock](./jsre/methods/debug/printBlock.md)
+ [dumpBlock](./jsre/methods/debug/dumpBlock.md)
+ [metrics](./jsre/methods/debug/metrics.md)
+ [accountExist](./jsre/methods/debug/accountExist.md)
- [eth](./jsre/methods/eth/eth.md)
+ [pendingTransactions](./jsre/methods/eth/pendingTransactions.md)
+ [sign](./jsre/methods/eth/sign.md)
+ [resend](./jsre/methods/eth/resend.md)
- [additional interfaces](./jsre/methods/interfaces/additional-interfaces.md)
+ [loadScript](./jsre/methods/interfaces/loadScript.md)
+ [web3](./jsre/methods/interfaces/web3.md)
+ [net](./jsre/methods/interfaces/net.md)
+ [shh](./jsre/methods/interfaces/shh.md)
+ [inspect](./jsre/methods/interfaces/inspect.md)




10 changes: 10 additions & 0 deletions docs/jsre/caveats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Caveat

The go-ethereum JSRE uses the [Otto JS VM](https://github.com/robertkrimen/otto) which has some limitations:

* "use strict" will parse, but does nothing.
* The regular expression engine (re2/regexp) is not fully compatible with the ECMA5 specification.

Note that the other known limitation of Otto (namely the lack of timers) is taken care of. Ethereum JSRE implements both `setTimeout` and `setInterval`. In addition to this, the console provides `admin.sleep(seconds)` as well as a "blocktime sleep" method `admin.sleepBlocks(number)`.

Since `web3.js` uses the [`bignumber.js`](https://github.com/MikeMcl/bignumber.js) library (MIT Expat Licence), it is also autoloded.
34 changes: 34 additions & 0 deletions docs/jsre/how-to.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# How to
It is possible to specify the set of API's which are offered over an interface with the `--${interface}api` command line argument for the go ethereum daemon. Where `${interface}` can be `rpc` for the `http` interface or `ipc` for an unix socket on unix or named pipe on Windows.

For example, `geth --ipcapi "admin,eth,miner" --rpcapi "eth,web3"` will
* enable the admin, official DApp and miner API over the IPC interface
* enable the eth and web3 API over the RPC interface

Please note that offering an API over the `rpc` interface will give everyone access to the API who can access this interface (e.g. DApp's). So be careful which API's you enable. By default geth enables all API's over the `ipc` interface and only the eth,net and web3 API's over the `rpc` and `ws` interface.

To determine which API's an interface provides the `modules` transaction can be used, e.g. over an `ipc` interface on unix systems:

```
echo '{"jsonrpc":"2.0","method":"rpc_modules","params":[],"id":1}' | socat -,ignoreeof UNIX-CONNECT:$HOME/.ethereum/geth.ipc
```
will give all enabled modules including the version number:
```
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"admin": "1.0",
"debug": "1.0",
"eth": "1.0",
"miner": "1.0",
"net": "1.0",
"personal": "1.0",
"rpc": "1.0",
"txpool": "1.0",
"web3": "1.0",
"geth": "1.0"
}
}
```
20 changes: 20 additions & 0 deletions docs/jsre/integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Integration
These additional API's follow the same conventions as the official DApp API. Web3 can be [extended](https://github.com/ethereumproject/web3.js/pull/229) and used to consume these additional API's.

The different functions are split into multiple smaller logically grouped API's. Examples are given for the [Javascript console](./JavaScript-Console) but can easily be converted to a rpc request.

**2 examples:**

* Console: `miner.start()`

* IPC: `echo '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":1}' | socat -,ignoreeof UNIX-CONNECT:$HOME/.ethereum/geth.ipc`

* RPC: `curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":74}' localhost:8545`

With the number of THREADS as an arguments:

* Console: `miner.start(4)`

* IPC: `echo '{"jsonrpc":"2.0","method":"miner_start","params":["0x04"],"id":1}' | socat -,ignoreeof UNIX-CONNECT:$HOME/.ethereum/geth.ipc`

* RPC: `curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":["0x04"],"id":74}' localhost:8545`
38 changes: 38 additions & 0 deletions docs/jsre/interactive-use.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Interactive use: the JSRE REPL Console

The `ethereum CLI` executable `geth` has a JavaScript console (a **Read, Evaluate & Print Loop** = REPL exposing the JSRE), which can be started with the `console` or `attach` subcommand. The `console` subcommands starts the geth node and then opens the console. The `attach` subcommand will not start the geth node but instead tries to open the console on a running geth instance.

```shell
$ geth 2>>out.log console # redirect logs to a file and begin interactive console session
```

```shell
$ geth # terminal 1
$ geth attach # terminal 2
```

The attach node accepts an endpoint in case the geth node is running with a non default ipc endpoint or you would like to connect over the rpc interface.

$ geth attach ipc:/some/custom/path
$ geth attach http://191.168.1.1:8545
$ geth attach ws://191.168.1.1:8546

Note that by default the geth node doesn't start the http and weboscket service and not all functionality is provided over these interfaces due to security reasons. These defaults can be overridden when the `--rpcapi` and `--wsapi` arguments when the geth node is started, or with [admin.startRPC](admin_startRPC) and [admin.startWS](admin_startWS).

If you need log information, start with:

$ geth --verbosity 5 console 2>> /tmp/eth.log

Otherwise mute your logs, so that it does not pollute your console:

$ geth console 2>> /dev/null

or

$ geth --verbosity 0 console

Geth has support to load custom JavaScript files into the console through the `--preload` argument. This can be used to load often used functions, setup web3 contract objects, or ...
```
geth --preload "/my/scripts/folder/utils.js,/my/scripts/folder/contracts.js" console
```

3 changes: 3 additions & 0 deletions docs/jsre/management-apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Management APIs

Beside the official [DApp API](https://github.com/ethereumproject/wiki/wiki/JSON-RPC) interface the go ethereum node has support for additional management API's. These API's are offered using [JSON-RPC](http://www.jsonrpc.org/specification) and follow the same conventions as used in the DApp API. The go ethereum package comes with a console client which has support for all additional API's.
23 changes: 23 additions & 0 deletions docs/jsre/methods/admin/addPeer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#### admin.addPeer

admin.addPeer(nodeURL)

Pass a `nodeURL` to connect a to a peer on the network. The `nodeURL` needs to be in [enode URL format](https://github.com/ethereumproject/wiki/wiki/enode-url-format). geth will maintain the connection until it
shuts down and attempt to reconnect if the connection drops intermittently.

You can find out your own node URL by using [nodeInfo](#adminnodeinfo) or looking at the logs when the node boots up e.g.:

```
[P2P Discovery] Listening, enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@54.169.166.226:30303
```

##### Returns

`true` on success.

##### Example

```javascript
> admin.addPeer('enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@54.169.166.226:30303')
```
3 changes: 3 additions & 0 deletions docs/jsre/methods/admin/admin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Admin

The `admin` exposes the methods to manage, control or monitor your node. It allows for limited file system access.
17 changes: 17 additions & 0 deletions docs/jsre/methods/admin/datadir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#### admin.datadir

admin.datadir

the directory this nodes stores its data

##### Returns

directory on success

##### Example

```javascript
admin.datadir
'/Users/username/Library/Ethereum'
```
16 changes: 16 additions & 0 deletions docs/jsre/methods/admin/exportChain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#### admin.exportChain

admin.exportChain(file)

Exports the blockchain to the given file in binary format.

##### Returns

`true` on success, otherwise `false`.

##### Example

```javascript
admin.exportChain('path/to/file')
```
18 changes: 18 additions & 0 deletions docs/jsre/methods/admin/getContractInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#### admin.getContractInfo

admin.getContractInfo(address)

this will retrieve the [contract info json](./Contracts-and-Transactions#contract-info-metadata) for a contract on the address

##### Returns

returns the contract info object

##### Examples

```js
> info = admin.getContractInfo(contractaddress)
> source = info.source
> abi = info.abiDefinition
```
19 changes: 19 additions & 0 deletions docs/jsre/methods/admin/importChain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#### admin.importChain

admin.importChain(file)

Imports the blockchain from a marshalled binary format.
**Note** that the blockchain is reset (to genesis) before the imported blocks are inserted to the chain.


##### Returns

`true` on success, otherwise `false`.

##### Example

```javascript
admin.importChain('path/to/file')
// true
```
26 changes: 26 additions & 0 deletions docs/jsre/methods/admin/nodeInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#### admin.nodeInfo

admin.nodeInfo

##### Returns

information on the node.

##### Example

```
> admin.nodeInfo
{
Name: 'Ethereum(G)/v0.9.36/darwin/go1.4.1',
NodeUrl: 'enode://c32e13952965e5f7ebc85b02a2eb54b09d55f553161c6729695ea34482af933d0a4b035efb5600fc5c3ea9306724a8cbd83845bb8caaabe0b599fc444e36db7e@89.42.0.12:30303',
NodeID: '0xc32e13952965e5f7ebc85b02a2eb54b09d55f553161c6729695ea34482af933d0a4b035efb5600fc5c3ea9306724a8cbd83845bb8caaabe0b599fc444e36db7e',
IP: '89.42.0.12',
DiscPort: 30303,
TCPPort: 30303,
Td: '0',
ListenAddr: '[::]:30303'
}
```

To connect to a node, use the [enode-format](https://github.com/ethereumproject/wiki/wiki/enode-url-format) nodeUrl as an argument to [addPeer](#adminaddpeer) or with CLI param `bootnodes`.
15 changes: 15 additions & 0 deletions docs/jsre/methods/admin/peers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#### admin.peers

admin.peers

##### Returns

an array of objects with information about connected peers.

##### Example

```
> admin.peers
[ { ID: '0x6cdd090303f394a1cac34ecc9f7cda18127eafa2a3a06de39f6d920b0e583e062a7362097c7c65ee490a758b442acd5c80c6fce4b148c6a391e946b45131365b', Name: 'Ethereum(G)/v0.9.0/linux/go1.4.1', Caps: 'eth/56, shh/2', RemoteAddress: '54.169.166.226:30303', LocalAddress: '10.1.4.216:58888' } { ID: '0x4f06e802d994aaea9b9623308729cf7e4da61090ffb3615bc7124c5abbf46694c4334e304be4314392fafcee46779e506c6e00f2d31371498db35d28adf85f35', Name: 'Mist/v0.9.0/linux/go1.4.2', Caps: 'eth/58, shh/2', RemoteAddress: '37.142.103.9:30303', LocalAddress: '10.1.4.216:62393' } ]
```
27 changes: 27 additions & 0 deletions docs/jsre/methods/admin/register.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#### admin.register

admin.register(address, contractaddress, contenthash);

will register content hash to the codehash (hash of the code of the contract on contractaddress). The register transaction is sent from the address in the first parameter. The transaction needs to be processed and confirmed on the canonical chain for the registration to take effect.

##### Returns

`true` on success, otherwise `false`.

##### Examples

```js
source = "contract test {\n" +
" /// @notice will multiply `a` by 7.\n" +
" function multiply(uint a) returns(uint d) {\n" +
" return a * 7;\n" +
" }\n" +
"} ";
contract = eth.compile.solidity(source).test;
txhash = eth.sendTransaction({from: primary, data: contract.code });
// after it is uncluded
contractaddress = eth.getTransactionReceipt(txhash);
filename = "/tmp/info.json";
contenthash = admin.saveInfo(contract.info, filename);
admin.register(primary, contractaddress, contenthash);
```
30 changes: 30 additions & 0 deletions docs/jsre/methods/admin/registerUrl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#### admin.registerUrl

admin.registerUrl(address, codehash, contenthash);

this will register a contant hash to the contract' codehash. This will be used to locate [contract info json](./Contracts-and-Transactions#contract-info-metadata)
files. Address in the first parameter will be used to send the transaction.

##### Returns

`true` on success, otherwise `false`.

##### Examples

```js
source = "contract test {\n" +
" /// @notice will multiply `a` by 7.\n" +
" function multiply(uint a) returns(uint d) {\n" +
" return a * 7;\n" +
" }\n" +
"} ";
contract = eth.compile.solidity(source).test;
txhash = eth.sendTransaction({from: primary, data: contract.code });
// after it is uncluded
contractaddress = eth.getTransactionReceipt(txhash);
filename = "/tmp/info.json";
contenthash = admin.saveInfo(contract.info, filename);
admin.register(primary, contractaddress, contenthash);
admin.registerUrl(primary, contenthash, "file://"+filename);
```
Loading

0 comments on commit cf22a08

Please sign in to comment.