-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupContracts.js
179 lines (146 loc) · 7.56 KB
/
setupContracts.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
let Web3 = require('web3');
const fs = require('fs');
const { exit } = require('process');
const keys = fs.readFileSync(".keys").toString().trim().replace('\r', '').replace('\r', '').split('\n');
console.log(`Found ${keys.length} Keys`)
let web3;
let networkId;
var args = process.argv;
console.log(`Running ${args[2]} version.`)
if (args[2] == 'prod'){
web3 = new Web3(new Web3.providers.HttpProvider('https://rpc-mumbai.matic.today'));
networkId = 80001;
}
else {
web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));
networkId = 1001;
}
keys.forEach((key)=>{
web3.eth.accounts.wallet.add(key);
})
function getContractInstance(name = '', network = networkId){
let build = require(`./build/contracts/${name}.json`);
let address = build.networks[network].address;
let abi = build.abi;
return new web3.eth.Contract(abi, address, {gas: 8000000});
}
let ANC = getContractInstance('ANC');
let Faucet = getContractInstance('Faucet');
let Libertas = getContractInstance('Libertas');
let LibertasArticles = getContractInstance('LibertasArticles');
(async () => {
/* */
await ANC.methods.enableTransfer().send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Enable Token Transfer 1: ${receipt.transactionHash}`)
})
await ANC.methods.mint(web3.eth.accounts.wallet[0].address, web3.utils.toWei('150', 'ether')).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Mint ANC to Account 1: ${receipt.transactionHash}`)
})
await ANC.methods.mint(web3.eth.accounts.wallet[0].address, web3.utils.toWei('150', 'ether')).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Mint More ANC to Account 1: ${receipt.transactionHash}`)
})
await ANC.methods.mint(web3.eth.accounts.wallet[1].address, web3.utils.toWei('100', 'ether')).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Mint ANC to Account 2: ${receipt.transactionHash}`)
})
await ANC.methods.mint(web3.eth.accounts.wallet[2].address, web3.utils.toWei('100', 'ether')).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Mint ANC to Account 3: ${receipt.transactionHash}`)
})
await ANC.methods.mint(Faucet._address, web3.utils.toWei('100')).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Mint ANC to Faucet: ${receipt.transactionHash}`)
})
await ANC.methods.balanceOf(web3.eth.accounts.wallet[0].address).call()
.then(function(data){
console.log(`🤑 Balance of Account 1: ${web3.utils.fromWei(data)} ANC`)
})
await ANC.methods.balanceOf(web3.eth.accounts.wallet[1].address).call()
.then(function(data){
console.log(`🤑 Balance of Account 2: ${web3.utils.fromWei(data)} ANC`)
})
await ANC.methods.balanceOf(web3.eth.accounts.wallet[2].address).call()
.then(function(data){
console.log(`🤑 Balance of Account 3: ${web3.utils.fromWei(data)} ANC`)
})
await ANC.methods.balanceOf(Faucet._address).call()
.then(function(data){
console.log(`🤑 Balance of Faucet: ${web3.utils.fromWei(data)} ANC`)
})
await ANC.methods.approve(Libertas._address, web3.utils.toWei('300', 'ether')).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Approve Libertas to Spend ANC from Acct 1: ${receipt.transactionHash}`)
})
await Libertas.methods.createAdvertiser('Adv1').send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Create Advertiser from Acct 1: ${receipt.transactionHash}`)
})
await Libertas.methods.createAd(
"QmaH98sj1UVsjuKnnvFNmg2VG4LuYBT6XrCWhR25CBRw3Q","lego.com","2",web3.utils.toWei('1', 'ether'),web3.utils.toWei('100', 'ether')
).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Create Ad 1 from Acct 1: ${receipt.transactionHash}`)
})
await Libertas.methods.createAd(
"QmYufx8TtYYMtSDJE1czxPndTTcwQf9KBbPUTjnjRDJJPW","store.google.com","1",web3.utils.toWei('5', 'ether'),web3.utils.toWei('100', 'ether')
).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Create Ad 2 from Acct 1: ${receipt.transactionHash}`)
})
await Libertas.methods.createVideo(
"QmUY5PdTpDmSgwre8C4cdFUSTApVweXRPzdG7ErTgdFc8A","QmaQKArfLrdQFdbCpzbtxJiqFVs6mviVdHznJGh5iAu9WK","I Built The World's Largest Lego Tower","World's Largest Lego Tower","100","2"
).send({from: web3.eth.accounts.wallet[1].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Create Video 1 from Acct 2: ${receipt.transactionHash}`)
})
await Libertas.methods.createVideo(
"QmPU7pns9LQdQfqfiXVzxgiokwPSM4X46PycHHBk84GqVc","QmSBsiRTdJu34cREmwU3DT6okhjX69VMMdYz5sJCwGEHGh","The danger of AI is weirder than you think","TED talk by Janelle Shane","100","1"
).send({from: web3.eth.accounts.wallet[2].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Create Video 2 from Acct 3: ${receipt.transactionHash}`)
})
await Libertas.methods.sponsorVideo(
"1","1"
).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Sponsor Video 1 from Acct 1: ${receipt.transactionHash}`)
})
await Libertas.methods.sponsorVideo(
"2","2"
).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Sponsor Video 2 from Acct 1: ${receipt.transactionHash}`)
})
await Libertas.methods.selectSponsor(
"1","1"
).send({from: web3.eth.accounts.wallet[1].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Select Sponsor for Video 1 from Acct 2: ${receipt.transactionHash}`)
})
await Libertas.methods.selectSponsor(
"2","2"
).send({from: web3.eth.accounts.wallet[2].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Select Sponsor for Video 2 from Acct 3: ${receipt.transactionHash}`)
})
await LibertasArticles.methods.createArticle(
true, "Libertas - Introduction" ,"QmV69b2my5J1AFxqgRbevLc8gswjUmZcqC9CjcgnoKNspm", false, "0", "1"
).send({from: web3.eth.accounts.wallet[0].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Create a new Article: ${receipt.transactionHash}`)
})
await LibertasArticles.methods.createArticleAnonymous(
"Libertas - Introduction" ,"QmV69b2my5J1AFxqgRbevLc8gswjUmZcqC9CjcgnoKNspm","1"
).send({from: web3.eth.accounts.wallet[1].address})
.once('confirmation', function(confirmationNumber, receipt){
console.log(`✅ Create a new Anonymous Article: ${receipt.transactionHash}`)
})
await sleep(10000)
exit(0)
})()
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}