Deploy and Use the Smart Contract
First thing is to deploy the Smart Contract. Then weāll see if we can deposit some Ether and get the balance from the Smart Contract.
Deploy the Smart Contract
Head over to the Deploy and Run Transactions Plugin and deploy the Smart Contract into the JavaScript VM:
It should appear at the bottom of the Plugin - you probably need to expand the contract instance:
Send Ether To The Smart Contract
Now it is time to send some Ether to the Smart Contract!
Scroll up to the āvalueā field and put ā1ā into the value input field and select āetherā from the dropdown:
Then scroll down to the Smart Contract and hit the red āreceiveMoneyā button:
Also observe the terminal , see that there was a new transaction sent to āthe networkā (although just a simulation in the browser, but it would be the same with a real blockchain).
Check the Balance
Now we sent 1 Ether, or 10^18 Wei, to the Smart Contract. According to our code the variable balanceReceived
and the function getBalance()
should have the same value.
And, indeed, they do:
But how can we get the Ether out again? Letās add a simple Withdrawal method.
You want to try yourself first? Here are some hints:
We want a function that sends all Ether stored in the Smart Contract to the msg.sender (thatās the address that calls the Smart Contract).
Since Solidity 0.8 that is non-payable, so youād need to do something like payable(msg.sender)
, which would give you an address that is capable of receiving Ether.
If you have no clue what the heck Iām talking about, donāt worry - just head over to the next page.