Vikas Singh

sharing words with this world :)

Archive for the month “May, 2016”

POC on Blockchain: A firsthand experience of ETHEREUM MIX IDE

·         Download the Ethereum MIX IDE from below links. It’s a C++ implementation.

https://github.com/ethereum/cpp-ethereum/releases

  • Take help in learning the solidity language from below links.

 

https://github.com/ethereum/wiki/wiki/Solidity-Features

https://learnxinyminutes.com/docs/solidity/

http://solidity.readthedocs.io/en/latest/

 

  • Ethereum IDE community have their communication channel on gitter, which you can access at below location for help.

https://gitter.im/ethereum/ethereumj

  • There shall be some dependent softwares one might need to download to make sure you have a running MIX IDE on Windows8.1 (this is platform where we developed our POC). I’ve to download this package as a dependent software.

 

https://www.microsoft.com/en-ca/download/details.aspx?id=40784

  • After successful download and installation of the MIX IDE, the screen shall look like this.
IDE_SNAPSHOT

IDE_SNAPSHOT

 

  • Currently, the above screen have some entries which we created during the creation of the contract like sol and Page1.html. These terms like contract shall be present in the links provided for Solidity language above. Rest of the things in the left side of the screen comes bundled with the MIX IDE. It has a sample contract named contract.sol and one HTML file called index.html

To create the contract as per your use case, one have to write the contract in the black screen in the above IDE.

Once you are done with writing the contract, deploy it on the blockchain, so that you and your fellow users can start using this in each of their subsequent transaction. The IDE gives you error if there is some error in the contract. Check below screenshot.

 

Blockchain Error

Blockchain Error

 

In the above screenshot, I’ve removed the ‘;’ from the 3rd line of the contract, which gave you the above error. So, once there is no syntax error, check for syntactical error.

NOTE: Make sure that there shouldn’t be any infinite loop.

For every function that you write to deploy on blockchain in contract, some gas is used. If while deploying the contract, there exist an endless loop, the MIX IDE won’t be able to store it in the blockchain.

So, let’s deploy the contract and learn the steps while doing it. All the deployment is being done on the local machine. No live/test blockchain is being used in this.

Machine used for POC:

 

Machine conf

Machine conf

 

To deploy the contract in local machine, we click on the Add transaction on the right side.

Add Transaction

Add Transaction

 

We get below screen.

Add Transaction-2

Add Transaction-2

 

Notice the Gas, in the bottom half of the above screen as Transaction Fees.

Gas details in transaction

Gas details in transaction

 

Select the contract which you created & want to deploy on the blockchain. In my case, it’s preopertyTransfer. I selected the preopertyTransfer from drop down. The Gas should be calculated and must show some no. It should not display anything other than a no. Now, click OK on the above screen. We get below screen.

Deployed the contract in Blockchain

Deployed the contract in Blockchain

 

Now, there are some significant things you have to check. Let’s start one by one.

  • On top, the message should be “Run Complete”.
  • A transaction should come under the Pending transaction on right side. This is the contract which we deployed.
  • User account pane shall appear just below of the Pending transaction on the right side.
  • Public variables in the contract shall come under the contract account on the right side.

You can add any no of user in the IDE from the Edit Starting Parameters button. 4 users are by-default present in the IDE. In our case, we just renamed them. You can add the user account and assign them some initial amount in the internal currency that Ethereum has created. PFB Screenshot.

 

Adding an account in MIX

Adding an account in MIX

 

Click OK. This TestUSer1 shall be added to the accounts. You can use this account in the transaction for this POC. Though, we have used the already present users in the IDE.

 

successful addition of user account

successful addition of user account

 

The amount we gave to the TestUser1 was 100 Ether, but on screen it’s showing 1 with lot of zeroes. You can check this currency conversion at below link. Here you shall know, how much wei is there in 1 ether.

http://ether.fund/tool/converter

Let’s perform some transaction using the contract that we deployed in the blockchain.

The use case which we are trying to create is “transfer of property”. We want the property to be transferred securely and user should not be able to double spend the same property.

  • Now, as per the use case, each user shall first assign one property to himself. We need to declare that a user1 owns some property Say, e.g. user1 owns property1, user2 owns property2, so on and so forth.
  • Then one user1 shall transfer his property to other user, a user2 may be.
  • Again, user1 shall try to transfer the same property to another user, say user3, which is already transferred in the previous step to user2. We’re trying to create a scenario of double spending here. In this case, ideally, the property should not be transferred from user1 to user3, as it’s already transferred to user2.
  • Now, user2 shall be able to sell the property to user3. As the property belongs to the user2.

We shall do this only. Other than this, we did not covered in this POC.

 

Let’s assign property to user Vikas and Saket the properties Vikas1 and Saket1 respectively.

Click on the PLUS sign on the right hand side of the IDE and click Add transaction.

 

Add Transaction for deploying contract

Add Transaction for deploying contract

 

Make sure, after clicking Ok, that the

  • Sender Account is selected as Vikas.
  • Type of Transaction is seleted as “Transact with Contract”.
  • Recipient contract is “Property transfer – 0”
  • Function is storeProperty
  • propertyName is “Vikas1”

Leave rest of the things as it is. PFB snapshot. Click OK.

 

transact with contract-txn1

transact with contract-txn1

 

