Smart contract Developer Jobs

Blockchain development thriving in bear market

image source — shuttlestock

I think, till now everyone developer on the earth has heard about the blockchain. It’s the current buzzword. Though the Blockchain industry still needs a lot of talent to produce mainstream products. Today we’ll talk about smart contract development. In my view, a developer’s entry point to the blockchain industry is Smart contract development. That’s how I got in.

What is a smart contract?

Ok, So you understand the contract, correct? An agreement between two or more parties. The condition of the agreement has to be followed by all parties, But what if this thing is enforced by the code. Let’s take an example, Alice agrees to buy a car from Bob on this Christmas. There are below conditions.

  1.  Alice will pay upfront 3% of the total car value. 
  2. Alice has to pay bob remaining 97% before the Christmas day to get the ownership.
  3.  In case, Alice is not able to buy the car, Bob will keep that 3% upfront payment.
  4.  In case, Alice will pay full payment, Car ownership will be transferred to Alice. (Let’s assume car ownership can be acquired by a password)

In a normal world, Alice and Bob will be transacting through cash or online banking payments and agreement will have some intermediate party to enforce the rules of agreement. But in the blockchain world. This can be done automatically. We have a smart contract and let’s see how it works.

  1. Bob and Alice decide the car’s total worth and put in the smart contract.
  2.  Alice deposit 3% of the car’s total worth in the smart contract.
  3.  Bob stores the car’s password in the smart contract.
  4.  Now if Alice transfer the remaining 97% of the car’s total worth before Christmas, Smart contract will transfer the total amount to Bob and car’s password to Alice.
  5.  In case if Alice were unable to transfer the remaining 97% smart contract will transfer the 3% upfront payment to Bob and destroy the password.

So here a smart contract is working as an intermediary. Isn’t this cool? and this was a very simple example, we can do limitless things with the smart contracts. Think of a smart contract network talking to each other and settling things.

How to start with smart contract development?

You can choose any smart contract development platform but ethereum is one of good to start with. Though you need to learn Solidity, it’s not difficult. believe me. I am attaching a few articles which will help you get started with the ethereum smart contract.

Introduction to Solidity Programming and Smart Contracts (For Complete Beginners)

Top Solidity Tutorials

You can find more Solidity articles here. 

Why become a smart contract developer?

The blockchain is growing industry but we are nowhere near producing scalable systems right now. Though tools are getting developed and in future we will have scalable decentralize systems. Blockchain industry needs an army of developers to build tools on it. There is a lot of benefits to learning smart contract development.

1- Lack of good smart contract developers with the understanding of decentralize philosophy.
2- Remote jobs / Freelancing 
3- Developing your own project.

Smart contract Jobs Growth

A quick search on AngelList shows that more than 500+ companies hiring smart contract developers and more than 1500+ companies hiring in Blockchain overall. Other than that all the ICO’s you saw last year were developed using smart contracts. Thousands of Dapps are getting developed using smart contracts.

More than 200+ tokens are getting created every day on the ethereum network. 

How many smart contracts get created on ethereum every day? 

There are thousands of smart contracts are getting created on ethereum main net every day. 

source — bloxy.info

How many smart contracts get used monthly?

Last month more than 1.5 million smart contracts got used. Most of them are a general purpose smart contracts. In the bear market, smart contract development is growing.

Image source —bloxy.info 

We just talked about the ethereum network. There are other networks like EOS, Tezos and stellar on which you can build smart contracts too. 

Blockchain Job Interview Questions

Blockchain Jobs

Now Let’s deep dive into questions.

Attribution – This article is written by Chirag Maliwal. You can say hello to him here.

Q: What is the difference between Wei and Ether?
A: Wei is a denomination, like cents to Dollars or pennies to Pounds. 1 ETH = ¹⁰¹⁸ Wei

Q: What is the average block time in Ethereum?
A: ~14 seconds view more on https://etherscan.io/chart/blocktime

