What is a smart contract?
A smart contract is a computer program that automatically executes tasks when specified conditions are met.
A smart contract is a computer program that automatically executes tasks when specified conditions are met.
Smart contracts:
enable the automation of digital assets,
enable trustless, transparent & verifiable transactions,
streamline processes,
reduce the need for intermediaries and their associated costs.
Smart contracts can be used for:
financial transactions,
supply chain management,
digital identity,
legal agreements.
The most important smart contract languages are Solidity, Vyper, Cairo, and Rust.
Ethereum is the most widely used smart contract blockchain.
Code for a basic smart contract
Here's the code for a very basic smart contract called "HelloWorld".
It has one string variable called "message" which is public and can be accessed by anyone.
The contract has a constructor and an "updateMessage" function.
The constructor function executes automatically when the contract is first deployed. In this case, it sets the initial value of the "message" variable to "Hello, World!".
The "updateMessage" function allows anyone to change the value of the "message" variable. It takes in a single input, "newMessage", which is the new value that the message variable should be set to.
This contract can be deployed on Ethereum. Other contracts & external accounts can interact with it via function calls.