Using the Deployed Smart Contract in Remix

To interact with our smart contract, let's look at the functionality we have available. Under Deployed Contracts, expand your deployed Money Game smart contract to see its functions:

MoneyGame6

We have the following functions:

  • play: allows a user with a blockchain address to join the current game - the red button means it's a payable function and we need to pass in ether to call it

  • readTargetNumber: shows the owner of the contract the current targetNumber

Reading data from the smart contract#

When a smart contract gets deployed on the Ethereum blockchain, you have a piece of software that lives on the blockchain. The software we have created is the Money Game. This section will teach you how to interact with a deployed smart contract on Remix (i.e. play the Money Game that we created on the Ethereum blockchain). To use the Money Game smart contract we will invoke various functions (the ones we created) using Remix.

The address that we used to deploy the smart contract has been set as the "owner". To verify this, look at the address you deployed the contract with in the JavaScript console or if you haven't changed the Account field under the Deploy & Run Transactions section.

MoneyGame7

These are all the accounts that are loaded with the JavaScript VM running on my computer (yours will look slightly different).

MoneyGame8

I take note that the account that I deployed with started with 0x5b3 and ends with eddC4.

Now if I cross-reference with what I see in the JavaScript console, the section of Remix where I can see my blockchain transactions, I will see the corresponding transaction that I executed to deploy my smart contract.

MoneyGame9

Now that we can confirm the address that I used to deploy the smart contract, let's see if we can invoke the readTargetNumber function. If we can invoke it correctly, we should see the value 5 returned to us since that is what we set it as when we deployed the smart contract.

To invoke the function, click the button labeled readTargetNumber. You should see a value returned, 5 (if you set your targetNumber) to be 5.

MoneyGame10

The console will also identify to you that the address you deployed with is trying to read the function.

MoneyGame11

To confirm that the function works, let's change the address that we are using and try to call the function again. I can change the function by scrolling back to the top of Remix and changing the address to another account (e.g. one that starts with 0xAb8 and ends with 35cb2).

 

This page is a preview of Creating an ERC20 Token on Ethereum

No discussions yet