GetContract - Tron

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

protobufrpc GetContract (BytesMessage) returns (SmartContract)

Request Message

BytesMessage

FieldTypeDescription
valuebytesThe contract address as raw bytes

Request

bashgrpcurl -H 'x-api-key: <ACCESS-TOKEN>' \
  -d '{"value": "41a614f803b6fd780986a42c78ec9c7f77e6ded13c"}' \
  shared.eu-central-1.getblock.io:443 protocol.Wallet/GetContract

example.py

pythonimport 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('shared.eu-central-1.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

goconn, _ := grpc.Dial(
    "shared.eu-central-1.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

FieldTypeDescription
contract_addressbytesThe contract address
origin_addressbytesThe deployer address
abiABIThe contract ABI, when available
namestringThe contract name
bytecodebytesThe 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

CodeStatusDescription
3INVALID_ARGUMENTA request field is missing or malformed
5NOT_FOUNDThe requested account, block, or transaction does not exist
16UNAUTHENTICATEDThe access token is missing or invalid
13INTERNALThe node failed to process the request