-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract.js
168 lines (133 loc) · 4.05 KB
/
contract.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
/**
* Containes all the functions related to web3 integration
* deploying and interacting with smart contract
*/
const Web3 = require("web3");
require("dotenv").config();
const IBLOCK_WSURL="https://goerli.infura.io/v3/8b9d3fdeaccc4be4aeea708c77476676" // url where the iblock platform is running
const web3 = new Web3(
new Web3.providers.HttpProvider(IBLOCK_WSURL)
);
const contract = require("./bin/Verifier.json");
const userContract = require("./bin/User.json");
deployContract = async () => {
let verifierContract = await new web3.eth.Contract(contract.abi);
const fundingAccount = await web3.eth.accounts.privateKeyToAccount(
process.env.FUNDING_ACCOUNT
);
const account = await web3.eth.accounts.create();
const initialTxSign = await web3.eth.accounts.signTransaction(
{
to: account.address,
value: "500000000000000000", // equivalent to 0.5 ether
gas: 2000000,
},
process.env.FUNDING_ACCOUNT
);
const initialRecipt = await web3.eth.sendSignedTransaction(
initialTxSign.rawTransaction
);
const transaction = await verifierContract.deploy({
data: contract.bytecode,
});
const options = {
data: transaction.encodeABI(),
gas: 3000000,
};
const signed = await web3.eth.accounts.signTransaction(
options,
account.privateKey
);
const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
return {
"private-key": account.privateKey,
"verifier-address": account.address,
"contract-address": receipt.contractAddress,
};
};
getVerifiedToken = async (
_token,
_verifierAccountAddress,
_verifierSmartContractAddress
) => {
let contractInstance = new web3.eth.Contract(
contract.abi,
_verifierSmartContractAddress
);
let userSmartContractAddress = await contractInstance.methods
.getVerifiedUserAddress(_token)
.call({ from: _verifierAccountAddress });
if (userSmartContractAddress === "0x0000000000000000000000000000000000000000")
return "PENDING";
return userSmartContractAddress;
};
getUserName = async (_userSmartContractAddress, _verifierAccountAddress) => {
let contractInstance = new web3.eth.Contract(
userContract.abi,
_userSmartContractAddress
);
let userName = await contractInstance.methods
.getName()
.call({ from: _verifierAccountAddress });
return userName;
};
getUserEmail = async (_userSmartContractAddress, _verifierAccountAddress) => {
let contractInstance = new web3.eth.Contract(
userContract.abi,
_userSmartContractAddress
);
let userEmail = await contractInstance.methods
.getEmail()
.call({ from: _verifierAccountAddress });
return userEmail;
};
getUserDOB = async (_userSmartContractAddress, _verifierAccountAddress) => {
let contractInstance = new web3.eth.Contract(
userContract.abi,
_userSmartContractAddress
);
let userDOB = await contractInstance.methods
.getDOB()
.call({ from: _verifierAccountAddress });
return userDOB;
};
getUserCountry = async (_userSmartContractAddress, _verifierAccountAddress) => {
let contractInstance = new web3.eth.Contract(
userContract.abi,
_userSmartContractAddress
);
let userCountry = await contractInstance.methods
.getCountry()
.call({ from: _verifierAccountAddress });
return userCountry;
};
getUserMobile = async (_userSmartContractAddress, _verifierAccountAddress) => {
let contractInstance = new web3.eth.Contract(
userContract.abi,
_userSmartContractAddress
);
let userMobile = await contractInstance.methods
.getMobile()
.call({ from: _verifierAccountAddress });
return userMobile;
};
getUserGender = async (_userSmartContractAddress, _verifierAccountAddress) => {
let contractInstance = new web3.eth.Contract(
userContract.abi,
_userSmartContractAddress
);
let userGender = await contractInstance.methods
.getGender()
.call({ from: _verifierAccountAddress });
return userGender;
};
module.exports = {
deployContract,
getVerifiedToken,
getUserName,
getUserEmail,
getUserDOB,
getUserCountry,
getUserMobile,
getUserGender,
};