mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 19:55:54 +00:00
Checks tutorial: separate signing for CheckCreate
This commit is contained in:
10
content/code_samples/checks/cli/sign-req-1.sh
Normal file
10
content/code_samples/checks/cli/sign-req-1.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
rippled sign s████████████████████████████ '{
|
||||
"TransactionType": "CheckCreate",
|
||||
"Account": "rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za",
|
||||
"Destination": "rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis",
|
||||
"SendMax": "100000000",
|
||||
"Expiration": 570113521,
|
||||
"InvoiceID": "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
"DestinationTag": 1,
|
||||
"Fee": "12"
|
||||
}'
|
||||
24
content/code_samples/checks/cli/sign-resp-1.txt
Normal file
24
content/code_samples/checks/cli/sign-resp-1.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
Loading: "/home/mduo13/.config/ripple/rippled.cfg"
|
||||
2018-Mar-21 21:00:05 HTTPClient:NFO Connecting to 127.0.0.1:5005
|
||||
|
||||
{
|
||||
"result" : {
|
||||
"status" : "success",
|
||||
"tx_blob" : "120010228000000024000000012A21FB3DF12E00000001501146060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE29168400000000000000C694000000005F5E100732103B6FCD7FAC4F665FE92415DD6E8450AD90F7D6B3D45A6CFCF2E359045FF4BB40074473045022100EB5A9001E14FC7304C4C2DF66507F9FC59D17FDCF98B43A4E30356658AB2A7CF02207127187EE0F287665D9552D15BEE6B00D3C6691C6773CE416E8A714B853F44FC8114735FF88E5269C80CD7F7AF10530DAB840BBF6FDF8314A8B6B9FF3246856CADC4A0106198C066EA1F9C39",
|
||||
"tx_json" : {
|
||||
"Account" : "rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za",
|
||||
"Destination" : "rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis",
|
||||
"DestinationTag" : 1,
|
||||
"Expiration" : 570113521,
|
||||
"Fee" : "12",
|
||||
"Flags" : 2147483648,
|
||||
"InvoiceID" : "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
"SendMax" : "100000000",
|
||||
"Sequence" : 1,
|
||||
"SigningPubKey" : "03B6FCD7FAC4F665FE92415DD6E8450AD90F7D6B3D45A6CFCF2E359045FF4BB400",
|
||||
"TransactionType" : "CheckCreate",
|
||||
"TxnSignature" : "3045022100EB5A9001E14FC7304C4C2DF66507F9FC59D17FDCF98B43A4E30356658AB2A7CF02207127187EE0F287665D9552D15BEE6B00D3C6691C6773CE416E8A714B853F44FC",
|
||||
"hash" : "07C3B2878B6941FED97BA647244531B7E2203268B05C71C3A1A014045ADDF408"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
content/code_samples/checks/cli/submit-create-req-1.sh
Normal file
1
content/code_samples/checks/cli/submit-create-req-1.sh
Normal file
@@ -0,0 +1 @@
|
||||
rippled submit 120010228000000024000000012A21FB3DF12E00000001501146060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE29168400000000000000C694000000005F5E100732103B6FCD7FAC4F665FE92415DD6E8450AD90F7D6B3D45A6CFCF2E359045FF4BB40074473045022100EB5A9001E14FC7304C4C2DF66507F9FC59D17FDCF98B43A4E30356658AB2A7CF02207127187EE0F287665D9552D15BEE6B00D3C6691C6773CE416E8A714B853F44FC8114735FF88E5269C80CD7F7AF10530DAB840BBF6FDF8314A8B6B9FF3246856CADC4A0106198C066EA1F9C39
|
||||
9
content/code_samples/checks/js/package.json
Normal file
9
content/code_samples/checks/js/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
33
content/code_samples/checks/js/prepareCreate.js
Normal file
33
content/code_samples/checks/js/prepareCreate.js
Normal 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)
|
||||
2
content/code_samples/checks/js/sign-resp-example.txt
Normal file
2
content/code_samples/checks/js/sign-resp-example.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
tx_blob is: 12001022800000002400000001201B0075139F68400000000000000C694000000005F5E100732103B6FCD7FAC4F665FE92415DD6E8450AD90F7D6B3D45A6CFCF2E359045FF4BB4007446304402204B5DA588DC2B9B9E52248129F07083AE71039CBDD8A87F58583853A4A9A8461B02205973D04A9F97EE0684DB98D4EC813CF748806019751062FB600406D8BE95D18D8114735FF88E5269C80CD7F7AF10530DAB840BBF6FDF8314A8B6B9FF3246856CADC4A0106198C066EA1F9C39
|
||||
tx hash is: DC334D25AA70A4412E8EA80D3199414C5D8579DFD3F085E5AF7CE35C334F5246
|
||||
21
content/code_samples/checks/js/signCreate.js
Normal file
21
content/code_samples/checks/js/signCreate.js
Normal 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)
|
||||
26
content/code_samples/checks/js/submitCreate.js
Normal file
26
content/code_samples/checks/js/submitCreate.js
Normal 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)
|
||||
15
content/code_samples/checks/websocket/sign-req-1.json
Normal file
15
content/code_samples/checks/websocket/sign-req-1.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"id": "sign_req_1",
|
||||
"command": "sign",
|
||||
"tx_json": {
|
||||
"TransactionType": "CheckCreate",
|
||||
"Account": "rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za",
|
||||
"Destination": "rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis",
|
||||
"SendMax": "100000000",
|
||||
"Expiration": 570113521,
|
||||
"InvoiceID": "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
"DestinationTag": 1,
|
||||
"Fee": "12"
|
||||
},
|
||||
"secret" : "s████████████████████████████"
|
||||
}
|
||||
23
content/code_samples/checks/websocket/sign-resp-1.json
Normal file
23
content/code_samples/checks/websocket/sign-resp-1.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"id": "sign_req_1",
|
||||
"result": {
|
||||
"tx_blob": "120010228000000024000000012A21FB3DF12E00000001501146060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE29168400000000000000C694000000005F5E100732103B6FCD7FAC4F665FE92415DD6E8450AD90F7D6B3D45A6CFCF2E359045FF4BB40074473045022100EB5A9001E14FC7304C4C2DF66507F9FC59D17FDCF98B43A4E30356658AB2A7CF02207127187EE0F287665D9552D15BEE6B00D3C6691C6773CE416E8A714B853F44FC8114735FF88E5269C80CD7F7AF10530DAB840BBF6FDF8314A8B6B9FF3246856CADC4A0106198C066EA1F9C39",
|
||||
"tx_json": {
|
||||
"Account": "rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za",
|
||||
"Destination": "rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis",
|
||||
"DestinationTag": 1,
|
||||
"Expiration": 570113521,
|
||||
"Fee": "12",
|
||||
"Flags": 2147483648,
|
||||
"InvoiceID": "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
"SendMax": "100000000",
|
||||
"Sequence": 1,
|
||||
"SigningPubKey": "03B6FCD7FAC4F665FE92415DD6E8450AD90F7D6B3D45A6CFCF2E359045FF4BB400",
|
||||
"TransactionType": "CheckCreate",
|
||||
"TxnSignature": "3045022100EB5A9001E14FC7304C4C2DF66507F9FC59D17FDCF98B43A4E30356658AB2A7CF02207127187EE0F287665D9552D15BEE6B00D3C6691C6773CE416E8A714B853F44FC",
|
||||
"hash": "07C3B2878B6941FED97BA647244531B7E2203268B05C71C3A1A014045ADDF408"
|
||||
}
|
||||
},
|
||||
"status": "success",
|
||||
"type": "response"
|
||||
}
|
||||
Reference in New Issue
Block a user