Q: What is the average block size in Ethereum?
A: Around 2KB, although it depends. Ethereum has a gas limit rather than a block size. The gas limit is a cap on both processing and storage/bandwidth because the cost of a transaction/function is fixed in units of gas for each type of instruction.

The gas limit is voted up or down by each miner and each miner determines what gas price it is willing to accept which is like bitcoin transaction fees but on a per gas basis rather than a per transaction basis.

To figure out how many transactions can fit in a block you don’t need to know what the price of gas is. You just need to know how much gas a transaction uses and divide the gas limit by that.

If the network receives a load of spam transactions that start filling up blocks then miners have 2 choices. They can vote up the gas limit to fit in more transactions or they can start increasing the gas price and reject transactions that pay too low a fee. Like with bitcoin a transaction with a low fee might still get through but it would have to wait until a miner that accepts a lower fee (lower gas price) is willing to let it in.

With a sustained spam attack, it would just get progressively more costly to do transactions until either the spammer runs out of money or the miners make so much money that they start expanding the network capacity

Q: How was the Premine of ETH?
A: 60 million were first created in a presale in 2014. Also, ethers are created when a block is mined.

Q: What is a node?
A: A node is essentially a computer, connected to the network, which processes transactions.

Q: How many Ethereum networks are you familiar with?
A: There are three types of network — Live Network (Main), Test Network (like Ropsten and Rinkeby) and Private Network.

Q: What are some ways to interact with a network?
A: You can either use a Wallet or a DApp

Q: Can you “hide” a transaction?
A: No. All transactions are visible to everyone.

Q: Where are transactions recorded?
A: In the public ledger.

Q: Why would you have a private network?
A: There are many reasons, but mainly because of data privacy, distributed database, permissions control and testing.

Q: How can you easily see details about transactions and blocks?
A: Using blockchain explorers like etherscan.io or live.ether.camp

