Smart Contracts

What is a smart contract?

Smart contracts for blockchain are computer protocols intended to digitally facilitate, verify, or enforce the negotiation or performance of a contract. They facilitate credible transactions in a traceable and permanent manner, without the need for third parties. Smart contracts allow businesses, governments, organizations, and developers to control which contractual clauses are made partially or entirely self-executing and self-enforcing.

Smart Contract

Writing smart contracts in any coding language.

To start developing smart contracts on your own blockchain, you may find knowledge of containerization like Docker and OpenFaaS helpful. If you are not familiar with this technology, it is highly advised that you do some research on this subject. OpenFaaS (Functions as a Service) is a framework for building serverless functions with a Docker image that can be deployed on Docker swarm/Kubernetes with support for metrics. Any process can be packaged as a function, allowing consumption of a wide range of web events without repetitive boilerplate coding.

Dragonchain's smart contract system uses OpenFaaS to deploy smart contracts on the blockchain. It simplifies the deployment process. And allows developers to build smart contracts in any coding language they are familiar with. A unit test can be added to a smart contract in a docker file. The Dragonchain is unique among blockchain platforms in that it treats smart contracts as a software that can be maintained. An Ethereum smart contract for example can not be maintained, and can only be written in Solidity. Reversing an Ethereum smart contract on the Virtual Machine (VM) is, well... Quite the effort.

For the most up-to-date documentations on creating your Dragonchain smart contracts, visit our docs. Ready to start building your applications? Discover the features of our blockchain platform.

Key elements and benefits of smart contracts.

  • Docker: When developing a smart contract on your dragonchain, you will need to have a docker file, which will allow you to deploy the contract on Dragonchain. You will need to push the code to docker hub which is a secure repository (push it as private/public). Users can also specify the name of their smart contract (docker image) when deploying the contract to Dragonchain.
  • Entry-point: Dragonchain smart contracts use stdin to receive a payload and then stdout to print the payload result to the Dragonchain heap. A Heap is a flexible key and value pair storage that can be structured to meet different needs.
  • Speed and accuracy: Thanks to the underlying blockchain technology, digital and automated smart contracts save time on paperwork and bureaucracy. Executable code is more precise than the legalese that traditional contracts are written in. With Dragonchain, you can also edit your smart contracts at any time.
  • Trust: Smart contracts are used to execute transactions based on programmed rules and conditions. The encrypted records of those transactions are shared across participants. This can be through private shared blockchains, or selectively exposed on public blockchains as well while using Interchain.
  • Security: Blockchain transactions on your Level 1 business node are private, unless explicitly permissioned otherwise. Hashes of transactions are stored in blocks, that are connected to previous and subsequent blocks on the distributed ledger.
  • Savings: Save on intermediaries now that participants can trust each others data, and the contracts to properly execute the transaction.

Smart contract examples.

Smart contracts have Dragonchain architecture calls for the definition of “approval context” code to be configured or deployed on Level 1 business nodes. This approval code can be considered a smart contract. By default, this smart contract will only execute on that Level 1 node(s), under the direct control of the business owner. This provides a familiar client/server interface for smart contract creation and simplified risk evaluation. The attack vectors are more common and known to modern engineers. Turing completeness is provided within any web service platform.

Custom smart contracts.

Create your own custom smart contracts. With Dragonchain, you can run code written in any of the supported languages without provisioning or managing servers. A simple "post" can invoke your smart contract to run it identifying the smart contract in the post request adding conditional logic of your choice. Using conditional logic, you can digitally facilitate, verify, or enforce the negotiation or performance of a contract.

Publisher Smart Contracts

The process of developing an Interchain publisher smart contract.  These contracts use your Dragonchain's built-in wallet to sign and send transactions to a public network.  Currently ETH, ETC and NEO Publisher contracts are available.

Interchain Publisher Smart Contracts use your Dragonchain's built-in wallet to sign and send transactions to the Ethereum.  When writing to an Ethereum network the transaction must be paid for in gas.

The smart contract sends out the transaction with the provided parameters to the selected network and then waits for the transaction to be confirmed. Transaction parameters are fully configurable and defaults are provided for each. When the confirmation count is met the contract will post a Dragonchain transaction (will post the same result to the callback too, if provided) with the payload.

