-
Notifications
You must be signed in to change notification settings - Fork 1
/
claim.js
62 lines (54 loc) · 1.5 KB
/
claim.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
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 CLAIM_VOTE_CONTRACT = 'eosio';
const CLAIM_VOTE_ACTION = 'claimgbmvote';
const claimVote = async (actor, permission) => {
try
{
const result = await api.transact({
actions: [{
account: CLAIM_VOTE_CONTRACT,
name: CLAIM_VOTE_ACTION,
authorization: [{
actor: actor,
permission: permission,
}],
data: {
owner: actor
},
}]
}, {
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() => {
claimVote('saschaahcsas', 'claimgbmvote');
claimVote('fx', 'claimgbmvote');
claimVote('fabriceisone', 'claimgbmvote');
}
main();