eosio-push-guarantee

Push Guarantee

Retry time between push guarantee verification can be set with the DAPP_CLIENT_PUSH_TRANSACTION_SLEEP environment variable, defaults to 10ms.
1
const { PushGuarantee } = require("eosio-push-guarantee");
2
const { Api, JsonRpc, RpcError } = require('eosjs');
3
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
4
const fetch = require('node-fetch'); // node only; not needed in browsers
5
const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder
6
const defaultPrivateKey = "5JMUyaQ4qw6Zt816B1kWJjgRA5cdEE6PhCb2BW45rU8GBEDa1RC"; // bob
7
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
8
const rpc = new JsonRpc('https://kylin-dsp-2.liquidapps.io', { fetch });
9
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
10
​
11
(async () => {
12
const config = {
13
// pushGuarantee: 'none', // push guarantee level for trx
14
// readRetries: 0, // amount of times to try and verify trx before retrying trx
15
// pushRetries: 3, // amount of times to retry trx before failing
16
// backoff: 500, // time in ms between readRetries
17
// backoffExponent: 1.1 // multiplier backoff time for backoff (if 500ms and 1.1 multiplier then 550ms backoff next time, etc)
18
​
19
pushGuarantee: 'in-block',
20
readRetries: 3,
21
​
22
// pushGuarantee: 'handoffs:1',
23
// readRetries: 10,
24
​
25
// pushGuarantee: 'handoffs:2',
26
// readRetries: 20,
27
​
28
// pushGuarantee: 'handoffs:3',
29
// readRetries: 30,
30
31
pushGuarantee: 'irreversible',
32
readRetries: 100,
33
}
34
const push_guarantee_rpc = new PushGuarantee(rpc, config);
35
const account = 'dappservices';
36
const actor = 'vacctstst123';
37
const action = 'transfer';
38
const serializedTrx = await api.transact({
39
actions: [{
40
account,
41
name: action,
42
authorization: [{
43
actor,
44
permission: 'active',
45
}],
46
data: {
47
from: 'vacctstst123',
48
to: 'natdeveloper',
49
quantity: '1.0000 DAPP',
50
memo: ''
51
},
52
}]
53
}, {
54
blocksBehind: 3, // in-block
55
expireSeconds: 30, // in-block
56
​
57
// blocksBehind: 3, // handoffs
58
// expireSeconds: 90, // handoffs
59
60
// expireSeconds: 300, // irreversible
61
// useLastIrreversible: true, // irreversible,
62
63
broadcast: false
64
});
65
const response = await (await getClient()).dappNetwork.push_action(rpc, serializedTrx, config);
66
console.dir(result);
67
})().catch((e) => { console.log(e); });
Copied!
Last modified 5mo ago
Copy link