Guest User

Untitled

a guest
Jun 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <script type="text/javascript">
  2. var userAccount;
  3. function startApp() {
  4. var contractAddress = "<contract-address>";
  5. cryptoIpfs = new web3js.eth.contract(abi, contractAddress);
  6.  
  7. var accountInterval = setInterval(function() {
  8.  
  9. if (web3.eth.accounts[0] !== userAccount) {
  10. userAccount = web3.eth.accounts[0];
  11. }
  12. }, 100);}
  13.  
  14. function save_hash(hash) {
  15. return cryptoIpfs.methods.saveHash('hash') ////// error there! (error mentioned at bottom)/////
  16. .send({from: userAccount, value:web3.utils.toWei("0.001")})
  17. .on("receipt", function(receipt) {
  18. $("#txn_hash_2").text(receipt);
  19. })
  20. .on("error", function(error) {
  21. $("#txStatus").text(error);
  22. });
  23. }
  24.  
  25. window.addEventListener('load', function() {
  26. // Checking if Web3 has been injected by the browser (Mist/MetaMask)
  27. if (typeof web3 !== 'undefined') {
  28. // Use Mist/MetaMask's provider
  29. web3js = new Web3(web3.currentProvider);
  30. } else {
  31. // Handle the case where the user doesn't have Metamask installed
  32. }
  33. startApp()
  34. })
  35. </script>
  36.  
  37.  
  38. ////########## error in console######/////
  39. ipfsLink:172 Uncaught TypeError: Cannot read property 'saveHash' of undefined at save_hash (ipfsLink:172)
  40. at <anonymous>:1:1 save_hash @ ipfsLink:172
  41.  
  42. pragma solidity ^0.4.23;
  43.  
  44. contract IpfsLink{
  45. address owner;
  46. uint public lastHashId;
  47. uint hashCost = 0.001 ether;
  48.  
  49. struct IpfsHash{
  50. address sender;
  51. string hashString;
  52. uint timestamp;
  53. }
  54.  
  55. mapping (uint => IpfsHash) hashes;
  56.  
  57. modifier onlyOwner {
  58. require(msg.sender == owner);
  59. _;
  60. }
  61.  
  62. constructor() public{
  63. owner = msg.sender;
  64. lastHashId = 0;
  65. }
  66.  
  67. function saveHash(string _hashContent) external payable {
  68. require(msg.value >= hashCost);
  69.  
  70. uint hashId = ++lastHashId;
  71. hashes[hashId].sender = msg.sender;
  72. hashes[hashId].hashString = _hashContent;
  73. hashes[hashId].timestamp = now;
  74. }
  75. }
Add Comment
Please, Sign In to add comment