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
| Field | Type | Description |
|---|---|---|
| value | bytes | The 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/GetContractexample.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
| 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 |