Metamask-RPC error with payload

Hi @filip
Hi guys,
I keep getting this error “Metamask-RPC error with payload”
I tried thousands times to remove and add Metamask;
I also tried Metamask/ Advanced/ RESET All Accounts…;
I tried restart all, re initialize truffle project, migrate project from beggining… etc
Some times it works, but it appears again after few clicks…
I also searched the web for this issue… nothing worked
Are there someone had the same issue and can share the way out? Thank you.

I came up with adding a TopUp function, where I should top-up the Contract ballance before querying network… and it works…
OH… NO… It appears again… I had top up the contract for a huge amount, and still error…
Codes run well on Remix and passed all of my tests on truffle console…

Hi guys…
after reading this:


I have added these lines to the top of main.js;
// Is there is an injected web3 instance?
if (typeof web3 !== 'undefined') {
  //App.web3Provider = web3.currentProvider;
  web3 = new Web3(web3.currentProvider);
} else {
  // If no injected web3 instance is detected, fallback to Ganache.
  //App.web3Provider = new web3.providers.HttpProvider('http://127.0.0.1:7545');
  web3 = new Web3(App.web3Provider);
}

Don’t know if because of this or not but it seems this payload error is over (?)…

But the bad news is there is new error appears…

:thinking: :thinking: :thinking:

here is my updated code :

In my own experience with this project so far, a “RPC payload error” seems to indicate the contract returned an error message instead of success. Most often because:

  • A require statement failed resulting in a transaction rollback

It probably started working again after you added the “top up” method because it was trying to send ETH for a winning bet but didn’t have any ETH to send.

I’ve also had a problem where calling the paceBet() contract method resulted in setting ridiculous amounts of gas in Metamask. This happened when I started calling the provable_newRandomDSQuery() function in the provableAPI and was due to the fact it that it only works on the test network. Once I deployed to kovan it worked again.

1 Like

Thank you @mayjer
I am trying to check over all require statments…
So far I dont see the Error_PayLoad any more, instead I am having the issue with Big Number…

I remember @filip once said about this in a video… but could not remember in which episode…?
// New update:
I found that this is issue related to web3.min.js file, which is noted here:

Can I just install new version web3 via npm to avoid using this web3.min.js file? @filip

No, it seems not a right question… npm is just to install pakages for node.js right? While here we are just working on html… But don’t we have latter update for web3.min.js?

BigNumber is huge pain. Some general tips on it:

  • Always initialize BN instances with a string like new BN('1')
  • Always use BN instances with BN functions like let payout = betAmount.mul(new BN('2'))
  • web3.utils.fromWei() returns a string so you need to change it into a BN
  • If you pass web3.utils.toWei() a BN it will return a BN
  • When you query a contract function that returns uint256 with the web3 contract instance the value received in the response is a string so you need to convert it to BN

That’s about all I can say without trying to run your code, which my brain is too tired for atm. Hope that helps some.

1 Like

@mayjer,
I afraid I could not understand what you mean . Could you explain me more simple with a little code?

Here is my function in solidity:

function createBetForPlayer(uint betChoice, uint betAmount, address playerAddress) public {...
}

When I pass 1eth value which is converted to number type of wei and equals so thing like 10^18 wei -> error appears.

  1. the uint data type should hold be able to hold the value higher than 10^18 right? So why is the error?

  2. Are you suggesting to change the data type to string? Does it means I should change input data type of the solidity function in to string memory ? But in that case, other functions that call this function from inside Solidity file should then convert values like msg.value to string also (before passing data to this function). But as I know there is no builtin function for this Uint To String coversion (?)… And beside, does it means that all math with these "string"s should use implicit emulated math functions? … is kind of too confusing , is there any more simple approach?