-
Notifications
You must be signed in to change notification settings - Fork 1
/
voteproducer.js
64 lines (56 loc) · 1.65 KB
/
voteproducer.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
const { Api, JsonRpc, RpcError } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
const {defaultPrivateKey, node} = require(`./config.json`);
global.nativeFetch = require('node-fetch')
global.fetch = (url, args = {}) => {
args.headers = args.headers || {}
args.headers['user-agent'] = 'LifeWithSascha';
return nativeFetch(url, args)
}
global.WebSocket = require('ws')
const { TextEncoder, TextDecoder } = require('util');
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
const rpc = new JsonRpc(node, { fetch });
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const SET_VOTE_PRODUCER_CONTRACT = 'eosio';
const SET_VOTE_PRODUCER_ACTION = 'voteproducer';
const setVoteProducer = async (actor, permission, proxy) => {
try
{
const result = await api.transact({
actions: [{
account: SET_VOTE_PRODUCER_CONTRACT,
name: SET_VOTE_PRODUCER_ACTION,
authorization: [{
actor: actor,
permission: permission,
}],
data: {
voter: actor,
proxy: proxy,
producers: [],
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
}
catch (e)
{
if (e instanceof RpcError)
{
console.log(JSON.stringify(e.json, null, 2));
}
else
{
console.log(e);
}
}
}
const main = async() => {
setVoteProducer('saschaahcsas', 'voteproducer', 'waxcommunity');
setVoteProducer('fx', 'voteproducer', 'waxcommunity');
setVoteProducer('fabriceisone', 'voteproducer', 'waxcommunity');
}
main();