Interacting with Deployed Contract

Now, you are ready to interact with the contract that you have deployed. Go back to MyEtherWallet desktop and click on the “Interact with Contract” tab as shown in the screenshot below −

Interact With Contract

Paste the contract address that you previously copied in the “Contract Address” field. You also need to paste the “ABI / JSON Interface” of the contract on the above screen.

To get the ABI, go to the Remix window and click on the ABI button as shown in the screenshot below.

ABI button

The ABI / JSON interface will be copied to the clipboard. Paste this in your favorite editor to examine the generated interface, which is shown below −ABI / JSON Interface [ { “constant”: false, “inputs”: [ { “name”: “newDeposit”, “type”: “uint256” } ], “name”: “send”, “outputs”: [], “payable”: false, “stateMutability”: “nonpayable”, “type”: “function” }, { “inputs”: [ { “name”: “initialAmount”, “type”: “uint256” }, { “name”: “initialValue”, “type”: “uint256” } ], “payable”: false, “stateMutability”: “nonpayable”, “type”: “constructor” }, { “constant”: true, “inputs”: [], “name”: “getAmount”, “outputs”: [ { “name”: “”, “type”: “uint256” } ], “payable”: false, “stateMutability”: “view”, “type”: “function” }, { “constant”: true, “inputs”: [], “name”: “getBalance”, “outputs”: [ { “name”: “”, “type”: “uint256” } ], “payable”: false, “stateMutability”: “view”, “type”: “function” } ]

After you paste this JSON in the MyEtherWallet interface, you will notice that the ACCESS button below the JSON interface is now activated, as shown below −

My Ether Wallet

Click Access button to access the contract.

Upon clicking the Access button, the contract address and function selection dropdown will appear on the screen like in the Remix editor. This is shown in the screenshot below −

Access button

You may check the various functions of the contract as in the case of Remix deployment. Note that the contact is now deployed on an external Ganache Blockchain. Check the getAmount function; you will get the Amount value of zero and the getBalance will show a balance of 1000.

Now try sending some money. It will present you a textedit control for entering the amount. When you write the contract, some “gas” would be used and you will be asked to confirm the transaction before writing it to the Blockchain. The transaction would be executed in a short while depending on the mining timing set by you on the Ganache server. After this, you can reexamine the value and the amount fields of the contract to verify that these are indeed modified.

You may now examine the Ganache desktop to view the transactions that you have performed so far. A sample output is shown below −

sample output

So far, you were both the contract creator and the contract executor. This does not make much sense, as you expect others to use your contract. For this, we will create another client for our Ganache Blockchain and send some money from the newly created account # 2 to the contract creator at account # 1.

Similar Posts

  • Ganache for Blockchain

    Ganache is used for setting up a personal Ethereum Blockchain for testing your Solidity contracts. It provides more features when compared to Remix. You will learn about the features when you work out with Ganache. Before you begin using Ganache, you must first download and install the Blockchain on your local machine. Downloading Ganache You…

  • Summary

    You learned how to write your own digital contract in Solidity. You developed and tested the contract interface in the Remix IDE. For further multi-user testing, you deployed this contract on Ganache Blockchain. On Ganache, you created two user accounts. The first account was used for publishing the contract. The second account was used for…

  • Creating Wallet

    In this chapter, we will learn how to create Ethereum wallet. To create a new wallet, enter a password of your choice and then click on the “Create New Wallet” button. When you do so, a Wallet would be created. A digital wallet is essentially the generation of a public/private key pair that you need…

  • Deploying Contract

    To deploy the contract, select the Contracts menu option as shown in the screenshot below − You will need to enter the contract’s bytecode on this screen. Remember, when you compile your Solidity contract code, it generated a bytecode that runs on EVM. You will now need to obtain this bytecode from Remix IDE. Go to the Remix…

  • Smart Contracts

    There are several tools available to develop and test contracts. One of the simplest tools is provided on the official Ethereum site itself. The tool is called Remix, we will use this for our contract development. Remix for Contract Development Open the Remix IDE by typing in the following URL in your browser.https://remix.ethereum.org The following screen…

  • Creating Contract Users

    In this chapter, we will learn the creation of contract users on Ethereum. To create a user for our published contract, we will create another MyEtherWallet client attached to the same Ganache Blockchain that you have been using in the previous steps. Go to the MyEtherWallet screen and create a new wallet. Click on the contracts menu and select the “Interact with…