Dumbonet: How to write a smart contract in JavaScript
In the last article, we finished our blockchain network with Hyperledger Fabric help. At the heart of a blockchain network is a smart contract. Hyperledger Fabric users often use the terms smart contract and chaincode interchangeably.
A smart contract defines the executable logic that generates new facts that are added to the ledger.
A chaincode is typically used by administrators to group related smart contracts for deployment, but can also be used for low level system programming of Fabric.
In our case, we have one Dumbonet chaincode, and two smart contracts — one for Inquiry asset and one for Quotation asset.
A smart contract programmatically accesses two distinct pieces of the ledger — a blockchain, which immutably records the history of all transactions and a world state that holds a cache of the current value of these states, as it’s the current value of an object that is usually required.
Smart contracts primarily put, get and delete states in the world state, and can also query the immutable blockchain record of transactions.
· A get typically represents a query to retrieve information about the current state of a business object.
· A put typically creates a new business object or modifies an existing one in the ledger world state.
· A delete typically represents the removal of a business object from the current state of the ledger, but not its history.
Pay attention to this in code example below — getState,putState,deleteState.
We will define create, read, update and delete (CRUD) operation over our asset — Inquiry and you should do, by yourself, the second one, for asset Quotation. 🤞
Great, now we have almost everything — network, chaincode and now it’s time for API. In the next article, we will show you a few examples of transactions and you can write more if you want.
Stay tuned and until then — happy coding! 😎