-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminter.js
56 lines (47 loc) · 2 KB
/
minter.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
// This file is for minting 10 tokens, using `./zokrates/code/generated/*`
const fs = require("fs");
const Web3 = require("web3");
const HDWallet = require("@truffle/hdwallet-provider");
const SolnSquareVerifier = require("./build/contracts/SolnSquareVerifier.json");
const infuraKey = fs.readFileSync(".secret.infuraKey"); // '1cbe12...';
const mnemonic =
"tilt lunar exile blame merry good little undo evidence useful rotate error"; // the public/testing one // readFileSync(".secret.mnemonic").toString().trim();
const url = `https://rinkeby.infura.io/v3/${infuraKey}`;
const networkId = 4;
const provider = new HDWallet(mnemonic, url);
const web3 = new Web3(provider);
const solnSquareVerifierContract = new web3.eth.Contract(
SolnSquareVerifier.abi,
SolnSquareVerifier.networks[networkId].address
);
web3.eth.getAccounts(async (_err, [account1, account2]) => {
const totalSupplyBefore = await solnSquareVerifierContract.methods
.totalSupply()
.call();
console.log(`totalSupply before: ${totalSupplyBefore}`);
let countMintedTokens = 0;
for (let i = 0; i < 10; i++) {
const tokenOwner = i % 2 === 0 ? account1 : account2;
const tokenId = i + 1;
const solutionJson = require(`./zokrates/code/generated/proof${tokenId}.json`);
const { proof, inputs } = solutionJson;
try {
await solnSquareVerifierContract.methods
.addSolution(tokenOwner, proof.a, proof.b, proof.c, inputs)
.send({ from: account1 });
await solnSquareVerifierContract.methods
.mintOwnershipProvedToken(tokenOwner, tokenId, inputs)
.send({ from: account1 });
countMintedTokens++;
console.log("Minted tokenId", tokenId, "to", tokenOwner);
} catch (e) {
console.log(`ERROR for tokenId ${i}: ${e?.message}`);
}
}
console.log(`Successfully minted ${countMintedTokens} tokens`);
const totalSupplyAfter = await solnSquareVerifierContract.methods
.totalSupply()
.call();
console.log(`totalSupply after: ${totalSupplyAfter}`);
process.exit(0);
});