This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
buy-arns-name.ts
75 lines (65 loc) · 2.06 KB
/
buy-arns-name.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
import { IOState } from '../src/types';
import {
arnsContractTxId,
getContractManifest,
initialize,
loadWallet,
warp,
} from './utilities';
/* eslint-disable no-console */
(async () => {
// simple setup script
initialize();
//~~~~~~~~~~~~~~~~~~~~~~~~~~UPDATE THE BELOW~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This is the name that will be purchased in the Arweave Name System Registry
const nameToBuy = process.env.ARNS_NAME ?? 'a-test-name';
// This is the ANT Smartweave Contract TX ID that will be added to the registry. It must follow the ArNS ANT Specification
const contractTxId =
process.env.ANT_CONTRACT_TX_ID ??
'gh673M0Koh941OIITVXl9hKabRaYWABQUedZxW-swIA';
// The lease time for purchasing the name
const years = 1;
// load local wallet
const wallet = loadWallet();
// get contract manifest
const { evaluationOptions = {} } = await getContractManifest({
contractTxId: arnsContractTxId,
});
// Read the ANT Registry Contract
const contract = await warp
.contract<IOState>(arnsContractTxId)
.setEvaluationOptions(evaluationOptions)
.syncState(`https://api.arns.app/v1/contract/${arnsContractTxId}`, {
validity: true,
});
contract.connect(wallet);
// check if this name exists in the registry, if not exit the script.
const currentState = await contract.readState();
const currentStateString = JSON.stringify(currentState);
const currentStateJSON = JSON.parse(currentStateString);
if (currentStateJSON.records[nameToBuy] !== undefined) {
console.log(
'This name %s is already taken and is not available for purchase. Exiting.',
nameToBuy,
);
return;
}
// Buy the available record in ArNS Registry
console.log(
'Buying the record, %s using the ANT %s',
nameToBuy,
contractTxId,
);
const recordTxId = await contract.writeInteraction(
{
function: 'buyRecord',
name: nameToBuy,
contractTxId,
years,
},
{
disableBundling: true,
},
);
console.log('Finished purchasing the record: %s', recordTxId);
})();