andelf / tronpy

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

Delegating energy using permission from another wallet #139

Open Kranthos opened 2 weeks ago

Kranthos commented 2 weeks ago

I have two wallets

  1. bot's wallet: the one with the Private Key for the delegation.
  2. sender's wallet: I want to delegate energy from this wallet but I don't want to use the Private Key instead I gave permission to delegate energy to the bot wallet from this one.

The code roughly looks like this but it always returns tronpy.exceptions.BadKey: ('provided private key is not in the permission list', 'provided BOT_WALLET_ADDRESS', "required {'operations': '7fff1fc0033ec307000000000000000000000000000000000000000000000000', 'keys': [{'address': 'some_address_here', 'weight': 1}], 'threshold': 1, 'id': 2, 'type': 'Active', 'permission_name': 'active'}")

client = Tron(HTTPProvider(api_key="API_KEY"))
priv_key = PrivateKey(bytes.fromhex("BOT_WALLET_PRIVATE_KEY"))

txn = (
    client.trx.delegate_resource(owner=SENDER_WALLET, receiver=RECEIVER_WALLET, balance=1, resource="ENERGY")
    .permission_id(2)
    .build()
    .sign(priv_key)
    .broadcast()
)
txn.wait()

I have also tried with with_owner(SENDER_WALLET) and owner=BOT_WALLET but nothing seems to work.

What's wrong with the code? and is it even possible though the API to delegate energy from another wallet assuming it gave permission to the bot's wallet?