GetFunction gRPC Method
Parâmetros
package_id
cadeia de caracteres
OBRIGATÓRIO
A carregar...
module_name
cadeia de caracteres
OBRIGATÓRIO
A carregar...
nome
cadeia de caracteres
OBRIGATÓRIO
A carregar...
Devoluções
function
objeto
A carregar...
nome
cadeia de caracteres
A carregar...
visibility
cadeia de caracteres
A carregar...
isEntry
booleano
A carregar...
typeParameters
matriz
A carregar...
parameters
matriz
A carregar...
reference
cadeia de caracteres
A carregar...
body
objeto
A carregar...
tipo
cadeia de caracteres
A carregar...
typeName
cadeia de caracteres
A carregar...
typeParameterInstantiation
matriz
A carregar...
tipo
cadeia de caracteres
A carregar...
typeParameter
número inteiro
A carregar...
returns
matriz
A carregar...
body
objeto
A carregar...
tipo
cadeia de caracteres
A carregar...
typeName
cadeia de caracteres
A carregar...
typeParameterInstantiation
matriz
A carregar...
tipo
cadeia de caracteres
A carregar...
typeParameter
número inteiro
A carregar...
Pedido
1grpcurl \2-import-path . \3-proto sui/rpc/v2/move_package_service.proto \4-H "x-token: abcde123456789" \5-d '{6"package_id": "0x2",7"module_name": "coin",8"name": "mint"9}' \10docs-demo.sui-mainnet.quiknode.pro:9000 \11sui.rpc.v2.MovePackageService/GetFunction12
1grpcurl \2-import-path . \3-proto sui/rpc/v2/move_package_service.proto \4-H "x-token: abcde123456789" \5-d '{6"package_id": "0x2",7"module_name": "coin",8"name": "mint"9}' \10docs-demo.sui-mainnet.quiknode.pro:9000 \11sui.rpc.v2.MovePackageService/GetFunction12
1pacote principal23importar (4"contexto"5"crypto/tls"6"encoding/json"7"fmt"8"registo"9"time"1011"google.golang.org/grpc"12"google.golang.org/grpc/credentials"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-token29tipo auth estrutura {30token string31}3233func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]string, erro) {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.WithPerRPCCredentials(&auth{token}),45}4647conn, err := grpc.Dial(endpoint, opts...)48if err != nil {49log.Fatalf("Failed to connect: %v", err)50}51defer conn.Close()5253client := pb.NewMovePackageServiceClient(conn)5455packageID := "0x2"56moduleName := "coin"57functionName := "mint"5859req := &pb.GetFunctionRequest{60PackageId: &packageID,61ModuleName: &moduleName,62Name: &functionName,63}6465ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)66defer cancel()6768resp, err := client.GetFunction(ctx, req)69if err != nil {70log.Fatalf("GetFunction failed: %v", err)71}7273marshaler := protojson.MarshalOptions{74UseProtoNames: true,75EmitUnpopulated: true,76Indent: " ",77}7879jsonBytes, err := marshaler.Marshal(resp)80if err != nil {81log.Fatalf("Failed to marshal: %v", err)82}8384var pretty map[string]interface{}85if err := json.Unmarshal(jsonBytes, &pretty); err != nil {86log.Fatalf("Failed to parse JSON: %v", err)87}8889out, _ := json.MarshalIndent(pretty, "", " ")90fmt.Println(string(out))91}92
1pacote principal23importar (4"contexto"5"crypto/tls"6"encoding/json"7"fmt"8"registo"9"time"1011"google.golang.org/grpc"12"google.golang.org/grpc/credentials"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-token29tipo auth estrutura {30token string31}3233func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]string, erro) {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.WithPerRPCCredentials(&auth{token}),45}4647conn, err := grpc.Dial(endpoint, opts...)48if err != nil {49log.Fatalf("Failed to connect: %v", err)50}51defer conn.Close()5253client := pb.NewMovePackageServiceClient(conn)5455packageID := "0x2"56moduleName := "coin"57functionName := "mint"5859req := &pb.GetFunctionRequest{60PackageId: &packageID,61ModuleName: &moduleName,62Name: &functionName,63}6465ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)66defer cancel()6768resp, err := client.GetFunction(ctx, req)69if err != nil {70log.Fatalf("GetFunction failed: %v", err)71}7273marshaler := protojson.MarshalOptions{74UseProtoNames: true,75EmitUnpopulated: true,76Indent: " ",77}7879jsonBytes, err := marshaler.Marshal(resp)80if err != nil {81log.Fatalf("Failed to marshal: %v", err)82}8384var pretty map[string]interface{}85if err := json.Unmarshal(jsonBytes, &pretty); err != nil {86log.Fatalf("Failed to parse JSON: %v", err)87}8889out, _ := json.MarshalIndent(pretty, "", " ")90fmt.Println(string(out))91}92
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/move_package_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 MovePackageService = proto.sui.rpc.v2.MovePackageService;2829// Create secure client30const client = new MovePackageService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Request payload37const request = {38package_id: '0x2',39module_name: 'coin',40name: 'mint',41};4243// Perform gRPC call44client.GetFunction(request, metadata, (err: grpc.ServiceError | null, response: any) => {45if (err) {46console.error('gRPC Error:', {47code: err.code,48message: err.message,49details: err.details,50});51} else {52console.log('GetFunction Response:');53console.log(JSON.stringify(response, null, 2));54}55});56
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/move_package_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 MovePackageService = proto.sui.rpc.v2.MovePackageService;2829// Create secure client30const client = new MovePackageService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Request payload37const request = {38package_id: '0x2',39module_name: 'coin',40name: 'mint',41};4243// Perform gRPC call44client.GetFunction(request, metadata, (err: grpc.ServiceError | null, response: any) => {45if (err) {46console.error('gRPC Error:', {47code: err.code,48message: err.message,49details: err.details,50});51} else {52console.log('GetFunction Response:');53console.log(JSON.stringify(response, null, 2));54}55});56
1import grpc2import json3from google.protobuf.json_format import MessageToDict4from sui.rpc.v2 import move_package_service_pb2, move_package_service_pb2_grpc567def get_function():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 = move_package_service_pb2_grpc.MovePackageServiceStub(channel)1920package_id = "0x2"21module_name = "coin"22name = "mint"2324request = move_package_service_pb2.GetFunctionRequest(25package_id=package_id,26module_name=module_name,27name=name28)2930metadata = [("x-token", token)]3132return stub.GetFunction(request, metadata=metadata)333435def parse_response_to_json(response):36return json.dumps(37MessageToDict(response, preserving_proto_field_name=True),38indent=239)404142def main():43try:44response = get_function()45print(parse_response_to_json(response))46except grpc.RpcError as e:47print(f"{e.code().name}: {e.details()}")4849if __name__ == "__main__":50main()51
1import grpc2import json3from google.protobuf.json_format import MessageToDict4from sui.rpc.v2 import move_package_service_pb2, move_package_service_pb2_grpc567def get_function():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 = move_package_service_pb2_grpc.MovePackageServiceStub(channel)1920package_id = "0x2"21module_name = "coin"22name = "mint"2324request = move_package_service_pb2.GetFunctionRequest(25package_id=package_id,26module_name=module_name,27name=name28)2930metadata = [("x-token", token)]3132return stub.GetFunction(request, metadata=metadata)333435def parse_response_to_json(response):36return json.dumps(37MessageToDict(response, preserving_proto_field_name=True),38indent=239)404142def main():43try:44response = get_function()45print(parse_response_to_json(response))46except grpc.RpcError as e:47print(f"{e.code().name}: {e.details()}")4849if __name__ == "__main__":50main()51
Ainda não tem uma conta?
Crie o seu ponto de extremidade Quicknode em segundos e comece a desenvolver
Comece gratuitamente