I have a pretty straight-forward contract that let's you buy ERC721
Tokens.
My issue is that my "buyToken" function works half the time - and fails the other half of the time with the following error:
MetaMask - RPC Error: Error: [ethjs-query] while formatting outputs from RPC
'{"value" :
{"code" :-32603, "data":
{"message" : "VM Exception while processing transaction: invalid opcode",
"code" : -32000,
"data":
{"0xfd7b08996eb28759737deb2d695baaee53aaa0cea819d9f27a79181ccba021ae":
{"error" : "invalid opcode",
"program_counter" : 2687,
"return" : "0x"},
"stack" : "c: VM Exception while processing transaction: invalid opcode\n
at Function.c.fromResults (/usr/local/lib/node_modules/ganache-
cli/build/ganache-core.node.cli.js:4:194812)\n
at w.processBlock (/usr/local/lib/node_modules/ganache-cli/build/ganache-
core.node.cli.js:42:53376)\n a
t processTicksAndRejections (internal/process/task_queues.js:93:5)",
"name" : "c"
}
}
}
}'
What I'd really like to know is how we are supposed to decipher these invalid opcode
errors. Like what exactly does "code" :-32603
and "code" :-32000
actually mean?
What are the possible candidates of the issues I should be looking for?
To be clear: if my code failed 100% of the time and gave me this same error every single time, I would know with 100% certainly that it's my code that's bad. But it's working at least 50% of the time - and there's been absolutely no consistency in the failures.
I thought it might have to do with the PRICE of the Tokens - I have them ranging from 0.5 ETH
to 15 ETH
. But I could buy a Token for 1.5 ETH
and have the Tx
succeed, and then immediately try to buy another Token for the exact same 1.5 ETH
amount - and that Tx
would fail.
So this makes no sense.
Any tips on the sort of things I should be looking into with these invalid opcode
errors?