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

hqt
  • 449
  • 1
  • 3
  • 12

1 Answers1

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.

viz
  • 535
  • 4
  • 12
  • 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: https://ethereum.stackexchange.com/questions/765/what-is-the-difference-between-a-transaction-and-a-call (Recommendation to Call first, then sendTransaction) – hqt May 22 '18 at 04:55
  • So that means truffle-contract doesn't support this way ? – hqt May 22 '18 at 04: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 09: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 09: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 09:34
  • Do we have any reference said that metamask will do this for developer ? (testing before sending transaction). thanks. – hqt May 22 '18 at 09:34
  • Hmm.. I'd like to revoke that comment on metamask, it does estimate gas though. I think maybe the error has to do with ganache. Can you try this with testrpc? – viz May 22 '18 at 09:45