For the complete documentation index, see llms.txt. This page is also available as Markdown.

GetContract - Tron

Example code for the GetContract gRPC method. Complete guide on how to use GetContract gRPC method in GetBlock Web3 documentation.

This method returns the metadata and ABI of a smart contract deployed at an address.

Service

This method is served by the protocol.Wallet service.

Method

rpc GetContract (BytesMessage) returns (SmartContract)

Request Message

BytesMessage

Field
Type
Description

value

bytes

The contract address as raw bytes

Request

grpcurl -H 'x-api-key: <ACCESS-TOKEN>' \
  -d '{"value": "41a614f803b6fd780986a42c78ec9c7f77e6ded13c"}' \
  go.getblock.io:443 protocol.Wallet/GetContract
example.py
import grpc
# Stubs generated from java-tron's api.proto with grpcio-tools
from api import api_pb2_grpc
from core import Contract_pb2, Tron_pb2

creds = grpc.ssl_channel_credentials()
channel = grpc.secure_channel('go.getblock.io:443', creds)
metadata = [('x-api-key', '<ACCESS-TOKEN>')]
stub = api_pb2_grpc.WalletStub(channel)

response = stub.GetContract(api_pb2.BytesMessage(value=bytes.fromhex('41a614f803b6fd780986a42c78ec9c7f77e6ded13c')), metadata=metadata)
print(response)
example.go
conn, _ := grpc.Dial(
    "go.getblock.io:443",
    grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
)
defer conn.Close()

client := api.NewWalletClient(conn)
ctx := metadata.AppendToOutgoingContext(
    context.Background(), "x-api-key", "<ACCESS-TOKEN>")

resp, _ := client.GetContract(ctx, &api.BytesMessage{Value: contractBytes})
fmt.Println(resp)

Response Message

SmartContract

Field
Type
Description

contract_address

bytes

The contract address

origin_address

bytes

The deployer address

abi

ABI

The contract ABI, when available

name

string

The contract name

bytecode

bytes

The contract's deployed bytecode

Use Cases

  • ABI Retrieval: Read a contract's ABI to encode calls

  • Contract Inspection: Read a contract's name and deployer

  • Bytecode Reads: Retrieve deployed bytecode

  • Verification: Confirm a contract exists at an address

Error Handling

Code
Status
Description

3

INVALID_ARGUMENT

A request field is missing or malformed

5

NOT_FOUND

The requested account, block, or transaction does not exist

16

UNAUTHENTICATED

The access token is missing or invalid

13

INTERNAL

The node failed to process the request

Was this helpful?