1

I'm writing a snippet of code that should call an API and record the response to the chain:

function(APIResponse) {
    // Write to chain
    console.log(`API responded with:\n${APIResponse}`);
    let callResult = instance.writeResponse.call(APIResponse);
    console.log(`Writing api response to chain result: ${callResult}`);
    const ID = instance.writeResponse.sendTransaction(APIResponse);
    console.log(`Transaction ID: ${ID}`)
}

In an attempt to use the proper pattern, I first call to check the function and later send the transaction. The call passes and returns a boolean value, but the sendTransaction fails with the following:

requestmanager.js:61 Uncaught Error: VM Exception while processing transaction: out of gas(…)

Referencing a similar issue I attempted to add gas to the function calls:

function(APIResponse) {
    // Write to chain
    console.log(`API responded with:\n${APIResponse}`);
    let callResult = instance.writeResponse.call({gas: helper.averageGasBump}, APIResponse);
    console.log(`Writing api response to chain result: ${callResult}`);
    const ID = instance.writeResponse.sendTransaction({gas: helper.averageGasBump}, APIResponse);
    console.log(`Transaction ID: ${ID}`)
}

This time, no Error is thrown, the transaction gets recorded but when I try to access the varable that should have been stored in the chain as a JSON string, an empty string is being returned.

Interestingly enough, inside truffle console I can invoke all functions without the need for an additional gas bump and they get recorded properly.

I'm using testrpc.

Could you explain to me what is going on?

1 Answer 1

1

After some tinkering, I found out where the problem was - I was missusing the API.

The propper call with the gas bump should have been:

instance.writeResponse.call(APIResponse, {gas: helper.averageGasBump});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.