Programming Project - Phase 1

I Haven’t :frowning:

As suggested, caller is declared address payable in the function. The eth is always being sent to the contract, but never payed back.

1 Like

Here is my coin flip assignment.

1 Like

@xactant @Dominik_Clemente @KamilK

Hi Guys, This RPC error is doing my head in. Just when you fix a bug and would like to move onto the next issue, MetaMask gives you the middle finger.

How did you guys reset metamask to fix the issue? My port is correct. If you change the imported ganache private key to Account 2, do you have to make a change in the main.js file to reflect this?

Any assistance would be greatly appreciated.

Happy Quarantine!
Saoirse

Reset your browser cache to use your new/updated main.js file. Just reload the page by pressing Shift + F5

2 Likes

For anyone experiencing the RPC error issue (don’t worry, it’s not your fault!), the quickest way to solve it is to uninstall MetaMask and reinstall.

Resetting the browser cache wasn’t enough to solve it for me.

Anybody else having trouble with their withdrawal function? I see a lot of the submitted projects do not have withdrawal functionality.

2 Likes

Can you share a github link of your project i ll test it ?

1 Like

Thanks, I will. I moved into the ethereum game course, when I finish that I’ll return to this one.

1 Like

Hi all!

I’ve got the Dapp working for the most part:

The gif shows the interaction of a random user. If the admin (deployer of the contract) opens the page, then there pops up an additional admin-area, where you can fund the contract and withdraw the funds:

Anyways there are two major issues and reading the replies in this thread it appears to be a common issue:

  1. MetaMask Error: Sometimes (it almost seems at random) I receive a MetaMask RPC Error, the error message tells something about and rpc payload error. I tried to google the problem but didnt find a reason or a fix yet. When the error appears I simply retry the transaction or refresh the page, in both cases the error usually won’t pop up again. Very strange

  1. WithdrawFunds doesnt work: This issue I’ve also seen some times in this thread. I’m using Filips standard withdrawAll() function which I came across during the course:
function withdrawAll() public onlyOwner returns(uint) {
        uint toTransfer = balance;
        balance = 0;
        msg.sender.transfer(toTransfer);
        return toTransfer;
    }

When running the function via the Frontend Button the function will execute and even return me the “toTransfer” amount but the transaction seems not to go through and also the balance is not 0 but back to its original balance. I believe this happens because the transaction has an error and gets reverted. But I couldnt figure out why it reverts.

Does someone have a solution for those two problems? I just created my github profil and uploaded the entire project: https://github.com/Laserbach/laser-stuff

@filip

Best - Lars

1 Like

I have the same problem (besides the withdrawFunds issue). I couldnt yet figure out why the problem appears, but refreshing the page or simply retrying the transaction works for me. Anyways not a satisfactory solution…

1 Like

Hi @Laserbach

Your withdrawAll function doesn’t work because you are calling it with call() instead of send() in your frontend:

function widthdrawFunds() {
  contractInstance.methods.withdrawAll().call().then(function(result){
    result = web3.utils.fromWei(result, 'ether');
    alert("Balance withdrawn!")
    console.log(result);
  })
}

Should be

function widthdrawFunds() {
  contractInstance.methods.withdrawAll().send().then(function(result){
    result = web3.utils.fromWei(result, 'ether');
    alert("Balance withdrawn!")
    console.log(result);
  })
}
  • Send() is used when Functions are altering the state of the contract
  • Call() Functions when it does NOT altering the state of the contract

In your frontend code you are using send() for the flip/deposit functions why not for withdrawAll ?

EDIT: For your error in metamask does it happen when you are trying to switch to an other account ?
In this case i ll recommend you to look at this

https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#ear-listening-for-selected-account-changes

4 Likes

Hi Gabba,

As I am also having trouble with my withdrawal function, I decided to try out your code but I am getting an error when I run it (see below).

Uncaught (in promise) Error: Please pass numbers as strings or BigNumber objects to avoid precision errors.

I have tried also converting to a string but I get a different error (I am not familiar with what a BigNumber object is.

Thanks for your assistance, it is greatly appreciated.
Saoirse

Thank you so much for your reply, you have been spot on regarding the withdrawAll() function!
I have no idea why I decided to use call() over send().

Regarding MetaMask it is still a bit a weird issue. The error doesn’t explicitly happen when switching accounts (admin to user as example), I also had the error when I tried to make a flip directly after funding the contract. What I then do is I empty the cache, reload and then usually its all fine.

The resource you gave me regarding switching accounts on MetaMask is very interesting anyways and I will implement it.

Thanks a lot for your time and wishing you a great weekend!

Best - Lars

2 Likes

Can you share a github repository ?
Otherwise can share your function in solidity and in your javascript code ?
My answer to LaserBach was specific to his code

1 Like

Hi Gabba,

Thanks for taking a look! Also for some reason, my html elements (like user balance and result output) don’t update on the first function execution only after the second go.

Kindly,
Saoirse

Is this what you are looking for?

Hi @filip,
sometimes i get the following error from Metamask:


Can you say me how I can find out from where the error comes from, or what it exactly means? It Comes up when i flip the coin. Coding in Smart Contract:

Coding in main JS:

Thanks!!

1 Like

your code looks good, i do some research and i found this possible solution.

medium-Reset MetaMask.

PLEASE REMEMBER: before reseting the metamask or uninstalling it, put your private keys safe, you may lose them in the reset process, just please be aware of this.

Hope this work for you!

Carlos Z.

2 Likes

Thanks! I’ve tried it and it seems to work!

Addendum: That was probably too early :wink:
Sometimes the error still occurs. I’ve found this Github Post: https://github.com/MetaMask/metamask-extension/issues/7286

If I increase Gas Limit it seems to work.
Maybe it is, because In my coinFlip() method I call playerWon() or playerLose() method and Ganache is not able to calculate the Gas price?

I’ve noticed, the error occours i anyone wins the bet - and the playerWon() method ist more complex and has higher gas price. Part of sol File:

would it be better in general to integrate the two methods in coinFlip()?

best regards
Daniel

1 Like

Hi, here are my screenshots: https://1drv.ms/b/s!AtMLyk9_Sx70h9MPISclzWN55teXFA?e=0R94Jh

best regards
Daniel

1 Like

Don’t seem to be able to initially fund my contract. What am I missing?