Last active
February 20, 2018 10:19
-
-
Save nakov/5c43e0db3e56b3842d216b7bb7409660 to your computer and use it in GitHub Desktop.
Document Registry - Infura API (accessed through Web3.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
contract Cert { | |
mapping (string => bool) private certificateHashes; | |
address contractOwner = msg.sender; | |
function add(string hash) public { | |
require (msg.sender == contractOwner); | |
certificateHashes[hash] = true; | |
} | |
function verify(string hash) view public returns (bool) { | |
return certificateHashes[hash]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://ropsten.etherscan.io/address/0x184b1f4bccc68377ea2811e1e6268ded10b4d199 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Web3 = require("web3"); | |
let web3 = new Web3("https://ropsten.infura.io/z0NBZ7w5VCWFt9qjFUVk"); | |
//web3.eth.getBalance('0x5981768670925f461211b54212ed8bb95e9a3ba2').then(console.log) | |
const contractAddress = '0x184b1f4bccc68377ea2811e1e6268ded10b4d199'; | |
const contractABI = [ | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "hash", | |
"type": "string" | |
} | |
], | |
"name": "verify", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "hash", | |
"type": "string" | |
} | |
], | |
"name": "add", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
} | |
] | |
let contract = new web3.eth.Contract(contractABI, contractAddress); | |
contract.methods.verify("abc").call().then(retval => { | |
console.log("Document `abc` is valid? " + retval); | |
}); | |
contract.methods.verify("pesho").call().then(retval => { | |
console.log("Document `pesho` is valid? " + retval); | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment