0

I am using truffle-contract for connecting between frontend and smart contract. Currently, I can call method on smart contract and can consume ether successfully.

const result = await instance.adoptCreeptomas(
aquaQuantity,
firaQuantity,
aetherQuantity,
gaiaQuantity,
referrer,
{ from: accountAddress, value: ether(sendingEther) }

);

But before that, I want to test method first. So I move to this method:

 const data = await instance.adoptCreeptomas.call(
    aquaQuantity,
    firaQuantity,
    aetherQuantity,
    gaiaQuantity,
    referrer,
    { from: accountAddress, value: ether(sendingEther) }
  );

But when calling this, I meet following exception:

errors.js:38 Uncaught (in promise) Error: Invalid JSON RPC response: {"id":6,"jsonrpc":"2.0","error":{"code":-32603}}

I am using ganache for local blockchain and metamask for provider. Please help me figure out why.

Thanks

1

Please check out the difference between transaction and call.

The syntax .call() in truffle-contract is explicitly for making a call, while the syntax of direct call with the method name:

We called the abstraction's sendCoin function directly. This will result in a transaction by default (i.e, writing data) instead of call.

I can tell from your method signature that adoptCreeptomas does persist some change to the network. So just get rid of .call and see what happens.

  • yes. adoptCreeptomas persists some data to the blockchain (and also consume ether). That why I think we should "test" method first. I based on this: ethereum.stackexchange.com/questions/765/… (Recommendation to Call first, then sendTransaction) – hqt May 22 '18 at 4:55
  • So that means truffle-contract doesn't support this way ? – hqt May 22 '18 at 4:55
  • @hqt Okay I think I misunderstood your question then. Didn't really understand what you meant by "test method first" in the first time. – viz May 22 '18 at 9:19
  • 1
    If you are working with front-end, I am not sure you really need to test such stuff, because in usual provider like metamask will handle it. Anyway I'm looking into truffle-contract code and it looks like it will support if web3.eth.contract suppports. – viz May 22 '18 at 9:29
  • Thanks. I have tested. I am using web3 embedded by MetaMask. As I tested, web3.eth.contract is existed. But I don't know how to use this method. thanks. – hqt May 22 '18 at 9:34

Your Answer

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

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