Notice the right hand side screen. A new entry pop-up in the Pending transactions. Also the variables start changing their states.

  • The top two variables, flag and the nameOfPropertyTransferred, are going to change their state when the transfer of the property shall take place.
  • The last variable is keeping hold of the total no of property present at any point of time in the blockchain for this particular contract. So, total no of property is 1 now, after the property “Vikas1” is created into the blockchain system.

 

Store-property-1

Store-property-1

 

Similarly, add Saket1 property by the name of Saket. Make sure that the Sender Account name is selected as Saket this time in the below screen. Click OK.

 

Store-property-2

Store-property-2

 

You can see that the variable count is 2 now.

 

check variables after 2nd store property

check variables after 2nd store property

 

Now Vikas shall transfer the property “Vikas1” to Saket. We shall use the contract now to transfer the property. Again, click on Add transaction. And make sure that:

  • Sender account is selected as Vikas. As Vikas is transferring his property to Saket.
  • “Type of transaction” should be “Transact with Contract”.(this is what for we deployed our contract, to handle the storing and transfer of the property in blockchain)
  • Recipient Contract is “propertyTransfer-0”
  • Function is “transferProperty”
  • Recv(Address) is Saket, to whom Vikas is transferring the property.
  • & at last, the propertyName, “Vikas1” in this case.

Leave rest of the things as it is. Click OK.

 

transfer property vikas to saket

transfer property vikas to saket

 

Check the transaction variable. Flag signifies that the transfer was successful and the name of the transferred property is “Vikas1”.

 

variables after transfer property

variables after transfer property

 

Let’s try to send the same property from Vikas to Shashi, a third user in the system. Kindly follow the same steps. Click on the add transaction. And this time, we shall select Shashi as the recv address. PFB screenshot.

 

double spend 1

double spend 1

 

Click ok. Look at the variables now. The Flag says “undefined”, because we ‘can’t transfer the property’. & the total property in the blockchain is still 2, i.e. “Vikas1” & “Saket1”.

 

variables after trying the double transfer of property

variables after trying the double transfer of property

 

Let’s try to send the property from its rightful owner, Saket, to Shashi. Ideally, it should happen. Follow the same steps as per the previous step. Now by this step, one should know which user shall be sender and which one is recv.

 

transfer property saket to shashi

transfer property saket to shashi

 

Click ok. And observe the variables.

The flag is “true”, the nameOfPropertyTransferred is “Vikas1” and total no of property is still 2 in the system as there is no new addition.

 

variables after transfer property from saket to shashi

variables after transfer property from saket to shashi

 

We have finished our POC by completing this exercise.

Let’s check inside the transactions, what happened in the blockchain one by one.

First, we deployed the contract in the blockchain, let’s visit that.

Click on expand transaction of the transaction from the right side under Block1. A small arrow beside debug button.

 

expand txn link

expand txn link

 

Click on it. The transaction shall be opened. & we can see the details involved in deploying the contract. It shows that “Vikas” was the user who deployed the contract. To distinguish the contract from the actual transaction, notice the function being called. It’s the constructor of the contract itself.

 

internal of the deployed contract

internal of the deployed contract

 

Let’s visit the next transaction, where Vikas has stored the property “Vikas1” in the blockchain. Let’s click on it.

Notice the function called. It’s storeProperty of propertyTransfer contract. When we were carrying-out this transaction, we only provided the property name, “Vikas1”, which is shown below as well. It also indicates total gas used in carrying out this transaction in blockchain

 

internal of the storing of property Vikas1

internal of the storing of property Vikas1

 

Let’s move onto the next transaction. Here you can see that the sender is Saket and the property name is “Saket1”. Rest of the parameters are also showing similar no as above.

 

internal of the storing of property Saket1

internal of the storing of property Saket1

 

Let’s look at the transaction, where Vikas transferred the property “Vikas1” to Saket(his address shall be present in recv. You can verify that it’s the same user, by clicking on the edit parameters). In the below transaction, we user different function of the contract i.e. transferProperty. & we gave two parameters while doing it, i.e. recv add and the property name. You can cross-verify the same from the previous screenshot in the exercise, where we performed this transaction.

 

internal of the transfer of property Vikas1 to Saket

internal of the transfer of property Vikas1 to Saket

 

Now, as the property is transferred to Saket. Let’s see the transaction where we shall try to spend it again. In the below screenshot we tried to transfer the property to Shashi. You can see the recv add and the property “Vikas1”. Gas used shall be displayed in every transaction which is stored in blockchain successfully.

 

internal of the double spending of property Vikas1 to Shashi

internal of the double spending of property Vikas1 to Shashi

 

Let’s look at the final transaction, where Saket transferred the property “Vikas1” to Shashi, as he was the owner of the property of “Vikas1” after Vikas has transferred it to Saket. Recv address of Shashi can be seen in the pane below.

 

internal of the genuine transfer of property Vikas1 from Saket to Shashi

internal of the genuine transfer of property Vikas1 from Saket to Shashi

 

A lot of thing in this POC wasn’t included e.g. Events and re-using the contract & a whole lot more jargons. As it’s a wide space to explore, we kept the POC to optimum use of the terminology and get it done.

By going through this exercise, you shall be able to understand the core-use of the MIX IDE provided by Ethereum i.e. using of local blockchain for our own use-case.

This POC provides a high level of understanding in storing the variables in blockchain and doing some transaction like storing and transferring “something of value” i.e. property in our case and get the relevant information as output, in terms of variable.

Post Navigation