-
Notifications
You must be signed in to change notification settings - Fork 0
/
claimAndWrapName.js
66 lines (53 loc) · 2.13 KB
/
claimAndWrapName.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
63
64
65
66
require('dotenv').config({ path: '.env.local' });
const { AeSdk, MemoryAccount, Node } = require('@aeternity/aepp-sdk');
// https://github.com/GoogleChromeLabs/jsbi/issues/30#issuecomment-953187833
BigInt.prototype.toJSON = function() { return this.toString() }
const shutdown = (varName) => {
console.error(`Missing ENV variable: ${varName}`);
process.exit(1);
}
if(!process.env.SECRET_KEY_ACCOUNT_1) {
shutdown('SECRET_KEY_ACCOUNT_1');
}
if(!process.env.CONTRACT_ID) {
shutdown('CONTRACT_ID');
}
if(!process.env.AENS_NAME) {
shutdown('AENS_NAME');
}
const contractId = process.env.CONTRACT_ID;
const aensName = process.env.AENS_NAME;
// run 'generateBytecodeAndAci.js' first
const aci = require('../generated_artifacts/aci.json');
const AE_NETWORK = process.env.AE_NETWORK || 'TESTNET'
const SETTINGS = {
TESTNET: {
nodeUrl: 'https://testnet.aeternity.io'
},
MAINNET: {
nodeUrl: 'https://mainnet.aeternity.io'
}
}
const main = async () => {
const node = new Node(SETTINGS[AE_NETWORK].nodeUrl);
const aeSdk = new AeSdk({
nodes: [
{ name: AE_NETWORK, instance: node },
],
accounts: [new MemoryAccount(process.env.SECRET_KEY_ACCOUNT_1)],
});
// make sure to have enough AE balance to cover the name fee
const preClaimTx = await aeSdk.aensPreclaim(aensName);
// note: there will be a "timeout" until a new keyblock is mined before the actual NameClaimTx can be mined
await aeSdk.aensClaim(aensName, preClaimTx.salt);
const contract = await aeSdk.initializeContract({ aci, address: contractId });
const delegationSignature = await aeSdk.createDelegationSignature(contractId, [aensName]);
const namesDelegationSigs = new Map([[aensName, delegationSignature]]);
const wrapAndMintTx = await contract.wrap_and_mint(namesDelegationSigs);
const nftId = wrapAndMintTx.decodedResult;
const nftData = (await contract.get_nft_data(nftId)).decodedResult;
console.log(`TX hash: ${wrapAndMintTx.txData.hash}`);
console.log(`NFT ID: ${wrapAndMintTx.decodedResult}`);
console.log(`NFT data: ${JSON.stringify(nftData)}`);
}
main();