GetCoinInfo gRPC Method
參數
coin_type
字串
必填
載入中...
退貨
coinType
字串
載入中...
元資料
物件
載入中...
id
字串
載入中...
decimals
整數
載入中...
名稱
字串
載入中...
符號
字串
載入中...
說明
字串
載入中...
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套件 主函式23匯入 (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"log"9「時間」1011"google.golang.grpc"12"google.golang.grpc"13"google.golang.org/protobuf/encoding/protojson"1415pb "sui-grpc/sui/rpc/v2" // Your Generated .pb.go files path16)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 = "YOUR_TOKEN_NUMBER"25endpoint = "YOUR_QN_ENDPOINT:9000"26)2728// Auth structure for x-token29類型 auth 結構體 {30代幣 字串31}3233func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字串) (map[字串]字串, 錯誤) {34return map[string]string{"x-token": a.token}, nil35}36func (a *auth) RequireTransportSecurity() bool {37return true38}3940func main() {41creds := credentials.NewTLS(&tls.Config{})42opts := []grpc.DialOption{43grpc.WithTransportCredentials(creds),44grpc.WithPerRPC憑證(&auth{token}),45}4647conn, err := grpc.撥號(endpoint, opts...)48如果 err != nil {49log.Fatalf("Failed to connect: %v", err)50}51延後 延遲連接.關閉()5253client := pb.NewStateServiceClient(conn)5455coinType := "0x2::sui::SUI"5657// Build request with field mask58req := &pb.GetCoinInfoRequest{59CoinType: &coinType,60}6162ctx, 取消 := context.WithTimeout(context.背景(), 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,74Indent: " ",75}7677jsonBytes, err := marshaler.Marshal(resp)78如果 err != nil {79log.Fatalf("Failed to marshal: %v", err)80}8182var pretty map[string]interface{}83if err := json.Unmarshal(jsonBytes, &pretty); err != nil {84log.Fatalf("Failed to parse JSON: %v", err)85}8687out, _ := json.MarshalIndent(pretty, "", " ")88fmt.Println(string(out))89}90
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"log"9「時間」1011"google.golang.grpc"12"google.golang.grpc"13"google.golang.org/protobuf/encoding/protojson"1415pb "sui-grpc/sui/rpc/v2" // Your Generated .pb.go files path16)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 = "YOUR_TOKEN_NUMBER"25endpoint = "YOUR_QN_ENDPOINT:9000"26)2728// Auth structure for x-token29類型 auth 結構體 {30代幣 字串31}3233func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字串) (map[字串]字串, 錯誤) {34return map[string]string{"x-token": a.token}, nil35}36func (a *auth) RequireTransportSecurity() bool {37return true38}3940func main() {41creds := credentials.NewTLS(&tls.Config{})42opts := []grpc.DialOption{43grpc.WithTransportCredentials(creds),44grpc.WithPerRPC憑證(&auth{token}),45}4647conn, err := grpc.撥號(endpoint, opts...)48如果 err != nil {49log.Fatalf("Failed to connect: %v", err)50}51延後 延遲連接.關閉()5253client := pb.NewStateServiceClient(conn)5455coinType := "0x2::sui::SUI"5657// Build request with field mask58req := &pb.GetCoinInfoRequest{59CoinType: &coinType,60}6162ctx, 取消 := context.WithTimeout(context.背景(), 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,74Indent: " ",75}7677jsonBytes, err := marshaler.Marshal(resp)78如果 err != nil {79log.Fatalf("Failed to marshal: %v", err)80}8182var pretty map[string]interface{}83if err := json.Unmarshal(jsonBytes, &pretty); err != nil {84log.Fatalf("Failed to parse JSON: %v", err)85}8687out, _ := json.MarshalIndent(pretty, "", " ")88fmt.Println(string(out))89}90
1import * as grpc from '@grpc/grpc-js';2import * as protoLoader from '@grpc/proto-loader';3import * as path from 'path';45// Configuration6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/state_service.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.sui-mainnet.quiknode.pro:9000';14const token = 'abcde123456789';1516// Load protobuf definitions17const packageDefinition = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19longs: String,20enums: String,21defaults: true,22oneofs: true,23includeDirs: [path.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) as any;27const StateService = proto.sui.rpc.v2.StateService;2829// Create secure client30const client = new StateService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Request payload37const request = {38coin_type: '0x2::sui::SUI',39};4041// Perform gRPC call42client.GetCoinInfo(request, metadata, (err: grpc.ServiceError | null, response: any) => {43if (err) {44console.error('gRPC Error:', {45code: err.code,46message: err.message,47details: err.details,48});49} else {50console.log('GetCoinInfo Response:');51console.log(JSON.stringify(response, null, 2));52}53});54
1import * as grpc from '@grpc/grpc-js';2import * as protoLoader from '@grpc/proto-loader';3import * as path from 'path';45// Configuration6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/state_service.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.sui-mainnet.quiknode.pro:9000';14const token = 'abcde123456789';1516// Load protobuf definitions17const packageDefinition = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19longs: String,20enums: String,21defaults: true,22oneofs: true,23includeDirs: [path.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) as any;27const StateService = proto.sui.rpc.v2.StateService;2829// Create secure client30const client = new StateService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Request payload37const request = {38coin_type: '0x2::sui::SUI',39};4041// Perform gRPC call42client.GetCoinInfo(request, metadata, (err: grpc.ServiceError | null, response: any) => {43if (err) {44console.error('gRPC Error:', {45code: err.code,46message: err.message,47details: err.details,48});49} else {50console.log('GetCoinInfo Response:');51console.log(JSON.stringify(response, null, 2));52}53});54
1import grpc2匯入 json3from google.protobuf.json_format import MessageToDict4from sui.rpc.v2 import state_service_pb2, state_service_pb2_grpc567def get_coin_info():89# Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token10# For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678911# 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';1617channel = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())18stub = state_service_pb2_grpc.StateServiceStub(channel)1920coin_type = "0x2::sui::SUI"2122request = state_service_pb2.GetCoinInfoRequest(23coin_type=coin_type24)2526metadata = [("x-token", token)]2728return stub.GetCoinInfo(request, metadata=metadata)293031def parse_response_to_json(response):32return json.dumps(33MessageToDict(response, preserving_proto_field_name=True),34indent=235)363738def main():39try:40response = get_coin_info()41print(parse_response_to_json(response))42except grpc.RpcError as e:43print(f"{e.code().name}: {e.details()}")444546if __name__ == "__main__":47main()48
1import grpc2匯入 json3from google.protobuf.json_format import MessageToDict4from sui.rpc.v2 import state_service_pb2, state_service_pb2_grpc567def get_coin_info():89# Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token10# For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678911# 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';1617channel = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())18stub = state_service_pb2_grpc.StateServiceStub(channel)1920coin_type = "0x2::sui::SUI"2122request = state_service_pb2.GetCoinInfoRequest(23coin_type=coin_type24)2526metadata = [("x-token", token)]2728return stub.GetCoinInfo(request, metadata=metadata)293031def parse_response_to_json(response):32return json.dumps(33MessageToDict(response, preserving_proto_field_name=True),34indent=235)363738def main():39try:40response = get_coin_info()41print(parse_response_to_json(response))42except grpc.RpcError as e:43print(f"{e.code().name}: {e.details()}")444546if __name__ == "__main__":47main()48