At present, Substrate has a large number of client SDKs of different languages to interact with the blockchains. However, these client SDKs are oriented to the Substrate-based chain, so the functions provided by them are often limited to the APIs and primitive under the Substrate framework. All of these client SDKs do not support smart contracts.
In the Polkadot ecosystem, not all parachains need to include smart contracts support. In most cases, Runtime can already solve most certain application scenarios. Therefore, the client SDKs for Substrate does not have to support smart contracts. On the other hand, based on the principle of minimization, this type of smart contract SDKs should be developed in the form of an independent library. This is the development goal of Himalia.
A smart contract-based DApp not only needs to develop the contract on the chain, but also needs to develop user-oriented front-end interfaces and micro-services, which means that developers need to interact with contracts from different terminals and based on multiple development languages.
Himalia will provide FRAME Contracts SDK supports in a multi-language environment to support WASM DApp development. Himalia will be Patract Hub's 7th project for whole WASM contract development support. DApp needs to choose different technology stacks based on its form. For example, a service that provides users with contract status queries is often developed based on Golang, and a contract-based blockchain game can be developed in C# based on game engines such as Unity3D. This means that to expand the application scenarios of DApp, we need SDKs in as many environments as possible. Currently Himalia plans to implement SDK support for the following languages:
PatractGo
is a Golang contract SDK. In addition to supporting the basic interactive API with the contract, it mainly supports the development of micro-services based on the contract status. For example, for common ERC20 contracts, a service can be developed based on PatractGo to synchronize all transfer information to the database, and based on the database to implement the statistics and processing of transfer data. In addition, developers can also develop some command-line tools based on Golang to assist in testing and debugging. We will be independent of GSRPC and encapsulate the API provided by GSRPC , to adapt to different substrate-based chains.
Most contract behaviors are highly related to context. In addition to interacting with the chain, user-oriented contract applications also need to provide users with current relevant context status information:
+--DAPP-Front-End--------------+ +---Chain-------------------------+
| | | |
| +----+ +------------------+ | | +-------+ +-------+ |
| | | | | | Commit | | | | | |
| | | | Polkadot-JS +------------> Node +---->+ Node | |
| | +->+ | | Tx | | | | | |
| | | | | | | +-------+ +----+-++ |
| | | +------------------+ | | ^ | |
| | UI | | +---------------------------------+
| | | +------------------+ | | |
| | | | | | +--DAPP-Server--------------------+
| | | | | | Push | +--------+ +-----v-------+ |
| | +<-+ Model +<-----------+ +-----+ | |
| | | | | | | | Server | | PatractGo | |
| | | | +------------> +-----+ | |
| +----+ +------------------+ | Query | +----+---+ +-----+-------+ |
+------------------------------+ | | | |
| | +-----v-------+ |
| | | | |
| +-------->+ DataBase | |
| | | |
| +-------------+ |
| |
+---------------------------------+
PatractGo is mainly responsible for implementing micro-services in a DApp. Unlike querying the state of the chain API, PatractGo can monitor the calls and events generated by the specified contract. Developers can obtain the state storage based on this information to maintain consistent state with the chain. Through data services based on a typical API-DB architecture, the front-end DApp can efficiently and concisely obtain the state on the chain as context information.
Based on the API of chain nodes, PatractGo obtains block information and summarizes and filters it, and sends contract-related messages and events based on metadata analysis to the handler protocol specified by the developer. For example, for a typical ERC20 contract, the developer can use the channel to subscribe to all transfer events that occur, and then synchronize them into the database, so that other microservices can provide services corresponding to the token data of the account, such as querying the current token holding distribution and other logics.
Therefor, PatractGo will achieve the following support:
put_code
, call
, instantiate
, etc.PatractGo consists of the following packages:
patractgo/metadata
contract metadata processing, and metadata-based contract processingpatractgo/rpc/native
re-encapsulation of the contract module interface to provide the contract-related interaction based on chain RPCpatractgo/rpc
implement the interaction with the contract based on metadatapatractgo/rest
implements an http service based on metadata to interact with the contractpatractgo/scanner
Scanning support for contract status on chainpatractgo/observer
Monitoring support for contract status on the chainpatractgo/contracts/erc20
supports ERC20 contractspatractgo/cmd/patractgo
a command line tool for interacting with contractspatractgo/cmd/pdumper
monitors contract status and events and synchronizes them to the databasepatractgo/examples
SDK instancePatractPy
is a contract SDK to support the development of Python scripts that interact with contracts, including automated scripts to support testing. Unlike PatractGo, PatractPy is mainly for script development, so PatractPy mainly completes contract-related RPC interfaces, and completes contract deployment and instantiation-related operations. At the same time, PatractPy will implement PatractGo-based interaction and contract status monitoring support.
As a result, PatractPy will achieve the following support:
put_code
, call
, instantiate
, etc.PatractGo
, provide HTTP service for contract-based metadata information and contract interactionPatractGo
, provide Scanning and monitoring support for contract to do statistics and analysisPatractGo
, complete the contract interaction API based on metadata.jsonPatractGo
, complete the monitoring service support, and complete the example to write into the databaseWe have finished the design for the Java and .NET SDK, but because the chain SDK teams hasn't completed the Substrate 2.0 support , so we may need to wait for them to finish it and apply later, so the timeline maybe uncertain.