Skip to main content
Version: v0.50.x

Set Data Structure

Extend the template module and add how to store and interact with data. Specifically, you need to set and retrieve a name.

Set Name

Open the proto/nameservice/v1 directory. Edit tx.proto to add the transaction setter message.

proto/nameservice/v1/tx.proto

// SetServiceName allows a user to set their accounts name.
rpc SetServiceName(MsgSetServiceName) returns (MsgSetServiceNameResponse);
}

// MsgSetServiceName defines the structure for setting a name.
message MsgSetServiceName {
option (cosmos.msg.v1.signer) = "sender";

string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

string name = 2;
}

// MsgSetServiceNameResponse is an empty reply.
message MsgSetServiceNameResponse {}
Details

proto/nameservice/v1/tx.proto file proto/nameservice/v1/tx.proto file

Get Name

Find query.proto and add the following

proto/nameservice/v1/query.proto

// ResolveName allows a user to resolve the name of an account.
rpc ResolveName(QueryResolveNameRequest) returns (QueryResolveNameResponse) {
option (google.api.http).get = "/nameservice/v1/name/{wallet}";
}
}

// QueryResolveNameRequest grabs the name of a wallet.
message QueryResolveNameRequest {
string wallet = 1;
}

// QueryResolveNameResponse grabs the wallet linked to a name.
message QueryResolveNameResponse {
string name = 1;
}
Details

proto/nameservice/v1/query.proto proto/nameservice/v1/query.proto file

Generate Code

These .proto file templates will be converted into Golang source code for you to use. Build the Go source code using the command:

make proto-gen
Details

make proto-gen expected output make proto-gen