-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
52 lines (49 loc) · 1.29 KB
/
web.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
const Web3 = require('web3')
async function main() {
var web3 = new Web3("http://localhost:8545")
let accounts = await web3.eth.getAccounts()
console.log("account: ", accounts[0])
let json = [
{
"constant": false,
"inputs": [
{
"name": "_fname",
"type": "string"
},
{
"name": "_age",
"type": "uint256"
}
],
"name": "setFname",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getFname",
"outputs": [
{
"name": "",
"type": "string"
},
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
var myContract = new web3.eth.Contract(json, accounts[0])
myContract.methods.getFname().call().then(function (res) {
console.log(res)
})
}
main()