-
Notifications
You must be signed in to change notification settings - Fork 3
WebSocket API
KeyChain contains a WebSocket API. This API can be used to stream information from a KeyChain instance to any client that implements WebSockets. Implementations in different languages:
- NodeJS
- Python
- JavaScript/HTML
- etc
Install KeyChain for macOS.
-
On this demo page you can test all the KeyChain commands.
-
Here you will find the code of the KeyChain demo page. It will be automatically installed together with the KeyChain.
-
Here you can try out signing Ethereum transactions with KeyChain.
-
You can find an example of the code here.
Each WebSocket API message is a json serialized object containing a command with the corresponding parameters.
For example, here is a request for the current version:
{"command":"version"}
For full comprehensive descriptions of the commands, acceptable parameters and values, go to the Protocol.
The following will show the usage of websocket connections. We make use of the wscat
application available via npm:
$ npm install -g wscat
A simple call would take the form:
$ wscat -c ws://127.0.0.1:16384
> { "command": "version"}
The API will return a properly JSON formated response carrying the same id as the request to distinguish subsequent calls.
{"result": ..data..}
In case of an error, the resulting answer will carry an error attribute and a description in human-readable format:
{"error":"Error: keyfile could not found by keyname"}
Before you proceed with the integration, you need to install KeyChain for macOS.
After installing KeyChain, open the browser and connect to the demo page via http://localhost:16384/.
When the connection is established, you will see the following KeyChain page. If you click on one of the commands on the left panel, you will see its json request and response in the white boxes below:
You can see if the installation was successful by going to the terminal app, opening KeyChain and trying one of the commands that you can take from the Protocol:
c:\Users\User-1>cd "C: Program Files\WsKeychain"
c:\Program Files\WSKeychain>keychain
{"command":"version"}
A successful response will take the following format:
Field name | Type | Description |
---|---|---|
result | string |
current version number which has the form of "[major].[minor].[build number]". |
{"result":"0.9.114"}
Here you will find an example of how to build a web-page that connects to WebSocket.
Save this to the folder where you will be running the websocket
command.
Open this page via localhost: http://localhost:16384/
You can find the code for the demo page and the page itself up in the Demo pages in JavaScript section.