Rise JS
Rise JS is a JavaScript library for sending Rise transactions. It's main benefit is that it does not require a locally installed Rise node, and instead utilizes the existing peers on the network. It can be used from the client as a browserify compiled module, or on the server as a standard Node.js module.
Installation
npm install rise-js
Tests
npm test
Tests written using mocha + schedule.js.
Usage
On the client:
On the server:
var rise = ;
Generating a key pair
To generate a public / private key pair from a given passphrase:
var keys = risecrypto;
Returning:
publicKey: "5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09" privateKey: "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a2…44491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09"
Generating an address
To generate a unique Rise address from a given public key:
var address = risecrypto;
Returning:
18160565574430594874L
Creating a transaction
To create a signed transaction object, which can then be posted onto the network:
var amount = 1000 * Math; // 100000000000var transaction = risetransaction;
Returning:
type: 0 // Transaction type. 0 = Normal transaction. amount: 100000000000 // The amount to send expressed as an integer value. asset: {} // Transaction asset, dependent on tx type. fee: 100000000 // 0.1 RISE expressed as an integer value. id: "500224999259823996" // Transaction ID. recipientId: "1859190791819301R" // Recipient ID. senderPublicKey: "56e106a1d4a53dbe22cac52fefd8fc4123cfb4ee482f8f25a4fc72eb459b38a5" // Sender's public key. signSignature: "03fdd33bed30270b97e77ada44764cc8628f6ad3bbd84718571695262a5a18baa37bd76a62dd25bc21beacd61eaf2c63af0cf34edb0d191d225f4974cd3aa509" // Sender's second passphrase signature. signature: "9419ca3cf11ed2e3fa4c63bc9a4dc18b5001648e74522bc0f22bda46a188e462da4785e5c71a43cfc0486af08d447b9340ba8b93258c4c7f50798060fff2d709" // Transaction signature. timestamp: 27953413 // Based on UTC time of genesis since epoch.
Network identification with Nethash
You need to obtain the nethash in order to be sure you are posting to the right network (testnet, mainnet or others). The nethash is simply the payload hash from the genesisBlock. If no nethash or wrong nethash is provided in the headers, the request will be rejected returning the expected nethash.
The nethash for a given network can be obtained at the following API endpoint:
/api/blocks/getNetHash
You can also get the nethash from a peer this way:
On the client using jQuery:
var nethash;$;
From a server using Request:
var nethash;;
Posting a transaction
Transaction objects are sent to /peer/transactions
, using the POST
method.
Example:
Method: POSTContent-Type: application/json "transaction" : ...
Sending transaction on the Client
Using jQuery:
var { console;}; $;
Sending transaction on the Server
Using Request:
var request = ; var { console;}; ;
Peer Response
Upon successfully accepting a transaction, the receiving node will respond with:
If the transaction is deemed invalid, or an error is encountered, the receiving node will respond with:
Other transaction types
Creating a delegate transaction
var transaction = risedelegate;
Creating a second signature transaction
var transaction = risesignature;
Creating a vote transaction
var transaction = risevote;
Authors
- Justin Donnaruma justin@rise.vision
License
The MIT License (MIT)
Copyright (c) 2016 Rise
Copyright (c) 2016 Lisk
Copyright (c) 2015 Crypti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.