/
0-gold-asa.js
59 lines (49 loc) · 2.03 KB
/
0-gold-asa.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
const { balanceOf, executeTransaction } = require('@algo-builder/algob');
const { mkParam } = require('./common/common');
/*
Create "gold" Algorand Standard Asset (ASA).
Accounts are loaded from config.
To use ASA, accounts have to opt-in. Owner is opt-in by default.
*/
async function run(runtimeEnv, deployer) {
console.log('[gold]: Script has started execution!');
const masterAccount = deployer.accountsByName.get('master-account');
const goldOwner = deployer.accountsByName.get('alice');
const john = deployer.accountsByName.get('john');
const bob = deployer.accountsByName.get('bob');
// Accounts can only be active if they possess minimum amont of ALGOs.
// Here we fund the accounts with 5e6, 5e6 and 1e6 micro AlGOs.
const message = 'funding account';
const promises = [
executeTransaction(
deployer,
mkParam(masterAccount, goldOwner.addr, 5e6, { note: message })
),
executeTransaction(
deployer,
mkParam(masterAccount, john.addr, 5e6, { note: message })
),
executeTransaction(
deployer,
mkParam(masterAccount, bob.addr, 1e6, { note: message })
),
];
await Promise.all(promises);
// Let's deploy ASA. The following commnad will open the `assets/asa.yaml` file and search for
// the `gold` ASA. The transaction can specify standard transaction parameters. If skipped
// node suggested values will be used.
const asaInfo = await deployer.deployASA('gold', {
creator: goldOwner,
});
console.log(asaInfo);
// In asa.yaml we only added `john` to opt-in accounts. Let's add `bob` as well using the
// script;
await deployer.optInAcountToASA('gold', 'bob', {});
// to interact with an asset we need asset ID. We can get it from the returned object:
const assetID = asaInfo.assetIndex;
// we can inspect the balance of the goldOnwer. It should equal to the `total` value defined
// in the asa.yaml.
await balanceOf(deployer, goldOwner.addr, assetID);
console.log('[gold]: Script execution has finished!');
}
module.exports = { default: run };