If a contract on-chain does not have an ABI published, you can manually provide one by setting the abi property on the contract object. This allows you to call its functions using the expected signatures.
Example:
import json
from tronpy import Tron, keys
client = Tron(network='nile')
contract_address = 'TS..........'
# Define the ABI as a JSON string or list
abi_json = '''
[
{
"constant": false,
"inputs": [{"name": "min_tokens", "type": "uint256"}, {"name": "deadline", "type": "uint256"}],
"name": "trxToTokenSwapInput",
"outputs": [{"name": "", "type": "uint256"}],
"payable": true,
"stateMutability": "payable",
"type": "Function"
}
]
'''
cntr = client.get_contract(contract_address)
cntr.abi = json.loads(abi_json)
# Now you can call functions defined in the ABI
txn = (
cntr.functions.trxToTokenSwapInput.with_transfer(1_000_000_000)(1_000_000_000_000, 5)
.with_owner(from_addr)
.fee_limit(1_000_000_000)
.build()
.sign(priv_key)
)
import json
from tronpy import Tron, keys
client = Tron(network='nile')
dzi_trade = 'TS..........'
from_addr = 'TV..........'
priv_key = keys.PrivateKey(bytes.fromhex("975a..."))
abi = '''
[{"constant":false,
"inputs":[{"name":"min_tokens","type":"uint256"},{"name":"deadline","type":"uint256"}],
"name":"trxToTokenSwapInput",
"outputs":[{"name":"","type":"uint256"}],
"payable":true,
"stateMutability":"payable",
"type":"Function"}]
'''
cntr = client.get_contract(dzi_trade)
cntr.abi = json.loads(abi)
txn = (
cntr.functions.trxToTokenSwapInput.with_transfer(1_000_000_000)(1_000_000_000_000, 5)
.with_owner(from_addr)
.fee_limit(1_000_000_000)
.build()
.sign(priv_key)
)
print("txn =>", txn)
print("broadcast and result =>", txn.broadcast().wait())