-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
48 lines (41 loc) · 1.41 KB
/
utils.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
const {Api, JsonRpc} = require('eosjs');
const JsSignatureProvider = require('eosjs/dist/eosjs-jssig').default;
const {TextEncoder, TextDecoder} = require('util');
const fetch = require("node-fetch");
let endpoint = 'https://api-kylin.eoslaomao.com';
const customizedFetch = function (input, init) {
let headers = {};
// headers["Authorization"] = `Bearer ${jwtKey}`;
headers["X-Eos-Push-Guarantee"] = "in-block";
init.headers = headers;
return fetch(input, init)
};
const rpc = new JsonRpc(endpoint, {fetch: customizedFetch});
const account_name = "freeheresun1";
const defaultPrivateKey = ""; // freeheresun1
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
const api = new Api({rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder()});
const guestPrivateKey = ""; // freeheresun2
const guestSignatureProvider = new JsSignatureProvider([guestPrivateKey]);
const noAuthApi = new Api({
rpc,
signatureProvider: guestSignatureProvider,
textDecoder: new TextDecoder(),
textEncoder: new TextEncoder()
});
function randomName(len) {
let chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz';
let maxPos = chars.length;
let str = '';
for (i = 0; i < len; i++) {
str += chars.charAt(Math.floor(Math.random() * maxPos));
}
return str;
}
module.exports = {
rpc,
api,
noAuthApi,
account_name,
randomName
};