Skip to main content

GetContractABI gRPC Method

Loading...

Updated on
May 13, 2025

GetContractABI gRPC Method

Parameters

contractAddress
string
REQUIRED
Loading...

Returns

entrys
array
Loading...
anonymous
boolean
Loading...
constant
boolean
Loading...
name
string
Loading...
inputs
array
Loading...
indexed
boolean
Loading...
name
string
Loading...
type
string
Loading...
outputs
array
Loading...
indexed
boolean
Loading...
name
string
Loading...
type
string
Loading...
type
string
Loading...
payable
boolean
Loading...
stateMutability
string
Loading...
Request
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"encoding/json"
7
"fmt"
8
"github.com/fbsobreira/gotron-sdk/pkg/client"
9
"google.golang.org/grpc"
10
"google.golang.org/grpc/credentials"
11
"log"
12
)
13
14
// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token
15
// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789
16
// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}
17
// token will be : abcde123456789
18
19
var token = "YOUR_TOKEN"
20
var endpoint = "YOUR_ENDPOINT:50051"
21
22
type auth struct {
23
token string
24
}
25
26
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
27
return map[string]string{
28
"x-token": a.token,
29
}, nil
30
}
31
32
func (a *auth) RequireTransportSecurity() bool {
33
return false
34
}
35
36
func main() {
37
38
opts := []grpc.DialOption{
39
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
40
grpc.WithPerRPCCredentials(&auth{token}),
41
}
42
conn := client.NewGrpcClient(endpoint)
43
if err := conn.Start(opts...); err != nil {
44
panic(err)
45
}
46
defer conn.Conn.Close()
47
48
contractAddress := "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
49
fmt.Printf("Fetching ABI for contract: %s\n", contractAddress)
50
contractABI, err := conn.GetContractABI(contractAddress)
51
if err != nil {
52
log.Fatalf("Error getting contract ABI: %v\n", err)
53
}
54
55
fmt.Println("\nContract ABI Information:")
56
abiJSON, err := json.MarshalIndent(contractABI, "", " ")
57
if err != nil {
58
log.Printf("Error marshaling ABI to JSON: %v\n", err)
59
} else {
60
fmt.Println(string(abiJSON))
61
}
62
63
if contractABI.Entrys != nil && len(contractABI.Entrys) > 0 {
64
fmt.Printf("\nContract has %d function entries\n", len(contractABI.Entrys))
65
maxFunctions := 5
66
if len(contractABI.Entrys) < maxFunctions {
67
maxFunctions = len(contractABI.Entrys)
68
}
69
70
fmt.Println("\nFunction Overview:")
71
for i := 0; i < maxFunctions; i++ {
72
entry := contractABI.Entrys[i]
73
fmt.Printf("%d. Name: %s, Type: %s\n", i+1, entry.Name, entry.Type)
74
if len(entry.Inputs) > 0 {
75
fmt.Print(" Parameters: ")
76
for j, input := range entry.Inputs {
77
fmt.Printf("%s (%s)", input.Name, input.Type)
78
if j < len(entry.Inputs)-1 {
79
fmt.Print(", ")
80
}
81
}
82
fmt.Println()
83
}
84
if len(entry.Outputs) > 0 {
85
fmt.Print(" Returns: ")
86
for j, output := range entry.Outputs {
87
fmt.Printf("%s (%s)", output.Name, output.Type)
88
if j < len(entry.Outputs)-1 {
89
fmt.Print(", ")
90
}
91
}
92
fmt.Println()
93
}
94
}
95
96
if len(contractABI.Entrys) > maxFunctions {
97
fmt.Printf("\n... and %d more functions\n", len(contractABI.Entrys)-maxFunctions)
98
}
99
} else {
100
fmt.Println("No function entries found in this contract's ABI.")
101
}
102
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free