Ethereum – 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 IDE screen, your earlier typed contract should be there in the code window. If not, retype the contract in the code window. Click on the Bytecode button as shown in the following screenshot − The bytecode for your compiled source is copied to the clipboard along with some other information. Paste the copied code into your favorite text editor. Following is the screenshot of the text editor − The value of the object tag contains the desired bytecode. Copy this carefully making sure that you do not copy the enclosing quotes. The bytecode is really long, so make sure that you copy right upto the last byte inclusive of it. Now, paste this bytecode in the Deploy Contract screen as shown below − The Gas Limit field is automatically set. Below the Gas Limit field, you will find the selection for accessing the wallet. Now, access the wallet using the Private Key of the Ganache account on which this contract will be deployed. To get this private key, go back to the Ganache window. Click on the keys icon of the first account as shown below − You will see the private key of the user account # 1 as seen in the screenshot below − Copy this private key and paste it in the “Paste Your Private Key” section as shown below − You will see the “Unlock” button at the bottom of the screen. After unlocking, a “success” message will appear at the bottom of the screen. At this point, your wallet is attached to account #1 of the Ganache Blockchain. Now, you are ready to sign and deploy the contract. Click on the “Sign Transaction” button as shown in the screenshot below − Signing the transaction generates and displays both Raw and Signed transactions. Click on the “Deploy Contract” button to deploy the contract on the Ganache Blockchain. Remember the contract is deployed by account # 1 user of the Ganache Blockchain. Therefore, account # 1 user becomes the contract creator. Before the contract is deployed, you will be asked to confirm the transaction as it may cost you some real money if you were to deploy this contract on a public real Ethereum Blockchain. Do not worry, for the current private Blockchain running on your local machine, there is no real money involved. Click on the Make transaction button as shown in the screenshot below − Examine the Ganache console; you will see that the ETH balance in the account # 1 has reduced as seen in the screenshot below − Now, click on the TRANSACTIONS menu as shown in the screenshot below − You will see the transaction details. On this screen, you will find the contract’s published address. The address is marked in the above screenshot. You will distribute this address publicly to let others know that your contract is available at this specified address to which they can connect and execute the contract methods, such as sending money to you – the contract creator. Copy this contract address for your own reference as you are going to need it in the next step.
Category: Ethereum
Ethereum – 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 to store in a safe place. The wallet creation results in the following screen − Click on the “Download Keystore File (UTC / JSON)” button to save the generated keys. Now, click on the “I understand. Continue” button. Your private key will appear on the screen as seen in the screenshot below − Click on the “Print Paper Wallet” button to keep a physical record of your wallet’s private key. You will need this later for unlocking the wallet. You will see the following screen. Do not lose this output. To unlock your wallet, click on the “Save Your Address” button. You will see the following screen. The wallet can be unlocked using the Private Key option as highlighted in the above screen. Cut-n-paste the private key from the previous screenshot and click the Unlock button. Your wallet will be unlocked and you will see a message appear at the bottom of the screen. As the wallet does not contain anything as of now, unlocking the wallet is not really useful to us at this point.
Ethereum – A Quick Walkthrough We will now briefly understand what is available on the Ganache desktop. On the Desktop, at the top we have several menu options out of which a few are of immediate relevance to us. The menu bar is highlighted in the screenshot below − Clicking on the TRANSACTIONS menu shows all the transactions performed so far. You will be performing transactions very soon. Now, come back to the above screen and check the transactions from time to time. A typical transaction screen is as shown below − Likewise, when you click on the BLOCKS menu, you will see the various mined blocks. Consider the following screenshot to understand how the BLOCKS menu looks like − Click on the LOGS menu. It will open the system log for you. Here, you can examine the various operations that you have performed on the Ethereum Blockchain. Now, as you have understood how to use Ganache for setting up a private Ethereum Blockchain, you will now create a few clients who would use this Blockchain.
Ethereum – 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. The following screen will appear. In the center window, you will see some default code, which is a sample Solidity code. You will type your contract code in this code editor. Your code may be auto-compiled. Upon successful compilation of the code, you will be able to run the code in the same IDE. When you execute the contract methods, the results will be displayed in the same IDE window. There are facilities to debug the code and to unit test your project. These can be seen in the menu bar at the top right hand side as shown in the IDE screenshot below. You will be using these options shortly. You will now start writing your contract.
Ethereum – Interacting with the Contract When you click the deployed contract, you will see the various public methods provided by the contract. This is shown in the screenshot below. The first method send contains an edit box in front of it. Here, you will type the parameters required by the contract method. The other two methods do not take any parameters. Sending Money Now, enter some amount such as 100 in front of the send function seen in the contract window. Click the send button. This will execute the contract send method, reducing the value of the contract value field and increasing the value of the amount field. Examining Contract Value The previous send money action has reduced the contract value by 100. You can now examine this by invoking the getBalance method of the contract. You will see the output when you click on the getBalance button as shown in the screenshot below − The contract value is now reduced to 900. Examining Collected Amount In this section, we will examine the amount of money collected so far on this contract. For this, click on the getAmount button. The following screen will appear. The amount field value has changed from 0 to 100. Try a few send operations and examine the contract value and the amount fields to conclude that the deployed contract is executing as expected.
Ethereum Tutorial Job Search Looking at the advantages offered by Bitcoin − a digital currency, people wanted to use the concept of Blockchain in their own applications. People wanted to move out of their physical contracts to smart digital contracts where several issues like repudiation, transparency, security, etc. would be automatically addressed. The outcome of this effort resulted in the creation of Ethereum − a popular platform for creating distributed Blockchain applications that support smart contracts. Audience This tutorial is designed for those who wish to gain some insight on how Ethereum works. After completing this tutorial, you will find yourself at a moderate level of expertise from where you can take yourself to the next level. Prerequisites Before proceeding with this course, we assume the reader has basic understanding in Web Development, JavaScript, Ajax-Requests, AngularJS, Gulp/Grunt and the Node Package Manager.
Ethereum – MyEtherWallet For client application, you will use MyEtherWallet. Download MyEtherWallet software from the following URL − If required, unzip the downloaded file and open index.html. You will see the following interface for creating a new wallet.
Ethereum – Developing MyContract We will name our contract MyContract as in the following declaration − contract MyContract { We will declare two variables as follows − uint amount; uint value; The variable amount will hold the accumulated money sent by the contract executors to the contract creator. The value field will hold the contract value. As the executors execute the contract, the value field will be modified to reflect the balanced contract value. In the contract constructor, we set the values of these two variables. constructor (uint initialAmount, uint initialValue) public { amount = 0; value = 1000; } As initially, the amount collected on the contract is zero, we set the amount field to 0. We set the contract value to some arbitrary number, in this case it is 1000. The contract creator decides this value. To examine the collected amount at any given point of time, we provide a public contract method called getAmount defined as follows − function getAmount() public view returns(uint) { return amount; } To get the balanced contract value at any given point of time, we define getBalance method as follows − function getBalance() public view returns(uint) { return value; } Finally, we write a contract method (Send). It enables the clients to send some money to the contract creator − function send(uint newDeposit) public { value = value – newDeposit; amount = amount + newDeposit; } The execution of the send method will modify both value and amount fields of the contract. The complete contract code is given below − contract MyContract { uint amount; uint value; constructor (uint initialAmount, uint initialValue) public { amount = 0; value = 1000; } function getBalance() public view returns(uint) { return value; } function getAmount() public view returns(uint) { return amount; } function send(uint newDeposit) public { value = value – newDeposit; amount = amount + newDeposit; } }
Ethereum – Compiling the Contract Once you write the complete contract code, compiling it in this IDE is trivial. Simply click on the Autocompile checkbox in the IDE as shown in the screenshot below − Alternatively, you may compile the contract by clicking the button with the title “Start to compile”. If there is any typo, fix it in the code window. Make sure the code is compiled fully without errors. Now, you are ready to deploy the contract.
Ethereum – Introduction A huge success of Bitcoin raised interest in the minds of several to create their own currencies. Looking at the advantages offered by Bitcoin – a digital currency, people wanted to use the concept of Blockchain in their own applications. People wanted to move out of their physical contracts to smart digital contracts where several issues like repudiation, transparency, security, etc. would be automatically addressed. The outcome of this effort resulted in the creation of Ethereum – a popular platform for creating distributed Blockchain applications that support smart contracts. In this tutorial, you will learn how to create a distributed application (DAPP) on Ethereum platform. More specifically, you will learn how to write a contract, test it on a local Blockchain and finally deploy it on an external Blockchain for deep testing and commercial use. You will use Solidity, an object-oriented language for contract development. You will also use Remix, an open source IDE for developing and testing contracts. To deploy the tested contract on an external Blockchain, you will use Ganache. To interact with the contract you will need a client application. We will use MyEtherWallet to create a wallet for each such client. The contract creator will publish the contract. Any other client will look at the contact value by using the interface provided by the contract and send some money to the creator for executing a part of the contract. So let us begin by writing the contract.