You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
updated readme with new changes for setting up config/connections.json for node connection by network. Added endpoints to get block and transaction information as well as syncing
-[Development local node](#development-local-node)
12
+
-[Testnet node](#testnet-node)
13
+
-[Run truffle commands](#run-truffle-commands)
14
+
-[Server](#server)
15
+
-[Adding Networks](#adding-networks)
3
16
-[Notes](#notes)
4
-
17
+
-[Scripts](#scripts)
18
+
-[Bash](#bash)
19
+
-[Helpers](#helpers)
20
+
-[Keystore](#keystore)
21
+
-[Error Debugging](#error-debugging)
22
+
-[Sample Contracts](#sample-contracts)
23
+
-[Version Control]($version-control)
5
24
-[Endpoint Notes](#endpoint-notes)
6
-
25
+
-[Get Block Info](#get-block-info)
26
+
-[Get Transaction Info](#get-transaction-info)
27
+
-[Send Transaction](#send-transaction)
7
28
-[List of All API Endpoints](#endpoints)
8
29
30
+
## Quick Start
31
+
32
+
Install [Ganache](http://truffleframework.com/ganache/) to have a local blockchain and start it. You will see 10 address and a mnemonic phrase. Copy `RPC Server` URL, e.g `HTTP://127.0.0.1:7545`
33
+
34
+
```
35
+
brew cask install ganache
36
+
```
37
+
38
+
Create `.env` in root
39
+
40
+
```
41
+
NODE_URL=http://127.0.0.1:7545
42
+
```
43
+
44
+
Clone repo and start server
45
+
46
+
```
47
+
git clone git@github.com:ar-to/ethereum-api.git
48
+
cd ethereum-api
49
+
npm install
50
+
npm start
51
+
```
52
+
in new terminal
53
+
```
54
+
curl http://localhost:3000/api/eth/syncing
55
+
{"nodeSynced":true}
56
+
```
9
57
10
58
## Getting Started
11
59
12
-
Please read notes for important information before developing.
60
+
Please read [notes](#notes) for important information before developing.
61
+
13
62
14
63
### Run Private Test Node
15
64
@@ -20,44 +69,36 @@ brew cask install ganache
20
69
```
21
70
Open application and it will automatically create 10 addresses. Save the mnemonic phrase if you want to use it again. It will be set the url to `http://127.0.0.1:7545`
22
71
23
-
### Environment Variables
24
-
25
-
Create `.env` file in the root directory and add the following:
72
+
### Config
73
+
Add connections to `config/connections.json`, and set the name of the network you want to use for the API using `"connectApi": "network-name",`
26
74
27
75
```
28
-
#
29
-
# Required by API
30
-
# to connect to correct node
31
-
# add NODE_URL values for different networks but have only one uncommented for use
32
-
# token contract address required for instantiating contract to use its functions
Currently, the best way to change the network you want to have the API connect web3 to, is to change the `NODE_URL`. So you can have multiple values but only have one uncommented. The example below will make the second url enabled.
97
+
You can change the port for the server and overwrite the node url from the connections.json by adding it in a `.env` file at the root directory.
57
98
58
99
```
59
-
#NODE_URL=http://127.0.0.1:7545
60
-
NODE_URL=http://127.0.0.1:8545
100
+
PORT=4000
101
+
NODE_URL=http://127.0.0.1:7545
61
102
```
62
103
63
104
**Remember to restart your server after changing environment variables. If running nodemon run `npm run nodemon` again**
@@ -81,7 +122,9 @@ First add the same OWNER_ACCOUNT address from the environment variable into the
Scripts are added for convenience to allow commands to be performs from the root and for testing.
206
249
207
-
- rpc-call - a curl command via an rpc call to communicated to a node. Remember to change the url:port to connect to the correct node and address when using the `eth_getBalance` method.
250
+
- rpc-call - a curl command via an rpc call to communicated to a node. Remember to change the url:port to connect to the correct node and address when using the `eth_getBalance` method or pass it as an argument:
251
+
```
252
+
sh bin/rpc-call http://127.0.0.1:7545
253
+
```
208
254
209
255
- bash bin/truffle-compile
210
256
@@ -261,13 +307,25 @@ gas cost estimation = 0.0449887 ether
261
307
262
308
Read about what is a [keystore](https://medium.com/@julien.m./what-is-an-ethereum-keystore-file-86c8c5917b97) file and how to make one. Above keystore taken from [here](https://github.com/hashcat/hashcat/issues/1228) If using the geth client for creating your node, you can run `geth account new`, enter your password and check the `keystore/` directory for the keystore file. This directory is next to the chaindata where you are storing the blockchain data.
263
309
310
+
## Error Debugging
311
+
312
+
Setting up can be somewhat complicated if not tedious. Maybe in future releases there will be much more efficient way to setup but for now fixing and understanding error is best to guarantee everything is running correctly. Below are a few warnings or error you may see and possible ways to solve them. More added as they are found. Keep in mind error do not necessarily mean bugs, but it does not mean a bug is not present. If an error turns out to be a bug file an issue and your solution. Thanks.
313
+
314
+
-`Invalid JSON RPC response: ""` - This may show as a response from testing the api endpoint the first time you are connecting to a node. It is a failure to connect by web3 provider. Solution:
315
+
1. restart your server
316
+
2. Check you have the correct node url inside the `.env` file
317
+
3. Make an RPC call to the node using the `bin/rpc-call` script to test for connection. See [scripts section](#scripts) for details
318
+
4. wait until the connection is successful and try the endpoint you got the error again
319
+
320
+
321
+
264
322
## Sample Contracts
265
323
266
324
Sample constracts are used for reference and can be found in `token-contract/samples`.
267
325
268
326
- advancedToken.sol - sample token code that has been fixed to meet solidity v0.4.23. This can be tested by adding it into Mist app. Deploy using TokenERC20 token name.
269
327
270
-
## VC
328
+
## Version Control
271
329
Question about storing artifact files (e.g. Token.json) after truffle compiles contracts with abi and contract addresses for different networks. Community in gitter (chat app) recommended to add to VC but optional not to.
272
330
273
331
-[stackexchange](https://ethereum.stackexchange.com/questions/19486/storing-a-truffle-contract-interface-in-version-control) - recommendation to store outside
@@ -277,14 +335,28 @@ Question about storing artifact files (e.g. Token.json) after truffle compiles c
277
335
278
336
transferOwnership & kill functions both catch an 'invalid address'. The response it 200 with `false` boolean indicating request failed.
279
337
338
+
`api/eth/tx-from-block/hashStringOrNumber` endpoint seems to fail when connected to Ropsten Testnet but not with ganache local node
339
+
340
+
280
341
## Endpoint Notes
281
342
282
-
### Send Transaction info
343
+
The ethereum endpoint for this API uses the [web3js](http://web3js.readthedocs.io/en/1.0/) so parameters for a web3 method is normally supported by the endpoint unless otherwise specified.
344
+
345
+
### Get Block Info
346
+
347
+
The following endpoints can be used to get information about blocks and even transactions.
348
+
349
+
-`/api/eth/tx:txHash` : get transaction details by the transaction hash
350
+
-`api/eth/tx-from-block/hashStringOrNumber` : hashStringOrNumber can be same as in the [web3 docs](http://web3js.readthedocs.io/en/1.0/web3-eth.html#gettransactionfromblock), e.g. `/latest` or `0xa343d89bb0447c8a22c8ce73bf35504d9363e234b2a1a8229d40b69ce3439fc5`. See [bug](#bugs-to-fix) for problem when using it in Ropsten
351
+
352
+
-`api/eth/block/2?showTx=true&useString=latest` : 1 is the blocknumber, the query `showTx` will show the transaction object in the output when set to true, and the query `useString` will overwrite the block number and use one of the strings used in the [getBlock api](http://web3js.readthedocs.io/en/1.0/web3-eth.html#getblock) such as `latest` to get the most recent block.
353
+
354
+
### Get Transaction info
283
355
284
356
285
357
You can get information about the transaction you want to send before sending it. Information like gas, gas price, amount in wei and ether, etc.
286
358
287
-
send the transaction object to the `api/eth/send-tx-info` endpoint
359
+
send a POST request with transaction object below to the `api/eth/send-tx-info` endpoint
0 commit comments