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.
Try it yourself first?
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.