-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
109 lines (104 loc) · 3.14 KB
/
index.js
File metadata and controls
109 lines (104 loc) · 3.14 KB
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
// Connect to the Ethereum network using Web3.js library
const web3 = new web3(web3.givenProvider || "http://localhost:8545");
// Load the contract ABI (Application Binary Interface)
const abi = [
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
},
{
"internalType": "string[]",
"name": "_courses",
"type": "string[]"
},
{
"internalType": "uint256[]",
"name": "_grades",
"type": "uint256[]"
},
{
"internalType": "string",
"name": "_issuedBy",
"type": "string"
},
{
"internalType": "uint256",
"name": "_issuedOn",
"type": "uint256"
}
],
"name": "addTranscript",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_id",
"type": "uint256"
}
],
"name": "getTranscript",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "string[]",
"name": "",
"type": "string[]"
},
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
},
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
];
// Load the contract address
const contractAddress = '0xd9145CCE52D386f254917e481eB44e9943F39138';
// Create a new instance of the contract using the loaded ABI and address
const contract = new web3.eth.Contract(abi, contractAddress);
// Add a new transcript to the contract
contract.methods.addTranscript("Vashishth Gajjar", ["PDC", "DBMS", "DSA"], [90, 85, 95], "VIT University", Date.now())
.send({ from: '0x0d2786065d8CA8Ac69b6B10EC83FD7bd5bf7ecee' }) // Replace with your account address
.then(() => console.log("Transcript added successfully!"))
.catch((error) => console.error(error));
// Get a transcript from the contract
contract.methods.getTranscript(0)
.call({ from: '0x0d2786065d8CA8Ac69b6B10EC83FD7bd5bf7ecee' }) // Replace with your account address
.then((result) => console.log(result))
.catch((error) => console.error(error));