Let’s Understand Smart Contracts in Blockchain

And maybe build one…

Structure of a Smart Contract in Solidity.

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
Contract myFirstContract {    // Your code here}

Sample Contract

//SPDX-License-Identifier: MITpragma solidity ^0.8.0;contract depositPool {   // Mapping to keep track of total amount for each user   mapping(address => uint256) public userToAmount;   function deposit() public payable {       //transfer balance to contract        updateBalanceRecord(msg.value, msg.sender);        }    function updateBalanceRecord(uint256 _amount, address _user) internal {        userToAmount[_user] += _amount;        }    function checkContractBalance() view public returns(uint256) {        //returns the total balance held by the contract        return address(this).balance;    }}

Conclusion

--

--

A social networking platform that turns creators into entrepreneurs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Moosa Ali

Blogger | Data Scientist | Machine Learning Engineer. For more content, visit: www.writersbyte.com. Support me on: ko-fi.com/moosaali9906