Blockchain: Developing Smart Contracts Using Standards and Open Source Libraries

0
918
Blockchain

Though the blockchain is very popular these days, there is a significant gap in the way it works and how most of us understand it. Most of its resources such as smart contracts are still a work in progress. Let’s talk a bit more about them.

Bitcoin and Ethereum are the two most popular cryptocurrencies today, with the latter being more developer-friendly. A program that runs on the Ethereum blockchain as a collection of code (its functions or rules) and data (its state) that resides at a specific address on this blockchain is a smart contract. A developer would need to learn how to code in smart contract language and have enough ETH (Ethereum currency) to pay as Gas fees (call it cost of doing business or initiating a transaction) for deployment of the contract.

In simpler terms, a smart contract can be considered as an open API that can call other APIs. A chain of smart contracts can make a serious business transaction. In the long run, the number of libraries is going to increase and development of smart contracts is going to be much easier and more efficient, targeted at replacing highly skilled professions such as lawyers or government contract agencies that focus on governance through compliance.

Development environments
Blockchain is an ever-evolving field, and there is no definitive approach or set pattern for the development of smart contracts. However, there are a few open source tools that have proved to be effective as development environments like Truffle, Embark and Builder. These tools efficiently handle compilation, deployment, debugging and upgradation of contracts with the sophistication of running unit tests.

Development of smart contracts requires a set of tools, most of which are available in open source. With trial-and-error, the appropriate environment for the development of smart contracts can be established. The good news is that there is quite a bit of information available on the Web for how to go about doing this. Also, the technology has been in the works for more than five years, bringing in some stability in the tools with enthusiastic developer forums putting in troubleshooting efforts.

Standards
The Ethereum community has defined multiple standards in the form of ERCs (Ethereum requests for comments). This is a document used by smart contract programmers to refer to the rules Ethereum based tokens must comply with. There is a thriving community of developers, enthusiasts and organisations across the globe working to standardise the use of Ethereum. Requests for Ethereum improvement proposal (EIP) are maintained on GitHub. At the time of writing this article, there are nearly 5000 requests suggesting the increased adoption and agility in this space. Of these, 267 have been finalised and the rest are in various stages of approval.

EIPs are of various types such as standard track, core, networking, interface, ERC, meta and informational.

The significant number of proposals and rapid finalisation workflow indicate a thriving community working towards standardising the interactions in blockchain (at least in the Ethereum world), thus building the momentum for developing standard libraries across routine functions.

Table 1: Top 10 Ethereum standards

EIP Description Use
20 Fungible token standard
  • Implementation of standard API within a smart contract
  • Standard protocol for issue and integration of tokens across smart contracts and wallets
165 Standard for method, instead of tokens
  • States how any contract can publish the interface after the implementation
  • States how to detect and track usage when a contract implements this standard
721 Non-fungible token (NFT) standard
  • Implementation of standard API for NFTs within a smart contract
  • Offers functionality to transfer and track NFTs
777 Increase efficiency in crypto transactions
  • Eliminates double transaction verification by lowering transaction overhead
  • Configures to reject incoming tokens from blacklisted address
778 Ethereum node records
  • Defines open format for p2p2 connectivity
1155 Multi-token standard
  • Creates multiple tokens in a single contract across fungible and non-fungible use
  • Resolves issues of ERC-20 and ERC0721
1363 Payable token
  • Eases token payment for transaction payment
  • Allows transfer or approval in single transaction
2767 Contract ownership governance
  • Contracts that hold administrative ownership of other smart contracts with voting power distributed
3448* Meta proxy standard
  • Standardises users and third party tools to discover contract redirect routes in a known path with immutable metadata
4626 Tokenized vault standard
  • An extension of the ERC-20 token, providing functionality for reading balance, depositing and withdrawing tokens with standard API for tokenised vaults

*EIPs are in various review stages

Smart contract libraries
Smart contract libraries are nothing but contracts. However, their purpose is to be deployed once at a specific address and then be reused for delegating routine tasks, so that the calling functions can execute as if this is their own code as part of the contract.

There are two kinds of smart contract libraries — reusable behaviours that one can add to contracts, and implementations of various standards.

Common routine coding patterns include exception handling or managing unexpected issues. Smart contract libraries usually provide reusable implementation of the behaviours as libraries or via inheritance in Solidity (a language in which smart contracts can be developed).

A developer’s environment of open source tools for smart contract development
Figure 1: A developer’s environment of open source tools for smart contract development

Open Zeppelin contract library is a GitHub project dedicated to secure smart contract development with a role based permissioning scheme for the development and use of reusable Solidity components. This is a very popular forum used in building complex decentralised systems. An innovative and interactive ‘Contracts Wizard’ approach is available to get started with generating smart contracts. The contracts support stable APIs, ensuring unexpected upgrade related issues are addressed efficiently.

Dappsys is another popular collection of smart contracts building blocks. It’s written in Solidity but can be linked to any language (think of it as smart embedded APIs). DS-Math is the most used library for arithmetic functions that does basic addition, subtraction, multiplication and division by handling integer overflows and simplifying routine functions like finding the minimum or maximum of two numbers.

The rapid adoption of blockchain and smart contracts is pushing the development community to get a common standard. This is still a work in progress, though.

LEAVE A REPLY

Please enter your comment!
Please enter your name here