#Binance #crypto2023 #smartcontracts #BTC #ETH What can smart contracts do?
Suppose we bet on the weather conditions for tomorrow. I bet it will be sunny tomorrow, and you bet it will be rainy. We agreed that the loser must give the winner Ā£100 pounds. So how do we ensure that the loser will keep the promise? There are three common ways:
1. Mutual trust
The easiest way is to trust each other. If we have been friends for many years and know each other well, it is easy to trust each other. But if we are strangers, it will be troublesome. It is difficult for us to trust each other.
2. Sign a legal agreement
Another way is to sign an agreement for our bets. It specifies the terms of the bet in detail, including what happens if the losing party violates the agreement.
The agreement can ensure that the losing party pays the winner, but this is unrealistic because reaching an agreement through legal means is more costly than a bet.
3. Seek help from mutual friends
We can also find a friend who trusts each other and let the friend take care of Ā£100 pounds. Pay Ā£100 pounds to the winner when the answer is revealed. But what if this friend ran away with the money?
Now we have three different methods, but each has its shortcomings. It is difficult for strangers to trust each other. Legal agreements are expensive and friends might not fully trust each other.
At this time, Ethereum's smart contracts come in handy. Smart contracts are equivalent to mutual friends of both parties, and they are written in code. Ethereum allows us to write software that allows both parties to pay Ā£100 worth of ether, check the weather with the weather API the next day, and then transfer Ā£200 worth of ether to the winner. Once the smart contract is written, it cannot be edited or modified. Therefore, no matter what is specified in the contract, it will be executed.
Simply put smart contracts are a computer program or transaction on a decentralized platform.
But how is the smart contract executed? What does it have to do with the blockchain?
What is the relationship between smart contracts and blockchain
When executing a smart contract, it records the execution information on the block as a transaction. Transactions on Ethereum are like this: Among them, "data" is used to record the creation and execution of smart contracts, which are called transactions. Any block on the Ethereum blockchain can contain the following three types of transactions:
1. Ether transactions between users
This is a regular Bitcoin-style transaction within the network. If you send Ether to your friend, the data field will be cleared.
2. Ether transaction with no receiver
If there is no receiver in the transaction, it means that the purpose of the transaction is to create a smart contract in the network using the content of the "data" field. The software code contained in the "data" field will be consistent with other users in the network
3. Ether transaction between user and smart contract
When a user or a smart contract wants to execute a smart contract, they must trade with the smart contract and place the execution instruction in the data field.
Just like other blockchains, as long as any of the above transactions are sent, they will be broadcast to the entire network, allowing each node to record. In addition, each node will also execute the indicated smart contract to keep its EVM state in sync with the network.
Each execution will be permanently stored in the blockchain.
What is Gas fees?
As mentioned above, users must pay a certain fee when executing smart contracts. This part of the cost will be paid to the nodes that consume memory, electricity, storage, and calculations, and the unit of cost is called gas. Finally, the gas is converted into Ether according to the exchange rate.
When you execute a smart contract, you must define the maximum amount of gas to be consumed. When the execution is complete or the gas value is reached, the execution will stop. This is to avoid the infinite loop in the smart contract and prevent the program from being stuck and unable to continue execution.
Conclusion
Ethereum is not just a tradable cryptocurrency, its true value lies in its purpose, and the scalability, however there are other cryptocurrencies such as Bitcoin, Ravencoin or Alephium which promise to be more efficient. However that is to be determined.