I am facing a problem when I am creating a contract on my local ethereum blockchain. I have a basic contract to register a doc on blockchain.
So, when a run my contract in truffle console I can call all my functions perfectly, but, when I create a webpage with a front end interface, I can't open metamask to pay a fee.
My contract has basicly 2 functions: addDoc and FindDoc. I did a test creating a transaction using remix website and it worked normal. At my page, I still can call a findDoc and get answer with the correct informations, but when I try creating a transaction and pay a fee, the metamask doesn't show me.
My project is just 4 files:
- index.html
- app.js
- notaryWebApp.js
- sha256
The codes can be found here: https://github.com/ffelipesimoes/solidity/tree/master/webapp
The main interact with blockchain is notaryWebApp.js file:
var contract = undefined; var customProvider = undefined; var address = "0x6A4494ed32ce0Ab8004fbEAdac534916f88C8d3E"; var abi = undefined; function notary_init() { // Check if Web3 has been injected by the browser (Mist/MetaMask) if (typeof web3 !== 'undefined') { // Use existing gateway window.web3 = new Web3(web3.currentProvider); } else { alert("No Ethereum interface injected into browser. Read-only access"); } //contract abi abi = [...] contract = new web3.eth.Contract(abi, address); }; //sends a hash to the blockchain function notary_send(hash, callback) { web3.eth.getAccounts(function (error, accounts) { contract.methods.addDocHash(hash).send({ from: accounts[0] }, function (error, tx) { if (error) callback(error, null); else callback(null, tx); }); }); }; //looks up a hash on the blockchain function notary_find(hash, callback) { contract.methods.findDocHash(hash).call(function (error, result) { if (error) callback(error, null); else { let resultObj = { mineTime: new Date(result[0] * 1000), blockNumber: result[1] } callback(null, resultObj); } }); }; since now, thank you all!