-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.js
62 lines (42 loc) · 1.36 KB
/
generate.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var inquirer = require('inquirer');
var createPdf = require('./lib/createPDF.js');
var eth = require('./lib/ethereum.js');
var ipfs=require('./lib/ipfs.js')
var fs = require('fs');
var util = require('ethereumjs-util');// /v
inquirer.prompt([{
name: 'privatekey',
type: 'input',
message: 'Enter private key of issuier wallet==> ',
}]).then((answers) => {
var ipfsHash;
var privateKey=answers.privatekey.substring(2);
var address="0x"+util.privateToAddress(answers.privatekey).toString('hex');
createPdf().then(function(result){
return ipfs.addCertificate(result);
}).then(function(result){
ipfsHash=result;
return eth.getNonce(address)
}).then(function(result){
const txParams = {
nonce:result,
gasPrice: '0x4a817c800',
gasLimit: '0x125000',
to: '0x5B019c67A26A9e66ac2Bbb7369Cef66Ba40140dD',
value: '0x00',
data: ipfsHash,
// EIP 155 chainId - mainnet: 1, ropsten: 3
chainId: 42
}
return eth.blockifyCertificate(privateKey,txParams)
}).then(function(result){
console.log("Transaction hash, you need this to verify the certificate on blockchain::::"+result)
return createPdf(result)
}).then(function(result){
fs.writeFile('./certificate/certificate'+new Date().toUTCString()+'.pdf',result, function (err,data) {
if (err) {
return console.log(err);
}
console.log("Certicate generated in Certicate folder");
})})
});