Skip to content

Instantly share code, notes, and snippets.

@nakov
Last active February 20, 2018 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakov/5c43e0db3e56b3842d216b7bb7409660 to your computer and use it in GitHub Desktop.
Save nakov/5c43e0db3e56b3842d216b7bb7409660 to your computer and use it in GitHub Desktop.
Document Registry - Infura API (accessed through Web3.js)
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];
}
}
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