-
Notifications
You must be signed in to change notification settings - Fork 2
/
agent.js
58 lines (54 loc) · 1.66 KB
/
agent.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
#!/usr/bin/env -S yarn node
const { calculateFee, GasPrice } = require("@cosmjs/stargate");
const utils = require('./utils');
async function main() {
const config = await utils.getChainConfig()
const coinConfig = await utils.getChainCoinConfig(config)
const agentWallet = await utils.getLabelledWallet(config, utils.agentnyms[0])
const agent = await utils.getAgentClient(config, utils.agentnyms[0])
const managerWallet = await utils.getLabelledWallet(config, utils.catnyms[0])
const managerContract = `${managerWallet.contractAddress}`
const gasPrice = GasPrice.fromString(`0.025${coinConfig.gas}`)
const fee = calculateFee(500_000, gasPrice)
const memo = `Agent MEOW!`;
const agentAddress = `${agentWallet.accounts[0].address}`
console.log('agentAddress', agentAddress);
console.log('managerContract', managerContract);
// 1. Register 1 or more agents
// RegisterAgent {}
try {
const r_tx = await agent.execute(
agentAddress,
managerContract,
{ register_agent: { payable_account_id: null } },
fee,
memo,
);
console.log('register tx hash', r_tx.transactionHash, r_tx);
} catch (e) {
console.log('REGISTER AGENT FAILED', e);
return;
}
// 2. Check status via agent info
// GetAgent { account_id: Addr }
try {
const q_tx = await agent.queryContractSmart(
managerContract,
{ get_agent: { account_id: agentAddress } },
);
console.log('get agent', q_tx);
} catch (e) {
console.log('GET AGENT FAILED', e);
return;
}
}
main().then(
() => {
console.info("Officially purr time.");
process.exit(0);
},
(error) => {
console.error(error);
process.exit(1);
},
);