How to Write and Deploy a Smart Contract Anastasia Lalamentik Full Stack Engineer @ Kaleido October 16, 2023
Table of Contents • Tools needed • How smart contracts work • Quick overview of Solidity • Build smart contract together • Deploy smart contract on an Ethereum test network • Interact with smart contract
Tools needed • Set up a Node development environment on your machine • You should be able to run node and npm commands from your Terminal • Hardhat - npm install --save-dev hardhat • MetaMask Wallet: Make sure you have some Sepolia Testnet ETH in your wallet. Use a Sepolia Faucet to fund your account. • Infura: Sign up for a free account and create a Sepolia network endpoint Full details in README found in https://github.com/lanasta/deploy-smart-contract/tree/ato2023 https://shorturl.at/chnM8
How smart contracts work • Runs in a blockchain network: decentralized, trustless, transparent, immutable • Self-execute when certain conditions are met, removes the need for a third-party (eg. centralized authorities like banks and intermediaries) • e.g. An artist no longer has to depend on record labels or distribution companies to receive royalties when someone buys their music. Percentage of shares coded in smart contract, cannot be tampered with. • Widely used in business management, legal processes, financial agreements, health systems • In enterprise use cases, a private blockchain would be of interest https://shorturl.at/chnM8
Smart contract concepts • Ethereum Virtual Machine(EVM): the execution environment for smart contracts in Ethereum. “World computer”, accessible to anyone around the world through participating Ethereum nodes. Each node runs a copy of the EVM. • Gas fees: required to compensate miners who use their computing power (usually referred to as running nodes in blockchain) to validate smart contracts, process and confirm transactions – variable based on traffic • Block explorer: A visualization tool that allows anyone to explore the state of a particular blockchain network and see information about blocks, transactions, balances, etc e.g. https://etherscan.io/ • Addresses: Each smart contract and each Ethereum account has an address that is represented by a 42-character hexadecimal address e.g. 0x92bc44d5318309EE2abF1539BF71dE1b7d7bE3b8 • Application Binary Interface(ABI): defines the methods and variables that are available to interact with in a smart contract https://shorturl.at/chnM8
https://shorturl.at/chnM8 Source: https://ethereum.org/en/developers/docs/smart-contrac ts/compiling/ What bytecode looks like Corresponding ABI for the Solidity code
https://shorturl.at/chnM8 Source: https://www.investopedia.com/terms/w/wei.asp Source: Etherscan.io transaction details Gas fees Source: Etherscan.io transaction details
https://shorturl.at/chnM8 Solidity Overview 1. Version pragma: solidity compiler version compatible with the code at the time of the development. Future versions may contain incompatible changes. 2. Contract keyword: the contract name follows after, encapsulates the smart contract logic 3. State variables: types include signed integers, unsigned integers, Boolean, addresses, enums, and bytes 4. Function declarations: can take in parameter, specify view or pure functions, return type and function visibility types – private, internal, external, or public. Source: https://www.tutorialspoint.com/solidity/solidity_quick_guide.htm Source: https://www.geeksforgeeks.org/introduction-to-solidity/
https://shorturl.at/chnM8 Solidity Global Variables Source: https://www.tutorialspoint.com/solidity/solidity_variables.htm
https://shorturl.at/chnM8 Other Solidity Features 1. struct: describes an object containing fields of different types 2. modifier: used to check pre-conditions for functions 3. event: logging capability enabling smart contracts to notify external applications of new events and changes on the blockchain
Let’s write and deploy a smart contract together!
Thank You /lanasta/deploy-smart-contract /in/anastasialalamentik anastasia.lalamentik@kaleido.io

How to Write & Deploy a Smart Contract

  • 1.
    How to Writeand Deploy a Smart Contract Anastasia Lalamentik Full Stack Engineer @ Kaleido October 16, 2023
  • 2.
    Table of Contents •Tools needed • How smart contracts work • Quick overview of Solidity • Build smart contract together • Deploy smart contract on an Ethereum test network • Interact with smart contract
  • 3.
    Tools needed • Setup a Node development environment on your machine • You should be able to run node and npm commands from your Terminal • Hardhat - npm install --save-dev hardhat • MetaMask Wallet: Make sure you have some Sepolia Testnet ETH in your wallet. Use a Sepolia Faucet to fund your account. • Infura: Sign up for a free account and create a Sepolia network endpoint Full details in README found in https://github.com/lanasta/deploy-smart-contract/tree/ato2023 https://shorturl.at/chnM8
  • 4.
    How smart contractswork • Runs in a blockchain network: decentralized, trustless, transparent, immutable • Self-execute when certain conditions are met, removes the need for a third-party (eg. centralized authorities like banks and intermediaries) • e.g. An artist no longer has to depend on record labels or distribution companies to receive royalties when someone buys their music. Percentage of shares coded in smart contract, cannot be tampered with. • Widely used in business management, legal processes, financial agreements, health systems • In enterprise use cases, a private blockchain would be of interest https://shorturl.at/chnM8
  • 5.
    Smart contract concepts •Ethereum Virtual Machine(EVM): the execution environment for smart contracts in Ethereum. “World computer”, accessible to anyone around the world through participating Ethereum nodes. Each node runs a copy of the EVM. • Gas fees: required to compensate miners who use their computing power (usually referred to as running nodes in blockchain) to validate smart contracts, process and confirm transactions – variable based on traffic • Block explorer: A visualization tool that allows anyone to explore the state of a particular blockchain network and see information about blocks, transactions, balances, etc e.g. https://etherscan.io/ • Addresses: Each smart contract and each Ethereum account has an address that is represented by a 42-character hexadecimal address e.g. 0x92bc44d5318309EE2abF1539BF71dE1b7d7bE3b8 • Application Binary Interface(ABI): defines the methods and variables that are available to interact with in a smart contract https://shorturl.at/chnM8
  • 6.
  • 7.
    https://shorturl.at/chnM8 Source: https://www.investopedia.com/terms/w/wei.asp Source: Etherscan.iotransaction details Gas fees Source: Etherscan.io transaction details
  • 8.
    https://shorturl.at/chnM8 Solidity Overview 1. Versionpragma: solidity compiler version compatible with the code at the time of the development. Future versions may contain incompatible changes. 2. Contract keyword: the contract name follows after, encapsulates the smart contract logic 3. State variables: types include signed integers, unsigned integers, Boolean, addresses, enums, and bytes 4. Function declarations: can take in parameter, specify view or pure functions, return type and function visibility types – private, internal, external, or public. Source: https://www.tutorialspoint.com/solidity/solidity_quick_guide.htm Source: https://www.geeksforgeeks.org/introduction-to-solidity/
  • 9.
    https://shorturl.at/chnM8 Solidity Global Variables Source:https://www.tutorialspoint.com/solidity/solidity_variables.htm
  • 10.
    https://shorturl.at/chnM8 Other Solidity Features 1.struct: describes an object containing fields of different types 2. modifier: used to check pre-conditions for functions 3. event: logging capability enabling smart contracts to notify external applications of new events and changes on the blockchain
  • 11.
    Let’s write anddeploy a smart contract together!
  • 12.