andelf / tronpy

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

How to fix 'provided private key is not in the permission list' error? #103

Closed reza-khalafi closed 1 year ago

reza-khalafi commented 1 year ago

I try to send usdt with this code:

async def send_trc20(self, private_key, sender_address, receiver_address, amount_as_usdt):
    try:
        provider = HTTPProvider(api_key="MY_API_KEY")
        client = Tron(provider=provider)
        contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
        pv_key = PrivateKey(bytes.fromhex(private_key))
        amount = int(amount_as_usdt * 1_000_000)
       fee = 10 * 1_000_000
        txn = (
            contract.functions.transfer(receiver_address, amount)
            .with_owner(sender_address)
            .fee_limit(fee)
            .build()
            .sign(pv_key)
        )
        tx_id = txn.txid
        result = txn.broadcast().wait()
        return tx_id, result
    except Exception as e:
        print(e)
        return None, None

But get provided private key is not in the permission list error.

And create addresses with this code:

private_key = PrivateKey.random()
public_key = private_key.public_key.to_base58check_address()

But seems this address has not permission to sign trc-20. How to do this? or any suggest.

reza-khalafi commented 1 year ago

I think my private key was wrong.

MrNaif2018 commented 1 year ago

Indeed, you probably passed wrong private key. Also re-check if your address is actually activated and has TRX