Skip to content

Instantly share code, notes, and snippets.

@jatinshah
Last active August 26, 2023 11:15
Show Gist options
  • Select an option

  • Save jatinshah/57c2ffc332f6b53369eb0a5431c0f12e to your computer and use it in GitHub Desktop.

Select an option

Save jatinshah/57c2ffc332f6b53369eb0a5431c0f12e to your computer and use it in GitHub Desktop.
Blockchain Engineer - Interview Questions
  • Write a smart contract with semantics defined below, deploy it to Ethereum Ropsten testnet. Please share contract address and include verified code on Etherscan
contract SimpleToken {
    // Create a new token, with default price of 0.01 ETH
    // Token ids can start with zero and auto increment
    // Current owner is 0x0
    // Returns token id
    function mint() public returns (uint256);
    
    // Getter & Setter functions for price
    function getTokenPrice(uint256 _tokenId) public view returns (uint256);
    function setTokenPrice(uint256 _tokenId, uint256 _price) public;
    
    function exists(uint256 _tokenId) public view returns (bool);

    // Purchase token at the current price
    function purchase(uint256 _tokenId) public payable;
    
}
  • Identify the bugs in the following smart contract.
contract Bank {
    // We want an owner that is allowed to selfdestruct.
    address owner;
    mapping (address => uint) balances;
   
    // Constructor
    function Bank(){
        owner = msg.sender;
    }

    // This will take the value of the transaction and add to the senders account.
    function deposit() public {
        balances[msg.sender] += msg.value;
    }

    // Attempt to withdraw the given 'amount' of Ether from the account.
    function withdraw(uint amount) public {
        msg.sender.send(amount);
        balances[msg.sender] -= amount;
    }

    function remove() public {
        selfdestruct(owner);

    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment