-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvote_transaction.js
37 lines (33 loc) · 1.65 KB
/
vote_transaction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function sendTransatcionToBigChainDB (assetdata){
// BigchainDB server instance or testnetwork (e.g. https://example.com/api/v1/)
//const API_PATH = 'http://192.168.100.126:9984/api/v1/'
const API_PATH = 'http://128.163.232.67:9984/api/v1/'
const DNode = new BigchainDB.Ed25519Keypair()
let createTxId
const DistrictNode = document.querySelector('meta[name="description"]').content;
const metadata = {"Token":"123456789101112131415", "District":+DistrictNode+""}
// Construct a transaction payload
const txCreateDNodeSimple = BigchainDB.Transaction.makeCreateTransaction(
assetdata,
metadata,
// A transaction needs an output
[ BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(DNode.publicKey))
],
DNode.publicKey
)
// Sign the transaction with private keys of DNode to fulfill it
const txCreateDNodeSimpleSigned = BigchainDB.Transaction.signTransaction(txCreateDNodeSimple, DNode.privateKey)
// Send the transaction off to BigchainDB
let conn = new BigchainDB.Connection(API_PATH)
conn.postTransactionCommit(txCreateDNodeSimpleSigned)
.then(res => {
createTxId = res.id
document.body.innerHTML ='<h3>Transaction created</h3>';
document.body.innerHTML+=API_PATH
document.body.innerHTML+='transactions/'
document.body.innerHTML+=txCreateDNodeSimpleSigned.id
document.body.innerhtml.href = API_PATH + 'transactions/' + txCreateDNodeSimpleSigned.id
})
return;
}