Created
February 16, 2018 12:32
-
-
Save nakov/bea8c2161d282401d82331d876d09100 to your computer and use it in GitHub Desktop.
Document Registry - Infura API
This file contains hidden or 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 hidden or 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 hidden or 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