-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_query_token.js
46 lines (36 loc) · 1.37 KB
/
2_query_token.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
const fs = require("fs");
const path = require("path");
const dotenv = require('dotenv');
dotenv.config({path: '.env'});
const hre = require("hardhat");
const DEPLOYER_ADDRESS = process.env.DEPLOYER_ADDRESS;
const USER_ADDRESS = process.env.USER_ADDRESS;
async function fetchTokenAddress() {
try {
var data = fs.readFileSync(path.resolve(__dirname, "../deployedContracts.json"));
} catch (err) {
console.log(err);
}
var deployedContracts = JSON.parse(data);
return deployedContracts.TokenAddress;
}
async function main() {
// ATTACH THE CONTRACT ABI TO THE CONTRACT ADDRESS
const token = await hre.ethers.getContractAt("Token", fetchTokenAddress());
// QEURY THE NAME, SYMBOL AND TOTAL-SUPPPLY OF THE TOKEN
console.log("Name of the Token is:", await token.name());
console.log("Symbol of the Token is:",await token.symbol());
console.log("Total Supply of the Token is:", await token.totalSupply());
// QUERY THE DEPLOYER-TOKEN-BALANCE
console.log("Deployer token balance is:", await token.balanceOf(DEPLOYER_ADDRESS));
// TRANSFER SOME TOKENS FROM DEPLOYER TO THE USER
await token.transfer(USER_ADDRESS, 1000);
// QUERY THE USER-TOKEN-BALANCE
console.log("User token balance is:", await token.balanceOf(USER_ADDRESS));
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});