The following are important technical points in the development process of smart contract DApp:
Smart contract language:Solidity is one of the main languages at present,because Ethereum,as one of the most widely used blockchain platforms,supports Solidity language as the writing language of smart contracts.In addition,there are other languages available for developing smart contracts,such as Vyper and Serpent.
Blockchain nodes and wallets:Publish smart contracts by selecting suitable blockchain nodes,and also require some wallet management tools,such as MetaMask wallets.
Browser integrated development tools:To facilitate the development and debugging of smart contract DApp,some browser integrated development tools such as Remix can also be used.
Frontend framework:When implementing the DApp front-end interface,it is necessary to choose a suitable front-end framework.The current popular front-end frameworks include React,Vue,Angular,and so on.
编写智能合约
使用Golang编写链码,需要使用到Fabric的shim包。链码的编写需要实现ChainCode interface,并实现Invoke方法,来提供交易处理逻辑。
举一个简单的例子,我们编写一个调用链码的代码,链码的功能为获取一个特定的键值。
func queryByKey(stub shim.ChaincodeStubInterface,args[]string)pb.Response{
if len(args)!=1{
return shim.Error("Incorrect number of arguments.Expecting key to query")
}
A:=args[0]
Avalbytes,err:=stub.GetState(A)
if err!=nil{
jsonResp:="{"Error":"Failed to get state for"+A+""}"
return shim.Error(jsonResp)
}
if Avalbytes==nil{
jsonResp:="{"Error":"Nil amount for"+A+""}"
return shim.Error(jsonResp)
}
jsonResp:="{"Name":""+A+"","Amount":""+string(Avalbytes)+""}"
fmt.Printf("Query Response:%sn",jsonResp)
return shim.Success(Avalbytes)
}