0

I am trying to call the smart contract for data using this code and every time I am getting this error. I am using a Private Ethereum Network with MetaMask. The calling function is given below.

function certify_find (hash, callback) {
  contract.methods.findDocHash(hash).call( function (error, result) {
  if (error) {
    console.log(error);
    callback(error, null);
  }else {
    let resultObj = {
      mineTime:  new Date(result[0] * 1000),
      blockNumber: result[1],
      instituteName: result[2],
      recipientName: result[3],
      courseName: result[4],
      marks: result[5],
      dateOfCompletion: result[6]
   }
   callback(null, resultObj);
  }
 }); 
};

The ABI is given below

[
{
    "inputs": [
        {
            "internalType": "bytes32",
            "name": "hash",
            "type": "bytes32"
        },
        {
            "internalType": "string",
            "name": "insti",
            "type": "string"
        },
        {
            "internalType": "string",
            "name": "reci",
            "type": "string"
        },
        {
            "internalType": "string",
            "name": "course",
            "type": "string"
        },
        {
            "internalType": "string",
            "name": "grade",
            "type": "string"
        },
        {
            "internalType": "string",
            "name": "doc",
            "type": "string"
        }
    ],
    "name": "addDocHash",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
},
{
    "inputs": [],
    "stateMutability": "nonpayable",
    "type": "constructor"
},
{
    "inputs": [
        {
            "internalType": "bytes32",
            "name": "hash",
            "type": "bytes32"
        }
    ],
    "name": "findDocHash",
    "outputs": [
        {
            "internalType": "uint256",
            "name": "",
            "type": "uint256"
        },
        {
            "internalType": "uint256",
            "name": "",
            "type": "uint256"
        },
        {
            "internalType": "string",
            "name": "",
            "type": "string"
        },
        {
            "internalType": "string",
            "name": "",
            "type": "string"
        },
        {
            "internalType": "string",
            "name": "",
            "type": "string"
        },
        {
            "internalType": "string",
            "name": "",
            "type": "string"
        },
        {
            "internalType": "string",
            "name": "",
            "type": "string"
        }
    ],
    "stateMutability": "view",
    "type": "function"
}
]

This is the smart contract

pragma solidity >= 0.5.0 < 0.7.0;

contract Certify {

struct Record {
    uint mineTime;
    uint blockNumber;
    string instituteName;
    string recipientName;
    string courseName;
    string marks;
    string dateOfCompletion;
}

mapping (bytes32 => Record) private docHashes;

constructor() public {

}

// function that is used to store records on the blockchain
function addDocHash(bytes32 hash, string memory insti, string memory reci, string memory course, string memory grade, string memory doc ) public {
    Record memory newRecord = Record(now, block.number,insti,reci,course,grade,doc);
    docHashes[hash] = newRecord;
}

// verify weather a hash exists on the blockchain and retrieve the corresponding record
function findDocHash(bytes32 hash) public view returns(uint, uint, string memory, string memory, string memory, string memory, string memory) {
    return (docHashes[hash].mineTime, docHashes[hash].blockNumber, docHashes[hash].instituteName, 
                docHashes[hash].recipientName, docHashes[hash].courseName, docHashes[hash].marks, docHashes[hash].dateOfCompletion);
}
}
  • You should by the least indicate exactly which line in your code throws this error! – goodvibration Jun 20 at 17:18
  • contract.methods.findDocHash(hash).call( function (error, result) outputs error = "Error: Couldn't decode uint256 from ABI: 0x and result = null – sampatghosh Jun 21 at 10:18
  • What is the value of hash? – goodvibration Jun 21 at 10:30
  • 0xf236f925722dd04d30ccb29fa44711028f8f6ede2731d1575dc2fc8e7aadbcf8 – sampatghosh Jun 21 at 11:12
  • What is the value of typeof hash? – goodvibration Jun 21 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.