Service
Smart Contract Service#
When writing a smart contract in aelf, the first step is to define it so our tools can generate it. aelf contracts are defined and generated using gRPC and protobuf.
Example: Multi-Token Contract#
Here is a simplified part of our multi-token contract definition:
1syntax = "proto3";23package token;4option csharp_namespace = "AElf.Contracts.MultiToken.Messages";56service TokenContract {7option (aelf.csharp_state) = "AElf.Contracts.MultiToken.TokenContractState";89// Actions10rpc Create (CreateInput) returns (google.protobuf.Empty) { }11rpc Transfer (TransferInput) returns (google.protobuf.Empty) { }1213// Views14rpc GetBalance (GetBalanceInput) returns (GetBalanceOutput) {15option (aelf.is_view) = true;16}17}
Service Methods#
There are two types of methods in a service:
Actions#
Example:
1rpc Create (CreateInput) returns (google.protobuf.Empty) { }
Views#
Example:
1rpc GetBalance (GetBalanceInput) returns (GetBalanceOutput) {2option (aelf.is_view) = true;3}
Edited on: 15 July 2024 03:24:10 GMT+0