Checks tutorial: separate signing for CheckCreate

This commit is contained in:
mDuo13
2018-03-21 15:14:54 -07:00
parent f335bcaa41
commit ab596fd371
12 changed files with 258 additions and 51 deletions

View File

@@ -0,0 +1,9 @@
{
"name": "checks-examples",
"description": "Example code for signing and submitting Checks with RippleAPI",
"version": "0.0.1",
"license": "MIT",
"dependencies": {
"ripple-lib": "^0.19.0"
}
}

View File

@@ -0,0 +1,33 @@
'use strict'
const RippleAPI = require('ripple-lib').RippleAPI
// This example connects to a public Test Net server
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
api.connect().then(() => {
console.log('Connected')
const sender = 'rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za'
const receiver = 'rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis'
const options = {
// Allow up to 60 ledger versions (~5 min) instead of the default 3 versions
// before this transaction fails permanently.
"maxLedgerVersionOffset": 60
}
return api.prepareCheckCreate(sender, {
"destination": receiver,
"sendMax": {
"currency": "XRP",
"value": "100" // RippleAPI uses decimal XRP, not integer drops
}
}, options)
}).then(prepared => {
console.log("txJSON:", prepared.txJSON);
// Disconnect and return
}).then(() => {
api.disconnect().then(() => {
console.log('Disconnected')
process.exit()
})
}).catch(console.error)

View File

@@ -0,0 +1,2 @@
tx_blob is: 12001022800000002400000001201B0075139F68400000000000000C694000000005F5E100732103B6FCD7FAC4F665FE92415DD6E8450AD90F7D6B3D45A6CFCF2E359045FF4BB4007446304402204B5DA588DC2B9B9E52248129F07083AE71039CBDD8A87F58583853A4A9A8461B02205973D04A9F97EE0684DB98D4EC813CF748806019751062FB600406D8BE95D18D8114735FF88E5269C80CD7F7AF10530DAB840BBF6FDF8314A8B6B9FF3246856CADC4A0106198C066EA1F9C39
tx hash is: DC334D25AA70A4412E8EA80D3199414C5D8579DFD3F085E5AF7CE35C334F5246

View File

@@ -0,0 +1,21 @@
'use strict'
const RippleAPI = require('ripple-lib').RippleAPI
// Can sign offline if the txJSON has all required fields
const api = new RippleAPI()
const txJSON = '{"Account":"rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za", \
"TransactionType":"CheckCreate", \
"Destination":"rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis", \
"SendMax":"100000000", \
"Flags":2147483648, \
"LastLedgerSequence":7672735, \
"Fee":"12", \
"Sequence":1}'
// Be careful where you store your real secret.
const secret = 's████████████████████████████'
const signed = api.sign(txJSON, secret)
console.log("tx_blob is:", signed.signedTransaction)
console.log("tx hash is:", signed.id)

View File

@@ -0,0 +1,26 @@
'use strict'
const RippleAPI = require('ripple-lib').RippleAPI
// This example connects to a public Test Net server
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
api.connect().then(() => {
console.log('Connected')
const tx_blob = "12001022800000002400000001201B0075139F68400000000000000C69"+
"4000000005F5E100732103B6FCD7FAC4F665FE92415DD6E8450AD90F7D6B3D45A6CFCF2E"+
"359045FF4BB4007446304402204B5DA588DC2B9B9E52248129F07083AE71039CBDD8A87F"+
"58583853A4A9A8461B02205973D04A9F97EE0684DB98D4EC813CF748806019751062FB60"+
"0406D8BE95D18D8114735FF88E5269C80CD7F7AF10530DAB840BBF6FDF8314A8B6B9FF32"+
"46856CADC4A0106198C066EA1F9C39"
return api.submit(tx_blob)
}).then(response => {
console.log("Preliminary transaction result:", response.resultCode)
// Disconnect and return
}).then(() => {
api.disconnect().then(() => {
console.log('Disconnected')
process.exit()
})
}).catch(console.error)