Instructions for creating and operating Smart contracts

In lesson 1, you learned how to use the Remixed IOE tool to program Smart Contracts in the Ethereum Blockchain. In this article, I will show you how to create your first Smart Contract and how to compile and deploy it.

If you want to change the world, you must first say hello to the world, so we create a workspace named “HelloWorld” as shown below: (Actually, we can’t change this world, when I was young I also wanted to change the world. change this and that, but since getting married and especially having a baby, I haven’t even had a chance to change my Youtube channel, let alone ask to change the world, I’m lucky to be able to change myself for the better) .
We name it as shown below and then click the OK button:
After clicking the OK button, we have the following results:
By default, Remix Ethereum IDE will create for you the folder structure and sample Contract files as above.

Now we create a .sol file (Contract written in Solidity programming language).
Named FirstSmartContract, it automatically generates the extension FirstSmartContract.sol:
Result after pressing Enter key:
Now we code as follows, Solidity code is similar to java, python…. Of course there are other points as it is specific to Smart Contracts. I will arrange time to write tutorial blogs about Solidity in the next posts to serve well for writing Smart Contract related projects.

In this post, just do as I wrote to give it a feeling first
The Contract code of FirstSmartContract above includes the balance property and the setBalance methods to change the balance’s value, and the getBalance method to retrieve the balance’s value.
When we write the wrong syntax, the program will automatically report an error, at this time we will not know how to translate, for example, I intentionally corrected it a little to make it error, you will see the following image:
Above there is no variable x2 but I still declare it, until it has an error with a red button. can’t compile at the moment.

See also  How to Support Synchronization in Ethereum Blockchain

OK, now you correct it so we can go to the compile step:
According to the image above, to compile we follow these steps:

1. Select Solidity compiler

2. Choose the latest compiler

3. Select the programming language as Solidity

4. Select Ethereum Virtual Machine (EVM), leave default

5. Click compile FirstSmartContract.sol

We see the result:
After successful compilation, we go to Deploy & Run transactions as shown below:
So you need to do the steps in the Deploy & run transactions section as follows:

1. Select Deploy & Run transactions

2. Select Enviroment as JavaScript VM (London). Here is a list of options

3. Select Ethereum Account, also many options

4. Select Gas limit

5. Select the Contract that you want to deploy, when compiling many contracts, it will display the list here

6. Press Deploy

After pressing Deploy we see the results:
When we click on the arrow to see the details, we have the following screen, the methods (transactions) are displayed for us to interact with:
For example, now we setBalance to 500000000, see the details of the operation:
Step 1: enter the value for the transaction setBalance

Step 2: press the setBalance button

Step 3: Details of the transaction performed, we can see

Next to check whether the setBalance transaction changes the value of balance, we test the getBalance transaction:
So here we have finished coding a Smart Contract as well as how to compile and deploy and run it.

Next article I will guide you to sync what you program on Remix Ethereum IDE to your local machine to store and maintain the code.

See also  How To Resolve "There Was a Problem Parsing the Package" Error on Android

Code FirstSmartContract.so download here:

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *