andelf / tronpy

TRON Python Client Library.
MIT License
204 stars 96 forks source link

How to calculate "parameter" for "trigger_constant_contract" method? #104

Closed reza-khalafi closed 1 year ago

reza-khalafi commented 1 year ago

I need to calculate energy_used so use tron.trigger_constant_contract like this:

    result = tron.trigger_constant_contract(
        owner_address="TQYbVpBqboaQu4rc4bLuD9VUqNAAAAAAA",
        contract_address="TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
        function_selector="transfer (address, uint256)",
        parameter="" # ?
    )
    print(result)

And for calculate parameter i used this:

    with open("abi/trc20_abi.json") as f:
        info_json = json.load(f) # from tronscan
    bytecode = '60806040526000...' # from tronscan
    cntr = Contract(name="TetherToken", bytecode=bytecode, abi=info_json)
    parameter = cntr.constructor.encode_parameter("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", 18) # like tronpy document
    print(parameter)

So get this error: TypeError: wrong number of arguments, require 4 got 2

What is 18 in this method? What is the problem? Is there better way?

MrNaif2018 commented 1 year ago

See an example here: https://github.com/bitcart/bitcart/blob/c1715ed9c302b5d2c92003d172a94467b4523284/daemons/trx.py#L388-L399