Q: What about private network?
A: You can do it using open source explorer clients (like https://github.com/etherparty/explorer)

Q: What is consensus in blockchain?
A: The process of validating transactions (creating blocks) following a specific protocol (like Ethereum).

Q: How mining in Ethereum works ?
A: How mining works

Today, ethereum’s mining process is almost the same as bitcoin’s.

For each block of transactions, miners use computers to repeatedly and very quickly guess answers to a puzzle until one of them wins.

More specifically, the miners will run the block’s unique header metadata (including timestamp and software version) through a hash function (which will return a fixed-length, scrambled string of numbers and letters that looks random), only changing the ‘nonce value’, which impacts the resulting hash value.

If the miner finds a hash that matches the current target, the miner will be awarded ether and broadcast the block across the network for each node to validate and add to their own copy of the ledger. If miner B finds the hash, miner A will stop work on the current block and repeat the process for the next block.

It’s difficult for miners to cheat at this game. There’s no way to fake this work and come away with the correct puzzle answer. That’s why the puzzle-solving method is called ‘proof-of-work’.

On the other hand, it takes almost no time for others to verify that the hash value is correct, which is exactly what each node does.

Approximately every 12–15 seconds, a miner finds a block. If miners start to solve the puzzles more quickly or slowly than this, the algorithm automatically readjusts the difficulty of the problem so that miners spring back to roughly the 12-second solution time.

The miners randomly earn these ether, and their profitability depends on luck and the amount of computing power they devote to it.

The specific proof-of-work algorithm that ethereum uses is called ‘ethash’, designed to require more memory to make it harder to mine using expensive ASICs — specialized mining chips that are now the only profitable way of mining bitcoin.

In a sense, ethash might have succeeded in that purpose, since dedicated ASICs aren’t available to mine ethereum (at least not yet).

Furthermore, since ethereum aims to transition from proof-of-work mining to ‘proof of stake’ — which we discuss below — buying an ASIC might not be a smart option since it likely won’t prove useful for long.

Q: What are the two commonly used consensus models in blockchain?
A: Proof of work and proof of stake. . Proof-Of-Activity :

Q: Explain proof of stake in a simple way.
A: The creator of the block is chosen randomly by means of wealth and age (stake). It is not computationally intensive.

Q: What consensus model does Ethereum use?
A: As of the beginning of 2018 it uses Proof of work but it is going to switch to Proof of stake.

In Proof-Of-Activity, an alternative incentive structure introduced in bitcoins which is the hybrid structure that combines both Proof-Of-Work and Proof-Of-Stake. To avoid hyperinflation we have to stop the mining incentives because there are no more coins left in the system. Only limited number of coins are present in some system like bitcoins. In proof-of-activity, before all the coins used Proof-Of-Work in the picture and as soon as coins finish Proof-Of-Stake start working in which fees are divided between miner and validators who signed off the block.

Q: What is used to sign transactions?
A: User’s private key.

Q: Can you recover your Ethereum account after losing your private key?
A: Yes, you can use your 12 word mnemonic.

Q: What are some ways to connect to a node?
A: IPC-RPC, JSON-RPC and WS-RPC.

Q: So what is Geth?
A: Geth is an Ethereum cli client.

Q: What is the default way of connecting to a geth client?
A: IPC-RPC is enabled by default, every other RPC is disabled.

Q: What geth APIs are you aware of?
A: Admin, eth, web3, miner, net, personal, shh, debug and txpool.

Q: Which RPCs can you use to connect to a geth client over the network?
A: You can connet to a geth client over the network using JSON-RPC and WS-RPC. IPC-RPC can only connect to geth clients on the same machine.

Q: If you pass option — rpc which RPC gets enabled?
A: JSON-RPC.

Q: Which RPC APIs are enabled by default?
A: eth, web3 and net.

Q: How would you enable admin api for JSON RPC?
A: By using the option — rpcapi

Q: What does the option — datadir do?
A: It specifies where the blockchain will be stored.

Q: What is geth’s “fast” sync, and why is it faster?
A: Instead of processing the entire blockchain one link at a time and replay all transactions that ever happened, fast sync downloads transaction receipts along with the blocks and pulls an entire recent state database.

Q: What does — testnet do?
A: It connects the client to Ropsten network.

Q: Starting the geth client dumps a lot of output on the screen. How would you reduce the noise?
A: By setting — verbosity to a lower number (default is 3)

Q: How can you connect one geth client to another using IPC-RPC?
A: First start a geth client, copy its pipe location, then start another geth client using the same datadir and passing — attach with the pipe location.

Q: How would you load custom javascript files into your geth console?
A: By passing — preload and the path of the file.

Q: Where are geth client accounts stored?
A: In the keystore directory.

Q: What do you have to do with an account in order to make transactions?
A: You have to unlock that account with — unlock by passing the account address or index. You can also specify a — password file where all passwords reside for each account.

Q: You mentioned something about indexes. What determines the account index?
A: The order in which you add the accounts.

Q: Is it possible to mine using geth?
A: Yes, by passing — mine option.

Q: What is “etherbase”?
A: This is the account which receives the mining awards, which is account with index 0.

Smart Contracts and Solidity

Q: What is ABI ?
A:

“ABI” as an “API” at a low level.

The ABI, Application Binary Interface, is basically how you call functions in a contract and get data back.

An ABI determines such details as how functions are called and in which binary format information should be passed from one program component to the next…

An Ethereum smart contract is bytecode deployed on the Ethereum blockchain. There could be several functions in a contract. An ABI is necessary so that you can specify which function in the contract to invoke, as well as get a guarantee that the function will return data in the format you are expecting.

From Ethereum’s ABI specification, an example:

contract Foo {
  function bar(real[2] xy) {}
  function baz(uint32 x, bool y) returns (bool r) { r = x > 32 || y; }
  function sam(bytes name, bool z, uint[] data) {}
}

If we wanted to call baz with the parameters 69 and true, we would pass 68 bytes in total, which can be broken down into:

0xcdcd77c0: the Method ID. This is derived as the first 4 bytes of the Keccak-256 hash of the ASCII form of the signature baz(uint32,bool). 0x0000000000000000000000000000000000000000000000000000000000000045: the first parameter, a uint32 value 69 padded to 32 bytes 0x0000000000000000000000000000000000000000000000000000000000000001: the second parameter — boolean true, padded to 32 bytes

The 68 bytes is what would be specified in the data field of a transaction: a security note on that is here. (To summarise, be careful what you put in the data field, because it can have unintended, possibly malicious side-effects when passing it to the calling contract.)

To avoid a common pitfall when deriving the Method ID, the canonical types must be used, for example uint256 instead of uint.

Here is an example in Solidity of computing a Method ID for sam above:

bytes4(sha3("sam(bytes,bool,uint256[])")

Using a higher-level library such as web3.js abstracts most of these details, but the ABI in JSON format still needs to be provided to web3.js.

Note: the ABI is an abstraction that is not part of the core Ethereum protocol. Anyone can define their own ABI for their contracts, and any callers of such contracts would have to comply with that ABI to get meaningful results. However, it is simpler for all developers to use Solidity, Serpent, and web3.js which all comply with the ABI above.

Q: So what is a Smart Contract?
A: It is computer code written in multiple languages. Smart contracts live on the network. They enforce rules and perform actions, negotiated by participants in those contracts.

Q: What languages can Smart Contracts be written in?
A: Solidity, which is the most commonly used language, Serpent and Lisp Like Language

Q: Example of a Smart Contract use case?
A: A popular Seller-Buyer scenario where a Buyer deposits money in the smart contracts, Seller sees the deposit and sends the goods, Buyer receives the goods and releases the payment.

Q: What is Metamask?
A: Metamask is a tool which helps you to easily interact with the Ethereum networks in your browser

Q: What node does Metamask use?
A: It uses infura.io

Q: What does Metamask NOT support?
A: Mining and contract deployment.

Q: Is execution of contracts free?
A: No, invoking contract methods is a transaction.

Q: Is accessing a Smart Contract state free?
A: Yes, querying state is not a transaction.

Q: Who executes the contracts?
A: Miners.

Q: Why does it cost money to invoke a method on a Smart Contract?
A: Some methods, which do not modify the state of the contract and have no logic other than returning a value, are free.
Apart from sending ether as a payment, invoking methods that make change the state cost money also because they require gas for execution.

Q: Why is there gas, more precisely?
A: Since miners execute contract code on their machines, they must cover their costs from executing the code requested by a caller.

Q: Does gas price determine when a transaction is processed?
A: Yes and no. The higher the gas price, the more likely your transaction will be mined. Despite, gas price is not a guarantee for faster transaction processing.

Q: What does the gas usage in a transaction depend on?
A: It depends on amount of storage, and type and number of instructions (opt codes). Each EVM opt code has a fixed amount of gas.

Q: And how is transaction fee calculated?
A: Gas used * gas price (specified by the caller)

Q: If an execution of a Smart Contract costs less than the specified gas, does the user get a refund?
A: Yes

Q: What happens if the execution of a Smart Contract costs more than the specified gas?
A: The user doesn’t get a refund and also the execution halts as soon as all the gas is used up and no changes are made to the contract.

Q: Who pays for Smart Contracts invocation?
A: The user who invokes the contract.

Q: What do nodes run Smart Contracts code on?
A: EVM — Ethereum Virtual Machine. EVM follows the EVM specification, which is part of the Ethereum protocol. EVM is simply a process on the node.

Q: What does the EVM need in order to run a Smart Contract?
A: It needs the contract’s bytecode which is generated from compiling a higher-level language such as Solidity.

Q: What are the segments of EVM on a higher level?
A: Memory area, Stacks and Execution engine.

Q: What is Remix?
A: An online tool for developing, testing and deloying contracts. It’s great for quickly building and testing lightweight contracts but not for more complex ones.

Q: In Remix, what nodes can you connect to?
A: You can connect to a public node using Metamask, local node using Geth and simulated memory node in the Javascript VM.

Q: What is a DApp and why is it different than a normal App?
A: An App usually consists of a client which communicates to some centralized resources (owned by an organization).
There is a mid-tier connecting to a centralized data tier. If information in the centralized data tier is lost, it cannot be recovered (easily).
DApp means Decentralized Application. DApps interact with the network via Smart Contracts. The data they work with resides in the contract instance.
Centralized data can be compromised more easily than decentralized.

Solidity

Q: Is Solidity statically or dynamically typed?
A: It is statically typed, which means that types are known at compilation.

Q: What is the equivalent to the Java “Class” in Solidity?
A: It’s the Contract.

Q: What is an instance of a contract?
A: An instance of a contract is the deployed contract on the blockchain.

Q: Give me a couple of differences between Java and Solidity.
A: Solidity supports multiple inheritance but doesn’t support overloading

Q: What is the very first thing you must specify in a Solidity file?
A: The version of Solidity compiler, which is specified as ^0.4.8. It is necessary because it prevents incompatibility errors which can be introduced when compiling with another version.

Q: What does a contract consist of?
A: It consists mainly of storage variables, functions and events.

Q: What types of functions are there?
A: There is a constructor, fallback function, constant functions and functions that modify the contract state.

Q: What error will I get if I put multiple contract definitions into a single Solidity file?
A: It is perfectly fine to put multiple contract definitions into a single Solidity file.

Q: What are some ways in which two contracts can interact?
A: A contract can invoke, create and inherit from another contract(s).

Q: What happens when you try to deploy a file with multiple contracts?
A: The compiler only deploys the last contract in that file and all other contracts are ignored.

Q: What if I have a huge project, do I need to keep all my related contracts into a single file?
A: You can use import statement to import a file,

import “./MyOtherContracts.sol”;

Q: Can I only import local files?
A: You can also import files using HTTP (even from Github),

import “http://github.com/<owner>/<repo>/<path to the file>”

Q: What parts is the memory of an EVM divided into?
A: It is divided into Storage, Memory and Calldata

Q: Explain Storage
A: Think of it as a database. Each contract manages its own Storage variables. It is a key-value datastore (256 bit key & value). The read and write are more costly in terms of gas used per execution.

Q: Explain Memory
A: It is a temporary storage. The data is lost once the execution terminates. You can allocate complex datatypes like arrays and structs.

Q: Explain Calldata
A: It can be thought of as the callstack. It is temporary, non-modifiable, and it stores EVM execution data.

Q: What variables are stored in the Storage and Memory areas respectively?
A: State variables and local variables (which are references to the state variables) are stored in Storage. Function arguments are located in Memory area.

Q: Take a look at the following code and explain which part of the code corresponds to which memory area:

A:
Part 1 — Storage.
Part 2 — Storage (array size points to the same location as counter)
Part 3 — Memory.
Part 4 — Reference to Storage.

Q: Can I do this:

function doSomething(uint[] storage args) internal returns(uint[] storage data) {…}

A: Yes, you can force the arguments of a function to be of type storage. In this case if you do not pass a storage reference, the compiler will complain.

What’s the difference between EVM and non-EVM calls?

  • EVM calls are smart contract method calls which trigger method execution and requires GAS.
  • non-EVM calls are reading values public values. No need to GAS.

How do you set a limit on the ether balance of a contract and what happens when you try to send more ether to the limited contract?

How can you set the value of msg.val in a contract acct and not an external acct? msg.val => msg.value = number of wei sent with the message

DApps and web3

Q: What is a DApp ?
A: Decentralized applications (dApps) are applications that run on a P2P network of computers rather than a single computer. dApps, have existed since the advent of P2P networks. They are a type of software program designed to exist on the Internet in a way that is not controlled by any single entity.

  • Decentralized applications don’t necessarily need to run on top of a blockchain network. BitTorrent, Popcorn Time, BitMessage, Tor, are all traditional dApps that run on a P2P network, but not on a Blockchain (which is a specific kind of P2P network).
  • As opposed to simple smart contracts, in the classic sense of Bitcoin, that sends money from A to B, dApps have an unlimited number of participants on all sides of the market.

Q: How DApps are different from Smart Contracts ?
A:
dApps are a ‘blockchain enabled’ website, where the Smart Contract is what allows it to connect to the blockchain. The easiest way to understand this is to understand how traditional websites operate.

  • The traditional web application uses HTML, CSS and Javascript to render a page. It will also need to grab details from a database utilizing an API. When you go onto Facebook, the page will call an API to grab your personal data and display them on the page. Traditional websites: Front End → API → Database
  • dApps are similar to a conventional web application. The front end uses the exact same technology to render the page. The one critical difference is that instead of an API connecting to a Database, you have a Smart Contract connecting to a blockchain. dApp enabled website: Front End → Smart Contract → Blockchain

As opposed to traditional, centralized applications, where the backend code is running on centralized servers, dApps have their backend code running on a decentralized P2P network. Decentralized applications consist of the whole package, from backend to frontend. The smart contract is only one part of the dApp:

  • Frontend (what you can see), and
  • Backend (the logic in the background).

A smart contract, on the other hand, consists only of the backend, and often only a small part of the whole dApp. That means if you want to create a decentralized application on a smart contract system, you have to combine several smart contracts and rely on 3rd party systems for the front-end.

Q: What does the front end use in order to connect to the backend (Smart Contracts)?
A: Web3 API libraries.

Q: Give some examples of DApps

A: Golem. The Golem project aims to create the first global market for idle computer power. Augur. Augur aims to combine the concept of prediction markets with the power of decentralised network to create a forecasting tool, for potential trading gains. Aragon Network aims to act as a digital jurisdiction that is extremely convenient for everyone to operate on.

Q: What do you need in order to interact with a contract from a DApp?
A: The contract’s ABI and bytecode.

Q: What is the ABI used for?
A: ABI is a description of the public interface of a contract, which is used by DApps for invoking the contract.

Q: What is the bytecode used for?
A: The EVM on each node requires bytecode in order to execute the contract code.

Q: Why would you use BigNumber library?
A: Because Javascript does not handle big numbers correctly.

Q: Why is it necessary to always check if the web3 provider is set in the beginning of your web DApp code?
A: Because Metamask injects it and overwrites the any other web3 with its own.

Q: Why would you use version web3 js 1.x instead of 0.2x.x?
A: Mainly because its async calls use promises instead of callbacks, which is preferred in the javascript world.

Q: How to list accounts in web3 1.x?
A: web3.eth.getAccounts

Q: What is the difference between .call and .send?
A: .send sends a transaction and costs moeny while .call queries the state of the contract.

Q: Is sending one ether like this “.send({ value: 1 })” okay?
A: No, you send 1 wei. Transactions always work with wei.

Q: So in order to send 1 ether I have to mutiply the value by ¹⁰¹⁸?
A: You can use the util method web3.utils.toWei(1, ‘ether’)

Q: What do I have to specify when calling “.send()”?
A: You must specify “from” which is the sender address. Everything else is optional.

Q: The only function of web3.eth.sendTransaction() is to send ethers to a specific address, is that correct?
A: No, you can also invoke contract methods.

Q: Do you know any solutions for scalability in Ethereum?
A: 2-layer protocols. Possible solutions are state channels and plasma.

“All the best”