-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathissue.js
More file actions
executable file
·63 lines (60 loc) · 2.33 KB
/
Copy pathissue.js
File metadata and controls
executable file
·63 lines (60 loc) · 2.33 KB
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
// Synopsis
//
// Issue tokens to address:
//
// $ truffle exec --network thunder-testnet issue.js address amount
//
// OPTIONS:
// (The --network option is from `truffle exec`)
//
// This is a Truffle external script:
// See: https://truffleframework.com/docs/truffle/getting-started/writing-external-scripts
const process = require('process');
const fs = require('fs');
const path = require('path');
const JSON5 = require('json5');
const program = require('commander');
const pprint = require('./pprint');
module.exports = function(done) {
program.usage('[options]')
.option('--network <network>', 'used by truffle only')
.parse(process.argv);
(async () => {
try {
const contractName = program.contract;
const networkId = await web3.eth.net.getId();
const contractDataStr = fs.readFileSync(path.join('contracts-deployed-to-production',
networkId + '-Token.json'),
{ encoding: 'utf8' });
const contractData = JSON5.parse(contractDataStr);
const deployedNetwork = contractData.networks[networkId];
if (!deployedNetwork || !deployedNetwork.address) {
console.log(`No record of contract "${contractName}" being deployed on chain with network_id: ${networkId}`);
process.exit(1);
}
const contractAddress = deployedNetwork.address;
const accounts = await web3.eth.getAccounts();
const fromAccount = accounts[0];
const contract = new web3.eth.Contract(contractData.abi, contractAddress, {
from: fromAccount
});
const address = process.argv[process.argv.length-2];
let amount = process.argv[process.argv.length-1];
const decimal = new web3.utils.BN(await contract.methods.decimals().call())
let t = new web3.utils.BN(amount)
let e = new web3.utils.BN(10)
e = e.pow(decimal)
t = t.mul(e)
console.log(`Issue ${t} to ${address}`)
let receipt = await contract.methods.issue(t.toString(10, 0), address).send();
console.log('receipt:', pretty.format(receipt));
let b = await contract.methods.balanceOf(address).call();
console.log(`balance of ${address}:`, address, b);
done();
} catch(err) {
console.log('Exception:', err);
process.exit(1);
done();
}
})();
}