-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
107 lines (89 loc) · 2.56 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @author yahuang.wu
* @date : 2018.10.15
*/
var express = require('express');
var app = express();
//启动gzip压缩
var compression = require('compression');
app.use(compression());
//操作日期的插件
var moment = require('moment');
Eos = require('eosjs');
config = {
chainId: 'd5939d04aeea3cfa82a0d2ba341cc80f4d24781d93b1d6608b5d9afd54bfbe0a',
keyProvider: '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', // This is test only keys and should never be used for the production blockchain.
httpEndpoint: 'http://127.0.0.1:8888',
expireInSeconds: 60,
broadcast: true,
verbose: false, // API activity
sign: true
};
var faucetAccount = 'eosio.faucet';
eos = Eos(config);
app.get('/newaccount', function (req, res) {
// generate public and private key pair
var PrivateKey = Eos.modules.ecc.PrivateKey;
var newAccountName = req.query.name;
PrivateKey.randomKey().then(function (d) {
var privkey = d.toWif();
var publicKey = d.toPublic().toString();
// create new account
eos.transaction(function (tr) {
tr.newaccount({
creator: faucetAccount,
name: newAccountName,
owner: publicKey,
active: publicKey
});
tr.buyrambytes({
payer: faucetAccount,
receiver: newAccountName,
bytes: 4096
});
tr.delegatebw({
from: faucetAccount,
receiver: newAccountName,
stake_net_quantity: '50.0000 MEETONE',
stake_cpu_quantity: '50.0000 MEETONE',
transfer: 1
});
tr.transfer({
from: faucetAccount,
to: newAccountName,
quantity: "900.0000 MEETONE",
memo: "from eosio.faucet"
});
}).then(function () {
res.send({
accountName: newAccountName,
publicKey: publicKey,
privateKey: privkey,
});
}).catch(function (result) {
console.log(result);
res.send(result.toString());
});
});
});
// get more 1000 MEETONE token
app.get('/get_token', function (req, res) {
var newAccountName = req.query.name;
eos.transaction(function (tr) {
tr.transfer({
from: faucetAccount,
to: newAccountName,
quantity: "1000.0000 MEETONE",
memo: "from eosio.faucet"
});
}).then(function () {
res.send({status: 'success'});
}).catch(function (result) {
console.log(result);
res.send(result.toString());
});
});
var port = 6677;
//监听端口
app.listen(port);
console.log('%s | node server initializing | listening on port %s | process id %s', moment().format('YYYY-MM-DD HH:mm:ss.SSS'), port, process.pid);