Smart Contract and Remix IDE

Tram Ho

Today I will introduce you a tool to program Smart Contract in the style of instant noodles that is Remix IDE (Please remember to type in more IDE. Type Remix does not indicate the music).

1. Smart Contract

Smart Contract is a contract management protocol Smart contract is a special protocol set with the goal of contributing, confirming or conducting the negotiation or contract performance process. Smart contract helps us make transactions without going through a 3rd channel. But this transaction is completely easy to track and cannot be tampered with or reversed. Smart contract contains all the details about the terms and how to perform them automatically.

2. How does Smart Contract work?

Smart Contract has operations like auto-robots. Or it can be said that these contracts are very similar to RPA (Robotic Process Automation). Everything is pre-programmed and will automatically operate without any party’s impact. First, the properties and permissions are encrypted into a Blockchain block. This Smart Contract will distribute and reproduce by nodes operating on that platform. After being implemented, the contract will be implemented in accordance with the predetermined terms. At the same time, Smart Contract will also automatically check the process of implementing the commitments stated in the contract.

3. What you need to create a smart-contract

• Contract subject: The program must be given access to the product / service listed in the contract so that it can automatically lock or unlock them.

• Electronic signatures: All parties agree to implement the agreement with their private keys (private keys).

• Contract terms: Smart contract agreement takes the form of a series of activities. The parties to the contract must sign and accept it. Once completed, the contract will be uploaded to the Blockchain of the respective rights section and distributed to the nodes of that platform.

4. Pros – Disadvantages of Smart contract

Smart contract has made use of all the advantages of Blockchain technology

• Security Smart contract is encrypted and distributed to nodes. These ensure it will not be lost or modified without your permission.

• Economic efficiency and quickness Most stages are dynamic, and almost eliminate intermediaries.

• Standardize

However, there are disadvantages:

• Human factors Because the entire code is composed by humans and they can still make mistakes. If smart contracts have been uploaded to the Blockchain, programmers will not be able to change it. A famous example of human identity is the DAO event. Programming errors have been discovered and exploited by some hackers, from which 60 million money is taken from users.

• Unclear legal status Currently, Smart Contract has not been managed by any government. Therefore, there is still potential for conflict to occur if institutions decide to build a legal framework for smart contract form.

• The cost of implementing Smart Contract cannot be established without programming. Therefore, it is necessary to have a seasoned programming expert in the development team to minimize possible errors in the contract and ensure the company’s infrastructure. like with Blockchain technology.

Maybe you are interested

What is big data? All you need to know

Slipping into HTTP Polling and SSE (Server-sent event)

5. Why Smart Contract is needed

In fact, the use of a third party stands out to deal with very popular jobs today. However, it is another thing to ensure that the terms of the contract are solved by a third person. That is the reason for the birth of Smart Contract. Contract terms are coded and posted on the block chain. This means everything is transparent and cannot be changed. Both parties can monitor and observe the Smart Contract operation.

For example :

The process of buying and selling online, when you want to buy a valuable product. The requester wants you to deposit some money to make sure you buy before shipping.

You can then transfer money directly to the seller (risk when the seller hugs the pile disappears) or can ask an intermediary to hold the money and receive the goods, then this person will hand over the money to sellers and goods for you (also risky, when the greed speaks), …

With Smart Contract, you can simply program a contract for this purchase according to the following concept. Use electronic money as a unit of money to trade. When you accept the purchase, electronic money (corresponding to the product value will be sent to Smart Contract). After the delivery time without your confirmation, the money will automatically return to your wallet. If the goods delivered to a safe place, you send a confirmation on Smart Contract and the money on Smart Contract will be transferred to a safe seller’s account. All Smart Contract codes are public so you can check the process flow of the process.

Although this is a simple example, it is not possible to solve all the risks of online buying and selling, e-commerce but it is clear that it is much safer than traditional methods.

Another example is the CrytoKitties Game. You play games to buy, sell, give two cats to xxx to create a new cat, … all code related to the flow of the game you can see at ( https://etherscan.io/address/0x06012c8cf97bead5deae237070f9587f8e7a266d# code ). You can view the transactions in the game that happened (Of course who is making this transaction confidential), can view the full code, the token types used for the Game. A groundbreaking game when applying Smart Contract, token ERC721 standard.

6. Smart Contract programming – Remix IDE

“Why Solidity? Isn’t Javascript nearly doing everything? ”. That’s basically the case, but what you write and run on Javascript or traditional languages ​​like C #, ASP.NET , … are all “centralization”. That is, you have control over the data and you change it, no one knows. And Solidity does not allow that. In terms of Solidity language, for those with Javascript platform, they can learn faster because this is a combination of Javascript and object-oriented language.

Remix IDE is an online tool that helps you to program Smart Contract immediately at the website: https://remix.ethereum.org .

The website supports you to create files with the .sol extension.

Compile with versions from oldest to newest of solidity. There is a console log section of syntax errors, code codes, … warnings and successful compilation sections

Support Smart Contract deployments with:

  • JavaScriptVM
  • Injected Web3
  • Web3 Provider

If deploying is successful, you can completely test your functions easily in the section below and monitor the operation of transactions with console log.

7. Practice a bit

Please visit the Remix homepage

This will be the interface when you enter

The left column will be the place to manage your files. There will be no folder creation, so if you create too many files it will look a bit small. Solidity is an object-oriented language, so you can implement the files into a file.

In the middle is the Code and console log section when running the functions

The right side includes a lot of functions but I will only mention the two most used parts are Compile and Run

When you’re on the Compile tab, you can select versions from old landmarks to the latest versions to compile.

There are options like Auto compile (no matter what fix or type in the way to compile), hide warning (Sometimes there are too many warnings to annoy you, even though the code is still running, please hide it by doing it) This feature), Enable Optimization

Below that you can select the Smart Contract you want to compile

Finally, the show log section when compile.

When on the Run tab, you can select the Smart Contract deployment environment types. I will use always 2 sample files of Remix to demo this part.

Selecting an environment is Injected Web3 to link to the electronic wallet at Metamask.

Because of Smart Contract deployments, it takes a little fee. So I will use the account at testnet Ropsten. You can claim ETH free for testing here ( https://faucet.metamask.io/ ). This is very important when you have to test Smart Contract before deploying on the mainnet. After you log in to Metamask the Remix website will automatically reload. At the bottom of the field, the accounts in Metamask e-wallet will appear.

Below is the section to select Smart Contract to deploy. When you click on the button deploy, you will need to create a transaction that requires Smart Contract to be deployed to the system. However, in the figure, beside the button deploy there is also a textinput section, because this Smart Contract sample requires entering arguments to initialize. You just enter any number. About the data types in solidity you can find it online to understand more. If successfully deployed, the interface will be as follows:

Below are the corresponding functions of Smart Contract. Functions that have a color button when done will require confirmation of the transaction and a fee. Functions with a light blue button will not create a transaction requiring confirmation. Can you make changes to the arguments to test whether the function function is okay?

This is a pretty good IDE for learning solidity programming and Smart Contract. However, when applying Smart Contract to applications with a slightly more complex interface, you must link the interactions between the sections: interface, Smart Contract, e-wallet.

Smart Contrac now offers many promises to help solve many problems in practice. What do you guys think about it?

Thank you everyone for reading your article.

Viblo

Share the news now

Source : Viblo