1. What is an Ethereum smart Contract?
    It is a small program that runs on the Ethereum blockchain.
  2. What makes an Ethereum smart contract so special compared to other programs?
    It cannot be stopped, hacked or modified.
  3. Can a smart contract interact with other smart contracts?
    Yes. A smart contract can call function of other smart contract.
  4. Can a Solidity smart contract call an API on the web?
    No. Oracle pattern can call function on the smart contract and feed the data and Solidity smart contract may make use of the data received. Smart contract function can be called always from outside to the smart contract and never other way around
  5. Can a solidity smart contract store a lots of data?
    No. Smart Contract storing data cost a gas. So directly storage data is limited.
  6. Can a smart contract be written in another language than Solidity?
    Yes. Viper, LLL, etc. But Solidity is very popular.
  7. Is Solidity a Dynamically or Statically typed language?
    Statically typed language that means variable types are required to mention. Other language like Java or python where variable do not require to mention type, language figures out the type. We have to be careful about the type of the variable because once the contract is deployed we cannot change, this way we reduce the chances of error.
  8. Is Solidity complied or interpreted?
    Complied. Before run the program it require to compile the program. Different than Java language. Java machine compile on the fly.
  9. What is the file extension of Solidity files?
    .sol
  10. Can a single Solidity file have several smart contracts?
    Yes. However it is better to have single contract in single file in order to mange code better.
  11. What is the typical layout of a Solidity smart contract?
    1. pragma statement for the version of the solidity
    2. contract statement and curly braces. Everything between the curly braces is the part of this contract.
    3. Define some variables.
    4. And functions to read and modify data.
      //pragma statement (required)
      pragma solidity ^0.5.9;
      // contract declaration (required)
      contract A{
      //state variables uint a;
      //functions function foo() {.....}
      }
  12. What is the difference between state and local variables?
    State variables are persisted on Blockchain after a smart contract finishes to execute. Whereas local variable live only during the execution of the function.
    contract A {
    // state variable uint a;
    //functions function foo() {
    uint b;
    //local variable
    }
    }
  13. What is the problem with the following code-1?
    contract Storage{
    uint data; //should update the 'data' storage variable above
    function set (uint _data) external{
    address data = _data;
    }
    }

    The set function redefine the data variable inside its body and this will create a local variable that shadow the state variable defined above.
    Remove the address keyword when you reference the data inside the set function.
  14. What is the problem with the following code-2?
    contract Storage{
    uint data; //Should update the 'data' storage variable above
    function set(uint data) external{
    //data = data?
    }
    }

    The data argument of the set function shadows the data state variable inside the set function. Because of this we can access the data inside the set function. To solve the problem we need to rename the argument from data to underscore data.
  15. What are the 2 variable visibilities for state variables in Solidity?
    private and public.
  16. Who can read private and public variables?
    private → can be read by only function inside the smart contract.
    public → anyone.
  17. What is the default visibility of state variables?
    private.
  18. Are private variables really private?
    No. Private variables are private only for EVM, Ethereum Virtual Machine, the part of the Ethereum that execute Smart Contracts. The data of the Smart Contract is put on the Ethereum Blockchain and all the data in this Blockchain is public.
    You can use a special tool to analyse blockchain data and you will be able to read any variables including private variable of the smart contract.
    Private variables are not really private but a little bit harder to read.
  19. How to deal with private data than?
    1. Do not put private data on blockchain
    2. use hashes
  20. Mention 3 data types that you use often, and explain why.
    uint → integer type mainly use for Ether and token transfer.
    address → it is used for identifying humans in smart contract.
    string → used for naming things.
  21. What are the 2 container types in Solidity?
    mapping and arrays
  22. How to declare an array of integer in Solidity?
    uint[] a;
  23. How to declare a mapping of address to booleans in Solidity?
    mapping(address => bool) a;

    In above example “address” is the key and “bool” is the value.
  24. How to declare a mapping of address to mapping of address of booleans (nested mapping)?
    mapping(address => mapping(address => bool)) a;
    In above example first key “address” and than we have second key “address” and value “bool”.
  25. How to add to an array declared as a state variable?
    by using “push” method.
    uint[] a;
    function add(uint newEntry) external{
    add.push(a);
    }
  26. How to add data to a mapping declared as a state variable?
    mapping(address => bool) a;
    function add(address addr) external {
    a[addr] = true;
    }
  27. How to loop through an array?
    uint[] a;
    for(uint i = 0; i < arr.length; i++){
    // do something with arr[]
    // reading:
    uint a = arr[i]
    // writing:
    arr[i] = a
    }
  28. What is the difference between a uint8 and a uint16?
    uint8 can store → 28-1
    uint16 can store → 216-1
  29. What are the 4 function visibilities in Solidity by increasing permissiveness?
    private → the function can be only be called from inside the same contract.
    internal → the function can be called from inside the same contract or another contract that inherit from it.
    external → the function can only be called from outside the smart contract.
    public → the function can be called from anywhere, from the function and outside the contract.
  30. How to conditionally throw an error, with an error message?
    require(a != b, "My error message")
    Use “require” statement.
    Specify the testing condition. If the testing condition fails than the second argument is the error message.
  31. What are the 2 artifacts produced by the Solidity complier when compiling a smart contract.
    abi
    bytecode
  32. What is the ABI of a smart contract?
    ABI is the define interface of a contract.
    That means, set of functions that can be called from outside the smart contract.
    It is used to interact with the smart contract.
    The idea is to use outside libraries like web3.js.
    The smart contract only defines function signatures i.e. function name, argument type and written types but it does not defines the implementation of function.
    ABI also defines events of the funciton.
  33. In the following contract, which function will be part of the ABI?
    contract A{
    function foo()
    external {....}
    function bar() public {....}
    function baz() internal {....}
    }

    foo and bar will part of ABI.
    baz can only be called from inside and inherited from it.
  34. Does the EVM understands Solidity?
    No, EVM under only byte code which must first be produced by the solidity outside the blockchain.
  35. What is the EVM bytecode?
    EVM byte code is a series of EVM elementary instruction called opcodes.
    These opcodes are very simple instruction like adding number, loading number from memory, etc.
    There are more than 100 opcodes defined in the Ethereum Yellow Paper.
    Coding using opcode will be very tedious so we need higher level language call Solidity for higher level of abstraction.
  36. What are the 2 APIs used to interact with a smart contract?
    eth_sendTransaction
    eth_call

    Transaction cost money and can modify the blockchain.
    Call does not cost money and cannot modify the blockchain.
  37. What is gas?
    Gas is an abstract unit to measure transaction cost.
  38. How is gas paid?
    Gas is paid in ether calculated from the following formula:
    ether cost = gasPrice * gas
    gasPrice is wai / gas generally represent in gwai.
    gas represent the gas cost during the execution of the transaction.
    A transaction also specify a gas limit parameter. Which specifies the maximum number of gas that can be paid by transaction. Without this a transaction can drain all the ether in the wallet.
  39. What happen if there is not enough gas in a transaction?
    Transaction will fail and all state changes will be revert.
  40. Who pays for gas in a transaction?
    The sender of the transaction.
  41. What is the most famous IDE for Solidity?
    Remix.
    Remix – Ethereum IDE
  42. List 2 famous smart contract framework for Solidity.
    • Truffle – most popular framework for developing Solidity smart contract. It allows easy deployment of smart contract to developer blockchain and interact with it.
    • OpenZeppelin – provide reference implementation for a lot of tokens standards like ERC20, ERC721. Before developing smart contract always check whether OpenZeppline have already implementation for the re-use.
  43. Which Javascript Ethereum client can we use to develop Solidity on a local blockchain?
    Ganache – Ganache is a CLI tool that can create a blockchain development on the local computer. It is not connected to any public Ethereum blockchain network.
    Everytime it start it start with fresh blockchain with no data on it.
    It comes with 10 preloaded Ethereum account that can be used to develop the smart contract. All ethers specified in it are fake.
  44. What do you need to deploy a smart contract to the Ethereum Network?
    • bytecode from the smart contract,
    • ethereum address,
    • enough ether to cover the transaction cost,
    • wallet to sign the transaction,
    • tool to create transaction, coordinate the signing of the transaction with wallet and sending the signed transaction to the ethereum blockchain network.
  45. List 4 famous Ethereum wallets
    1. Metamask
    2. MyEtherwallet
    3. Ledger
    4. Trezor
  46. List network where you can deploy a Solidity smart contract.
    • Mainnet – real Ethereum network
    • Ropsten – public test net use fake ethers.
    • Koven – public test net specific for Parity client.
  47. How to manage dates in Solidity?
    Solidity does not have native date type. It is managed by storing timestamp in second and uses uint variable.
  48. How to have the current timestamp in seconds?
    use built in ‘now’ variable.
  49. How to construct a timestamp of 1 day in the future?
    now + 86400 ( number of second in one day)
  50. What are the 2 ways to define custom data structure in solidity?
    • struct,
    • enum.