-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.js
123 lines (85 loc) · 2.87 KB
/
launch.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const ethers = require("ethers")
// const solc = require("solc")
const fs = require("fs-extra")
require("dotenv").config();
async function main() {
// First, compile this!
// And make sure to have your ganache network up!
let provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL)
let wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
// const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf8");
// let wallet = new ethers.Wallet.fromEncryptedJsonSync(
// encryptedJson,
// process.env.PRIVATE_KEY_PASSWORD
// );
// wallet = wallet.connect(provider);
const abi = fs.readFileSync("./workregistry_sol_Work_Attendance.abi", "utf8")
const binary = fs.readFileSync(
"./workregistry_sol_Work_Attendance.bin",
"utf8"
)
const contractFactory = new ethers.ContractFactory(abi, binary, wallet)
const owner = wallet.address;
console.log("Deploying, please wait...")
const contract = await contractFactory.deploy();
// const contract = await contractFactory.deploy({ gasPrice: 100000000000 });
// const deploymentReceipt = await contract.deployTransaction.wait(1)
// console.log(deploymentReceipt);
console.log(`Contract deployed by owner: ${owner}`);
console.log(`Contract deployed to ${contract.address}`)
//MY CODE
// let balance = await contract.getBalance();
// console.log(balance);
const users = [
{
user: 'John',
job: 'Architect',
salary: 1229393
},
{
user: 'Kante',
job: 'Footballer',
salary: 122039393
},
{
user: 'Idowu',
job: 'Graphics',
salary: 122229393
}
]
let createWorker = await contract.createWorker('Ayo', 'Blockchain Developer', 130000 );
createWorker.wait();
let worker = await contract.getWorker('Ayo');
console.log('Registration successful.....');
console.log('Displaying Details.....');
console.log(worker.name);
const id = worker.id
// console.log(id);
// console.log(worker.occupation);
const salary = worker.salary
// console.log(salary);
let occupation = await contract.getWorkerByID('Ayo');
console.log(`Ayo is a ${occupation} and he earns ${salary}. His ID is: ${id}`);
//END OF MY CODE
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
// synchronous [solidity]
// asynchronous [javascript]
// cooking
// Synchronous
// 1. Put popcorn in microwave -> Promise
// 2. Wait for popcorn to finish
// 3. Pour drinks for everyone
// Asynchronous
// 1. Put popcorn in the mircrowave
// 2. Pour drinks for everyone
// 3. Wait for popcorn to finish
// Promise
// Pending
// Fulfilled
// Rejected