|
21 | 21 | - [Error Debugging](#error-debugging) |
22 | 22 | - [Sample Contracts](#sample-contracts) |
23 | 23 | - [Version Control]($version-control) |
| 24 | +- [Connections](#Connections) |
24 | 25 | - [Endpoint Notes](#endpoint-notes) |
25 | 26 | - [Get Block Info](#get-block-info) |
26 | 27 | - [Get Transaction Info](#get-transaction-info) |
27 | 28 | - [Send Transaction](#send-transaction) |
| 29 | +- [Webhook](#webhook) |
| 30 | +- [Websockets](#websockets) |
28 | 31 | - [List of All API Endpoints](#endpoints) |
29 | 32 |
|
30 | 33 | ## Quick Start |
@@ -338,12 +341,54 @@ Question about storing artifact files (e.g. Token.json) after truffle compiles c |
338 | 341 | - [stackexchange](https://ethereum.stackexchange.com/questions/19486/storing-a-truffle-contract-interface-in-version-control) - recommendation to store outside |
339 | 342 | - [artifact-updates](https://github.com/trufflesuite/artifact-updates) - community repo for updating some issues with doing this. |
340 | 343 |
|
| 344 | +## Connections |
| 345 | + |
| 346 | +Full example of `connections.json` |
| 347 | + |
| 348 | +``` |
| 349 | +{ |
| 350 | + "networks": { |
| 351 | + "connectApi": "ropsten", |
| 352 | + "ganache":{ |
| 353 | + "url": "http://127.0.0.1:7545", |
| 354 | + "websocketUrl": "'ws://localhost:7545", |
| 355 | + "networkId": "5777", |
| 356 | + "networkName": "ganache", |
| 357 | + "networkType": "testrpc", |
| 358 | + "token": { |
| 359 | + "ownerAddress": "0x451E62137891156215d9D58BeDdc6dE3f30218e7", |
| 360 | + "tokenContractAddress": "0x4c59b696552863429d25917b52263532af6e6078", |
| 361 | + "migrateContractAddress": "0xcf068555df7eab0a9bad97829aa1a187bbffbdba" |
| 362 | + } |
| 363 | + }, |
| 364 | + "ropsten":{ |
| 365 | + "url": "http://10.10.0.163:8545", |
| 366 | + "websocketUrl": "ws://10.10.0.163:8546", |
| 367 | + "blockWebhookUrl": "http://4f5a64ba.ngrok.io/api/eth/webhook", |
| 368 | + "syncingWebhookUrl": "http://4f5a64ba.ngrok.io/api/eth/webhook", |
| 369 | + "testWebhookUrl": "http://4f5a64ba.ngrok.io/api/eth/webhook", |
| 370 | + "networkId": 3, |
| 371 | + "networkName": "ropsten", |
| 372 | + "networkType": "testnet", |
| 373 | + "token": { |
| 374 | + "ownerAddress": "0x83634a8eaadc34b860b4553e0daf1fac1cb43b1e", |
| 375 | + "tokenContractAddress": "0x3e672122bfd3d6548ee1cc4f1fa111174e8465fb", |
| 376 | + "migrateContractAddress": "0xa8ebf36b0a34acf98395bc5163103efc37621052" |
| 377 | + } |
| 378 | + }, |
| 379 | + "mainnet":{} |
| 380 | + } |
| 381 | +} |
| 382 | +``` |
| 383 | + |
341 | 384 | ## Bugs to Fix |
342 | 385 |
|
343 | 386 | transferOwnership & kill functions both catch an 'invalid address'. The response it 200 with `false` boolean indicating request failed. |
344 | 387 |
|
345 | 388 | `api/eth/tx-from-block/hashStringOrNumber` endpoint seems to fail when connected to Ropsten Testnet but not with ganache local node |
346 | 389 |
|
| 390 | +`` subscription does not seem to work and or do |
| 391 | + |
347 | 392 |
|
348 | 393 | ## Endpoint Notes |
349 | 394 |
|
@@ -506,6 +551,85 @@ See [web3 api](http://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#signtr |
506 | 551 | } |
507 | 552 | ``` |
508 | 553 |
|
| 554 | +## Webhook |
| 555 | + |
| 556 | +Webhooks allow data to be sent as POST request to an external url specified in the `config/connections.json` iside the `blockWebhookUrl` paramater. |
| 557 | + |
| 558 | +**To use this webhook you need to have websockets connected see [websockets](#websockets) for more information** |
| 559 | + |
| 560 | +``` |
| 561 | +"ropsten":{ |
| 562 | + ... |
| 563 | + "blockWebhookUrl": "http://4f5a64ba.ngrok.io/api/eth/webhook", |
| 564 | + "testWebhookUrl": "http://4f5a64ba.ngrok.io/api/eth/webhook", |
| 565 | + ... |
| 566 | +}, |
| 567 | +``` |
| 568 | + |
| 569 | +The `testWebhookUrl` parameter is used for testing but following these instructions: |
| 570 | + |
| 571 | +Run this api server and then run these |
| 572 | + |
| 573 | +``` |
| 574 | +brew cask install ngrok |
| 575 | +ngrok http 3000 |
| 576 | +``` |
| 577 | +grab the ngrok url and add it the `testWebhookUrl` parameter e.g.`http://4f5a64ba.ngrok.io/api/eth/webhook`. |
| 578 | + |
| 579 | +Then open the debug url for ngrok e.g. `http://127.0.0.1:4040` |
| 580 | + |
| 581 | +Send a post request to `http://localhost:3000/api/eth/post-to-webhook` and watch two request show, one for the request and the second that send another POST request to the `/api/eth/webhook` endpoint |
| 582 | + |
| 583 | +## Websockets |
| 584 | + |
| 585 | +A websocket connection to the node is used to subscribe to events (e.g. new blocks, transactions, see [web3 api](http://web3js.readthedocs.io/en/1.0/web3-eth-subscribe.html)) and required to use the webhook feature which sends these subscriptions to a specified url. |
| 586 | + |
| 587 | +**Setup** |
| 588 | + |
| 589 | +You need to enable a websocket connection inside the node and add that url to the `connections.json` |
| 590 | + |
| 591 | +``` |
| 592 | +``` |
| 593 | +"ropsten":{ |
| 594 | + ... |
| 595 | + "websocketUrl": "ws://10.10.0.163:8546", |
| 596 | + ... |
| 597 | +}, |
| 598 | +``` |
| 599 | +
|
| 600 | +or `.env` files which will overwrite the connections.json parameter |
| 601 | +
|
| 602 | +``` |
| 603 | +WEBSOCKET_URL=ws://127.0.0.1:8546 |
| 604 | +``` |
| 605 | +
|
| 606 | +Websockets are an experimental feature, and the code can be found inside `server/app/helpers/web3-websocket.js` |
| 607 | +There is one `subscriptionType` that is corrently tested and working: |
| 608 | +
|
| 609 | +``` |
| 610 | + blockSubscription |
| 611 | +``` |
| 612 | +
|
| 613 | +Another is to get status on the syncing of the node with the most current block. **Needs more testing so use with caution** |
| 614 | + |
| 615 | +``` |
| 616 | + syncingSubscription |
| 617 | +``` |
| 618 | +
|
| 619 | +**Create subscription** |
| 620 | +To create a subscription to block headers so every new block will be emitted and POSTed to a webhook url. |
| 621 | +
|
| 622 | +``` |
| 623 | +http://localhost:3000/api/eth/subscribe-block |
| 624 | +``` |
| 625 | +
|
| 626 | +**Remove Subscription** |
| 627 | +
|
| 628 | +``` |
| 629 | +http://localhost:3000/api/eth/close-subscriptions/blockSubscription |
| 630 | +http://localhost:3000/api/eth/close-subscriptions/syncingSubscription |
| 631 | +``` |
| 632 | +
|
509 | 633 | ## Endpoints |
510 | 634 |
|
511 | 635 | ``` |
|
0 commit comments