问题描述
我已经部署了我的智能合约,我的交易也在元掩码中完成,但是当我尝试通过调用智能合约的函数来显示我的结果时,我已经检查了数据类型,但我收到了这样的错误
Error: Returned values aren't valid,did it run Out of Gas?
at i.decodeParameters (web3.min.js:10290)
at o._decodeMethodReturn (web3.min.js:12156)
at _.outputFormatter (web3.min.js:12196)
at _.formatOutput (web3.min.js:7396)
at u (web3.min.js:7437)
at web3.min.js:8026
at s._handle (inpage.js:17) undefined
我不知道为什么它没有在 web3.min.js 中解码信息,而我的 js 代码是
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));
}
// Set Contract Abi
var contractAbi = [{
"anonymous": false,"inputs": [{
"indexed": true,"internalType": "address","name": "account","type": "address"
}],"name": "distributorAdded","type": "event"
},{
"anonymous": false,"name": "distributorRemoved","inputs": [{
"indexed": false,"internalType": "string","name": "_batchno","type": "string"
}],"name": "Made","name": "ManufacturerAdded","name": "ManufacturerRemoved","name": "Packed","name": "Sold","name": "UserAdded","name": "UserRemoved",{
"constant": false,"inputs": [{
"internalType": "address","name": "adddistributor","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
},"name": "addManufacturer","name": "addUser",{
"constant": true,"inputs": [{
"internalType": "string","name": "fetchMedicineBufferOne","outputs": [{
"internalType": "string","name": "batchno","type": "string"
},{
"internalType": "string","name": "medicineName",{
"internalType": "address","name": "ownerID","type": "address"
},"name": "originManufacturerID","name": "dosage",{
"internalType": "enum main.State","name": "medicinestate","type": "uint8"
}],"stateMutability": "view","name": "fetchMedicineBufferTwo","name": "FactoryName","name": "mfgdate","name": "expdate","name": "distributorID","name": "userID","name": "isdistributor","outputs": [{
"internalType": "bool","name": "","type": "bool"
}],"name": "isManufacturer","name": "isUser","name": "_medicineName","name": "_dosage","name": "_originManufacturerID","name": "_ownerID","name": "_FactoryName","name": "_mfgdate","name": "_expdate","type": "uint8"
},"name": "_distributorID","name": "_userID","name": "makeMedicine","name": "packMedicine","name": "receiveMedicine","inputs": [],"name": "renouncedistributor","name": "renounceManufacturer","name": "renounceUser","type": "function"
}]; // Add Your Contract ABI here!!!
// Set Contract Address
var contractAddress = '0xd9145CCE52D386f254917e481eB44e9943F39138'; // Add Your Contract address here!!!
// Set the Contract
var contract = new web3.eth.Contract(contractAbi,contractAddress);
$('form').on('submit',function(event) {
event.preventDefault();
batchno = $("#batchno").val();
console.log(batchno)
//display the Medicine
contract.methods.fetchMedicineBufferOne(batchno).call(function(err,result) {
console.log(err,result)
$('#ftc-medicine').html(result);
});
});
我的智能合约功能是
function fetchMedicineBufferOne(string memory _batchno) public view returns
(
string memory batchno,//the primary key batchno
string memory medicineName,//Medicine name
address ownerID,address originManufacturerID,string memory dosage,State medicinestate
)
}
return
(
medicines[_batchno].batchno,medicines[_batchno].medicineName,medicines[_batchno].ownerID,medicines[_batchno].originManufacturerID,medicines[_batchno].dosage,medicines[_batchno].medicinestate
);
}
创建了药物数组并将值存储在此函数中
function makeMedicine(string memory _batchno,string memory _medicineName,string memory _dosage,address _originManufacturerID,address _ownerID,string memory _FactoryName,string memory _mfgdate,string memory _expdate,State,address _distributorID,address _userID) public
onlyManufacturer
{
// Add the new medicine as part of medicines
Medicine memory makeMedicine = Medicine({
batchno:_batchno,medicineName:_medicineName,dosage:_dosage,originManufacturerID:_originManufacturerID,// Metamask-Ethereum address of the Manufacturer
ownerID:_ownerID,// Metamask-Ethereum address of the current owner as the medicine moves through 3 stages
FactoryName:_FactoryName,// Manufacturer Name
mfgdate:_mfgdate,//mfgdate
expdate:_expdate,//expdate
medicinestate: State.Made,distributorID: _distributorID,userID: _userID
});
medicines[_batchno] = makeMedicine;
medicines[_batchno].medicinestate = State.Made;
我在 ganache 中编译和部署了我的合约,我也在 remix 中进行了部署,其中函数运行正常 我在哪里出错?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)