Ad

Tuesday, November 16, 2021

What is a Smart Contract? - Blockchain tech explained

 What's a smart contract? Chainlink explains it really well. Be sure to read our disclaimer before proceeding to read the tutorial.  Please always read our disclaimers and terms of service before reading our posts. 

"When deployed to a blockchain, a smart contract is a set of instructions that can be executed without intervention from third parties. The code of a smart contract determines how it responds to input, just like the code of any other computer program.

A valuable feature of smart contracts is that they can store and manage on-chain assets (like ETH or ERC20 tokens), just like you can with an Ethereum wallet. Because they have an on-chain address like a wallet, they can do everything any other address can. This opens the door for programming automated actions when receiving and transferring assets.

Smart contracts can connect to real-world market prices of assets to produce powerful applications. Being able to securely connect smart contracts with off-chain data and services is what makes them hybrid smart contracts. This is done with oracles, which we will discuss later in this tutorial."

The language for programming smart contracts is solidity. 

"Solidity is a statically-typed curly-braces programming language designed for developing smart contracts that run on Ethereum."  official doc. Inspired by other programming languages. .sol extension. solidity is for smart contract programming.

Ethereum virtual machine : where ethereum programs are run

Remix : online playground / editor for trying out and running solidity code in the browser.

^ to specify version greater than the one specified.

smart contracts are essential a bunch of codes that are to be executed.

kind of like a microservice, everyone can see it, and execute the code. Look like a class but more than a class.

An example of smart contract - Chainlink


In the screenshot above, you can see this smart contract has one variable, publicly accessible - message. When initiated, the message would have been set, and there's also a function to update that variable. 

The first pragma specifies the version of solidity. The main logic is enclosed in a class like contract HelloWorld{ ... }.

Smart contract vulnerability, loop hole, failure can cause severe losses, hacking of tokens, assets, exchanges and just about any dapps. We often hear genesis smart contract problems being exploited. This not a component of blockchain that you should be coding yourself, don't re-invent the wheel. Only use well tested, audited contracts written by experienced, top developers. This is not a component you will want to hack together. A reminder: please read our disclaimer and term of usage: to summarize our tutorials and posts are for informationaly purpose only. They are not for production use, not for commercial use. They have not gone through security review. They are just toy examples.

One interesting trivia about solidity contracts is that it does not allow decimals aka floating point numbers as a data type. 

Source https://docs.chain.link/docs/beginners-tutorial/

Smart contract, solidity, data types:

int defaults to int256


Disclaimer - WARNING: https://www.siliconvanity.com/2021/11/blockchain-crypto-stock-personal.html

No comments:

Post a Comment

Error Message Hardhat debugging error unsupported engine hardhat, current node v18

Error message npm WARN EBADENGINE  Unsupported engine { package: 'hardhat@2.9.3', required: { node: '^12.0.0 || 14.0.0 || 16.0.0...