Watcher smart contracts

The process of developing an Interchain Watcher smart contract.  These types of contracts send a response every time something happens (such as various types of transactions) to a certain address on a given blockchain (Ethereum, Ropsten, Ethereum Classic etc.).   Currently watcher contracts are available for Ethereum and NEO.

Here we will outline an explanation of an interchain watcher smart contract on Dragonchain. Interchain Watcher Smart Contracts are used to watch certain types of transactions happen on a given address on a given blockchain.   It will send transactions from other blockchains to you.

What is a token?

A token is quite simply a quantified unit of value that can be spent, tracked and traded. These tokens can be exchanged for other currencies or tokens based on valuation. This is all accomplished via a marketplace and transactions.

Tokenized units of value can be anything within a system that has value, tangible or not. Unlike fiat currency, tokens allow us to define a broader set of values and the rules that govern how that value is spent. Unlike in a fiat model, things like social capital, natural capital, or cultural capital, can be tracked using a token system.

Tokens are digital and they can be programmed. Tokens can be programmed in such a way that it can only be used or spent under certain conditions. Conditions can be set and tracked in the code. A token could be created that could be paid in dollars but the token itself can only be used at certain parties or locations (marketplaces, health credits, educational credits, etc).

With Dragonchain, we track this value using  Distributed Ledger Technology within an L1 Dragonchain node.

Currency smart contracts.

A smart contract is a set of operations or instructions in the form of a computer program. They are programmatically made to only accept inputs and outputs defined in the contract. Any smart contract should promise that valid inputs lead to valid outputs.

Dragonchain smart contracts are executed on a private Level 1 business node, and are directly controlled by the contract owner. A smart contract can be distributed and executed on a pay-per-request basis.

Dragonchain's Currency smart contract creates and maintains a single tokenized economy for use as a currency on your Dragonchain. Currency smart contracts allow users to create their own currency within Dragonchain, send currency from one wallet to another, check the balance of a wallet address, and retrieve the total amount of currency.

Using the Currency smart contract, organizations can specify a total amount of currency that can be retrieved, transfer currency between wallet addresses, or check the balance of the currency in a wallet address. These can all be run using different schemas (e.g., ERC20 or ERC223).

The process of developing a smart contract that creates a currency on your Dragonchain is simple. Currency smart contracts are essential in most blockchain projects. Checking a balance and moving balances between addresses is as easy as posting transactions to your chain. Once the currency contract is created on the chain, these methods and variables can be used via the API

smart contract types

Use case example

Rewards or loyalty programs are an easy example to reference for currency contracts. A persistent downside of loyalty programs to organizations is unused incentives. Those loyalty points that just never get used. Unrealized incentives present specific accounting challenges, and might end up costing an organization more than the benefit they offer.

Dragonchain smart contracts solve this problem by allowing that redemption to be automated — eliminating the possibility of unused points. Let’s assume a grocery store uses smart contracts — perhaps that store also has a Dragonchain currency smart contract loyalty card for its customers. When customers reach a certain threshold, rewards can automatically be triggered — perhaps a free reusable grocery bag is mailed. Alternatively, that grocery store might query its base of loyalty card smart contract holders, inviting those with the highest balances to a valued customer event.

Q: How do you create a smart contract?
A: Go to the console, spin up your node, and create a new smart contract, or select an existing smart contracts within the smart contract library.

Q: Why are smart contracts important?
A: Smart contracts solve the lack of trust between people and stakeholders doing business. Smart contracts benefit all industries, reducing unnecessary costs, time expenditure, and inefficiencies in processes, while also increasing transparency

Q: What languages are smart contracts written in?
A: This depends on the blockchain, or the platform. Smart contracts are written in Solidity on Ethereum. On Dragonchain, smart contracts can be written in Nodejs, C#, Go, Python, as well as any other language, including *nix shell.

Q: Are smart contracts legal?
A: Yes and no. A legal smart contract that is capable of self-executing, with accepted terms of an agreement between two or more parties, can be legal. There is a lack of regulations and written laws.

Q: Who invented smart contracts?
A: Nicholas J. Szabo mentioned and described smart contracts for the first time in 1994, in a paper for The George Washington University Law School.