GetCoinInfo gRPC Method
参数
coin_type
字符串
必填
正在加载...
退货
coinType
字符串
正在加载...
元数据
对象
正在加载...
id
字符串
正在加载...
小数
整数
正在加载...
名称
字符串
正在加载...
符号
字符串
正在加载...
描述
字符串
正在加载...
iconUrl
字符串
正在加载...
metadataCapId
字符串
正在加载...
treasury
对象
正在加载...
id
字符串
正在加载...
totalSupply
字符串
正在加载...
supplyState
字符串
正在加载...
regulatedMetadata
对象
正在加载...
id
字符串
正在加载...
coinMetadataObject
字符串
正在加载...
denyCapObject
字符串
正在加载...
请求
1grpcurl -proto ./sui/rpc/v2/state_service.proto -H "x-token: abcde123456789" -d '{2"coin_type": "0x2::sui::SUI"3}' docs-demo.sui-mainnet.quiknode.pro:9000 sui.rpc.v2.StateService/GetCoinInfo4
1grpcurl -proto ./sui/rpc/v2/state_service.proto -H "x-token: abcde123456789" -d '{2"coin_type": "0x2::sui::SUI"3}' docs-demo.sui-mainnet.quiknode.pro:9000 sui.rpc.v2.StateService/GetCoinInfo4
1包 main23import (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8“日志”9“时间”1011"google.golang.grpc"12"google.golang.grpc"13"google.golang.org/protobuf/encoding/protojson"1415pb "sui" // 您生成的 .pb.go 文件路径16)1718// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token19// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678920// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}21// token will be : abcde1234567892223var (24token = "您的令牌编号"25endpoint = "您的QN端点:9000"26)2728// Auth structure for x-token29类型 auth 结构体 {30token 字符串31}3233func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字符串) (map[字符串]字符串, error) {34return map[string]string{"x-token": a.token}, nil35}36func (a *auth) RequireTransportSecurity() bool {37返回 true38}3940func main() {41creds := credentials.NewTLS(&tls.Config{})42opts := []grpc.DialOption{43grpc.WithTransportCredentials(creds),44grpc.WithPerRPCCredentials(&auth{令牌}),45}4647conn, err := grpc.Dial(endpoint, opts...)48如果 err != nil {49log.Fatalf("连接失败:%v", err)50}51推迟 conn.关闭()5253client := pb.NewStateServiceClient(conn)5455coinType := "0x2::sui::SUI"5657// Build request with field mask58req := &pb.GetCoinInfoRequest{59CoinType: &coinType,60}6162ctx, 取消 := context.带超时(context.Background(), 10*时间.第二次)63推迟 取消()6465resp, err := client.GetCoinInfo(ctx, req)66如果 err != nil {67log.Fatalf("GetCoinInfo failed: %v", err)68}6970// Pretty print the response71marshaler := protojson.MarshalOptions{72UseProtoNames: true,73EmitUnpopulated: true,74缩进: " ",75}7677jsonBytes, err := marshaler.Marshal(resp)78如果 err != nil {79log.Fatalf(“序列化失败:%v”, err)80}8182var pretty map[字符串]接口{}83if err := json.Unmarshal(jsonBytes, &pretty); err != nil {84log.Fatalf(“无法解析 JSON:%v”, err)85}8687out, _ := json.MarshalIndent(pretty, "", " ")88fmt.Println(字符串(out))89}90
1包 main23import (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8“日志”9“时间”1011"google.golang.grpc"12"google.golang.grpc"13"google.golang.org/protobuf/encoding/protojson"1415pb "sui" // 您生成的 .pb.go 文件路径16)1718// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token19// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678920// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}21// token will be : abcde1234567892223var (24token = "您的令牌编号"25endpoint = "您的QN端点:9000"26)2728// Auth structure for x-token29类型 auth 结构体 {30token 字符串31}3233func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字符串) (map[字符串]字符串, error) {34return map[string]string{"x-token": a.token}, nil35}36func (a *auth) RequireTransportSecurity() bool {37返回 true38}3940func main() {41creds := credentials.NewTLS(&tls.Config{})42opts := []grpc.DialOption{43grpc.WithTransportCredentials(creds),44grpc.WithPerRPCCredentials(&auth{令牌}),45}4647conn, err := grpc.Dial(endpoint, opts...)48如果 err != nil {49log.Fatalf("连接失败:%v", err)50}51推迟 conn.关闭()5253client := pb.NewStateServiceClient(conn)5455coinType := "0x2::sui::SUI"5657// Build request with field mask58req := &pb.GetCoinInfoRequest{59CoinType: &coinType,60}6162ctx, 取消 := context.带超时(context.Background(), 10*时间.第二次)63推迟 取消()6465resp, err := client.GetCoinInfo(ctx, req)66如果 err != nil {67log.Fatalf("GetCoinInfo failed: %v", err)68}6970// Pretty print the response71marshaler := protojson.MarshalOptions{72UseProtoNames: true,73EmitUnpopulated: true,74缩进: " ",75}7677jsonBytes, err := marshaler.Marshal(resp)78如果 err != nil {79log.Fatalf(“序列化失败:%v”, err)80}8182var pretty map[字符串]接口{}83if err := json.Unmarshal(jsonBytes, &pretty); err != nil {84log.Fatalf(“无法解析 JSON:%v”, err)85}8687out, _ := json.MarshalIndent(pretty, "", " ")88fmt.Println(字符串(out))89}90
1import * 作为 grpc from grpc;2import * 作为 protoLoader from grpc;3import * 作为 路径 from '路径';45// Configuration6const PROTO_PATH = 路径.join(__dirname, sui.proto');78// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token9// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678910// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11// token will be : abcde1234567891213const endpoint = 'docs-demo.mainnet.quiknode.pro:9000';14const 令牌 = 'abcde123456789';1516// Load protobuf definitions17const 包定义 = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19多头: 字符串,20枚举: 字符串,21默认值: true,22oneofs: true,23includeDirs: [路径.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) 作为 any;27const StateService = proto.sui.rpc.v2.StateService;2829// Create secure client30const 客户端 = new StateService(endpoint, grpc.凭据.createSsl());3132// Add token metadata33const 元数据 = new grpc.元数据();34元数据.添加('x-token', token);3536// Request payload37const 请求 = {38coin_type: '0x2::sui::SUI',39};4041// Perform gRPC call42client.GetCoinInfo(request, metadata, (err: grpc.ServiceError | null, response: any) => {43如果 (err) {44console.error('gRPC Error:', {45代码: err.代码,46消息: err.消息,47详细信息: err.详情,48});49} else {50console.log('GetCoinInfo Response:');51控制台.日志(JSON.stringify(response, null, 2));52}53});54
1import * 作为 grpc from grpc;2import * 作为 protoLoader from grpc;3import * 作为 路径 from '路径';45// Configuration6const PROTO_PATH = 路径.join(__dirname, sui.proto');78// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token9// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678910// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11// token will be : abcde1234567891213const endpoint = 'docs-demo.mainnet.quiknode.pro:9000';14const 令牌 = 'abcde123456789';1516// Load protobuf definitions17const 包定义 = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19多头: 字符串,20枚举: 字符串,21默认值: true,22oneofs: true,23includeDirs: [路径.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) 作为 any;27const StateService = proto.sui.rpc.v2.StateService;2829// Create secure client30const 客户端 = new StateService(endpoint, grpc.凭据.createSsl());3132// Add token metadata33const 元数据 = new grpc.元数据();34元数据.添加('x-token', token);3536// Request payload37const 请求 = {38coin_type: '0x2::sui::SUI',39};4041// Perform gRPC call42client.GetCoinInfo(request, metadata, (err: grpc.ServiceError | null, response: any) => {43如果 (err) {44console.error('gRPC Error:', {45代码: err.代码,46消息: err.消息,47详细信息: err.详情,48});49} else {50console.log('GetCoinInfo Response:');51控制台.日志(JSON.stringify(response, null, 2));52}53});54
1import grpc2导入 json3来源 谷歌.protobuf.json_format import MessageToDict4来自 sui.rpc.v2 import state_service_pb2, state_service_pb2_grpc567def get_coin_info():89#Quicknode 由两个关键组成部分构成:endpoint 和相应的令牌10# 例如:QNEndpoint:mainnet11# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}12# token will be : abcde1234567891314endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';15token = 'abcde123456789';1617频道 = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())18占位符 = state_service_pb2_grpc.StateServiceStub(channel)1920coin_type = "0x2::sui::SUI"2122request = state_service_pb2.GetCoinInfoRequest(23coin_type=coin_type24)2526元数据 = [("x-token", token)]2728return stub.GetCoinInfo(request, metadata=metadata)293031def parse_response_to_json(response):32返回 json.dumps(33MessageToDict(response, 保留_proto_字段_名称=True),34缩进=235)363738def main():39试一试:40response = get_coin_info()41打印(parse_response_to_json(response))42除了 grpc。RpcError 作为 e:43print(f"{e.code().name}: {e.details()}")444546如果 __name__ == "__main__":47主()48
1import grpc2导入 json3来源 谷歌.protobuf.json_format import MessageToDict4来自 sui.rpc.v2 import state_service_pb2, state_service_pb2_grpc567def get_coin_info():89#Quicknode 由两个关键组成部分构成:endpoint 和相应的令牌10# 例如:QNEndpoint:mainnet11# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}12# token will be : abcde1234567891314endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';15token = 'abcde123456789';1617频道 = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())18占位符 = state_service_pb2_grpc.StateServiceStub(channel)1920coin_type = "0x2::sui::SUI"2122request = state_service_pb2.GetCoinInfoRequest(23coin_type=coin_type24)2526元数据 = [("x-token", token)]2728return stub.GetCoinInfo(request, metadata=metadata)293031def parse_response_to_json(response):32返回 json.dumps(33MessageToDict(response, 保留_proto_字段_名称=True),34缩进=235)363738def main():39试一试:40response = get_coin_info()41打印(parse_response_to_json(response))42除了 grpc。RpcError 作为 e:43print(f"{e.code().name}: {e.details()}")444546如果 __name__ == "__main__":47主()48