forked from ar-io/testnet-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuy-arns-name-atomic-ant.ts
77 lines (68 loc) · 1.92 KB
/
buy-arns-name-atomic-ant.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
import { JWKInterface } from 'arweave/node/lib/wallet';
import * as fs from 'fs';
import { Tag } from 'warp-contracts';
import { keyfile } from './constants';
import { arweave, initialize, warp } from './utilities';
/* eslint-disable no-console */
(async () => {
// simple setup script
initialize();
// the name to buy
const domainName = 'atomic-ant-10';
// source code tx for ANT (must be in approved list)
const ANT_SOURCE_CODE_TX_ID = 'PEI1efYrsX08HUwvc6y-h6TSpsNlo2r6_fWL2_GdwhY';
// pointer for @ ant record
const ANT_PRIMARY_POINTER_TX_ID = '';
// ant name
const ANT_NAME = 'Atomic ANT';
// ant ticker
const ANT_TICKER = 'ANT';
// load local wallet
const wallet: JWKInterface = JSON.parse(
process.env.JWK ? process.env.JWK : fs.readFileSync(keyfile).toString(),
);
// load state of contract
const arnsContractTxId =
process.env.ARNS_CONTRACT_TX_ID ??
'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U';
// wallet address
const walletAddress = await arweave.wallets.getAddress(wallet);
const initialState = {
name: ANT_NAME,
owner: walletAddress,
evolve: null,
ticker: ANT_TICKER,
records: {
'@': {
transactionId: ANT_PRIMARY_POINTER_TX_ID,
},
},
balances: {
walletAddress: 1,
},
controller: walletAddress,
};
const appNameTag = new Tag('App-Name', 'SmartWeaveAction');
const contractTag = new Tag('Contract', arnsContractTxId);
const inputTag = new Tag(
'Input',
JSON.stringify({
function: 'buyRecord',
name: domainName,
contractTxId: 'atomic',
}),
);
const { contractTxId } = await warp.deployFromSourceTx(
{
wallet,
initState: JSON.stringify(initialState),
srcTxId: ANT_SOURCE_CODE_TX_ID,
tags: [appNameTag, contractTag, inputTag],
},
true,
);
console.log(
'Successfully submitted atomic ANT creation and name purchase TX id: ',
contractTxId,
);
})();