I have a contract as follows -
contract getSchwifty {
string internal constant seeWhatYouGot = "I want to see what you got!";
string internal contestResult;
mapping(uint=>string) Record;
// Contract constructor that takes a string param
function getSchwifty(string _contestResult) public {
contestResult = _contestResult;
}
function addRecord(uint id, string hashData) public {
Record[id] = hashData;
}
function getRecord(uint id) public returns (string) {
return Record[id];
}
function showMeWhatYouGot() external pure returns (string) {
return seeWhatYouGot;
}
function enterContest(string _contestEntry) external view returns (string) {
// completely disregard the _contestEntry ;)
return contestResult;
}
}
I deploy this contract using a web3 client and then try to call the addRecord and getRecord functions. When I do this using method.send(), I see no error:
simpleContract.methods.getRecord(123).send({from: '0xAA74487ec1cA68932baC64dF05d27a9CA6f8e156'}).then(console.log,console.log)
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> { blockHash: '0xeb3d7f287dd6da1dc824c2c433185db12e6292f4592894cdd6c82d6678c787f3',
blockNumber: 12065,
contractAddress: null,
cumulativeGasUsed: 21464,
from: '0xaa74487ec1ca68932bac64df05d27a9ca6f8e156',
gasUsed: 21464,
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
root: '0x696db44230e2701d1840643dee2543f58cb7ed042d75edba0c1e3ce739e76932',
to: '0x6ee9957aef5f4073c6af71441ec7962527c37674',
transactionHash: '0x46c4cb28ce7b0c99d91c6744ad12f29585ae215f048378270e8dcb252b093c03',
transactionIndex: 0,
events: {} }
However, I want to view the actual result of getRecord and hence tried the getRecord function using method.call(). Now I see an error.
simpleContract.methods.getRecord(123).call({from: '0xAA74487ec1cA68932baC64dF05d27a9CA6f8e156',gas: 0x66A84}).then(console.log,console.log)
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> Error: Returned values aren't valid, did it run Out of Gas?
at ABICoder.decodeParameters (/node_modules/web3-eth-abi/src/index.js:226:15)
at Contract._decodeMethodReturn (/node_modules/web3-eth-contract/src/index.js:465:22)
at Method.outputFormatter (/node_modules/web3-eth-contract/src/index.js:818:46)
at Method.formatOutput (/node_modules/web3-core-method/src/index.js:163:54)
at sendTxCallback (/node_modules/web3-core-method/src/index.js:473:33)
at /node_modules/web3-core-requestmanager/src/index.js:147:9
at XMLHttpRequest.request.onreadystatechange (/node_modules/web3-providers-http/src/index.js:91:13)
at XMLHttpRequestEventTarget.dispatchEvent (/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Not sure, what this error means. I am good with the gas limit: gasLimit: 67790268489,
A few questions -
- any comments on the solidity code? anything that doesnt sound right? I tried changing the getRecord function to public constant, but did not help.
If method.send() works, does this mean that everything is good with the solidity code? For me, deploy, send both work. In addition, the compile and loading of the contract on the geth node also worked.
lastly, what does this error mean? I tried searching on forums, but couldnt find anything useful.
Thanks in advance. techie champ