forked from etherspot/etherspot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
08-gateway.ts
114 lines (88 loc) · 2.66 KB
/
08-gateway.ts
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
108
109
110
111
112
113
114
import { Sdk, sleep } from '../../src';
import { logger, topUpAccount, randomAddress, randomWallet } from './common';
async function main(): Promise<void> {
const ownerWallet = randomWallet();
const externalWallet = randomWallet();
logger.log('owner wallet', ownerWallet.address);
logger.log('external wallet', externalWallet.address);
await topUpAccount(ownerWallet.address, '0.5');
await topUpAccount(externalWallet.address, '0.5');
const sdk = new Sdk(ownerWallet);
logger.log(
'contract account',
await sdk.computeContractAccount({
sync: false,
}),
);
{
logger.info('sending batch using owner wallet');
logger.log(
'owner wallet batch #1',
await sdk.batchAddAccountOwner({
owner: randomAddress(),
}),
);
logger.log(
'owner wallet batch #2',
await sdk.batchAddAccountOwner({
owner: randomAddress(),
}),
);
const transactionRequest = await sdk.encodeGatewayBatch();
logger.log('transaction request', transactionRequest);
const transactionResponse = await ownerWallet.sendTransaction(transactionRequest);
logger.log('transaction response', transactionResponse);
logger.log('transaction', await transactionResponse.wait());
}
{
logger.info('sending batch using external wallet');
logger.log(
'batch #1',
await sdk.batchAddAccountOwner({
owner: randomAddress(),
}),
);
logger.log(
'batch #2',
await sdk.batchAddAccountOwner({
owner: randomAddress(),
}),
);
const transactionRequest = await sdk.encodeGatewayBatch({
delegate: true, // use delegate for external wallets
});
logger.log('transaction request', transactionRequest);
const transactionResponse = await externalWallet.sendTransaction(transactionRequest);
logger.log('transaction response', transactionResponse);
logger.log('transaction', await transactionResponse.wait());
}
{
logger.info('sending batch using gateway');
await topUpAccount(sdk.state.accountAddress, '0.5');
logger.log(
'batch #1',
await sdk.batchAddAccountOwner({
owner: randomAddress(),
}),
);
logger.log(
'batch #2',
await sdk.batchAddAccountOwner({
owner: randomAddress(),
}),
);
logger.log('estimated batch', await sdk.estimateGatewayBatch());
const submittedBatch = await sdk.submitGatewayBatch();
const { hash } = submittedBatch;
await sleep(5);
logger.log(
'submitted batch',
await sdk.getGatewaySubmittedBatch({
hash,
}),
);
}
}
main()
.catch(logger.error)
.finally(() => process.exit());