forked from etherspot/etherspot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-ens.ts
64 lines (47 loc) · 1.4 KB
/
04-ens.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
import { Wallet } from 'ethers';
import { take } from 'rxjs/operators';
import { Sdk } from '../../src';
import { logger, topUpAccount } from './common';
async function main(): Promise<void> {
const wallet = Wallet.createRandom();
logger.log('wallet', wallet.address);
const sdk = new Sdk(wallet);
const { state } = sdk;
const ensTopLevelDomains = await sdk.getENSTopLevelDomains();
if (!ensTopLevelDomains.length) {
logger.info('ens top level domain not found');
return;
}
const notification = sdk.notifications$.pipe(take(1)).toPromise();
logger.log(
'contract account',
await sdk.computeContractAccount({
sync: false,
}),
);
await topUpAccount(state.accountAddress, '0.5');
const ensName = `random${Date.now().toString(16)}.${ensTopLevelDomains[0]}`;
const ensNode = await sdk.reserveENSName({
name: ensName,
});
logger.log('ens node', ensNode);
logger.log('last notification', await notification);
logger.log(
'batch',
await sdk.batchClaimENSNode({
nameOrHashOrAddress: ensName,
}),
);
logger.log('estimated batch', await sdk.estimateGatewayBatch());
logger.log('submitted batch', await sdk.submitGatewayBatch());
// unstoppable domains support
logger.log(
'ens node',
await sdk.getENSNode({
nameOrHashOrAddress: 'brad.crypto',
}),
);
}
main()
.catch(logger.error)
.finally(() => process.exit());