iexbase / tron-api-python

A Python API for interacting with Tron (TRX)
https://tronapi-for-python.readthedocs.io
MIT License
166 stars 84 forks source link

problem when send transaction #22

Closed 0xJayShen closed 5 years ago

0xJayShen commented 5 years ago

code

tron = Tron(full_node=full_node,
        solidity_node=solidity_node,
        event_server=event_server)
balance = tron.trx.get_balance(address="418f48df84f242a7828ccb07e1ad6d087490277c9b")
# result = tron.trx.get_transaction('TxId')
tron.private_key = '3a1d6b03cd151bfbaa360fdaedb9943d275a7a0a86e3f1ebdee77e715485f8a7'
tron.default_address = '418f48df84f242a7828ccb07e1ad6d087490277c9b'

# added message
send = tron.trx.send_transaction('41a858daf83d105dd94c6e9cca1b50894c9c773b17', 1000.0, {})

then

Traceback (most recent call last):
  File "/Users/jay/Desktop/selfcode/trx/try.py", line 27, in <module>
    send = tron.trx.send_transaction('41a858daf83d105dd94c6e9cca1b50894c9c773b17', 1000.0, {})
  File "/Users/jay/anaconda3/envs/wallet/lib/python3.6/site-packages/tronapi/trx.py", line 344, in send_transaction
    sign = self.sign(tx)
  File "/Users/jay/anaconda3/envs/wallet/lib/python3.6/site-packages/tronapi/trx.py", line 486, in sign
    address = self.tron.address.from_private_key(self.tron.private_key).hex.lower()
  File "/Users/jay/anaconda3/envs/wallet/lib/python3.6/site-packages/tronapi/base/account.py", line 35, in from_private_key
    return PrivateKey(private_key).address
  File "/Users/jay/anaconda3/envs/wallet/lib/python3.6/site-packages/tronapi/base/account.py", line 46, in __init__
    _private = unhexlify(bytes(private_key, encoding='utf8'))
TypeError: encoding without a string argument

what should i do,I tried a lot about methods of str and bytes

serderovsh commented 5 years ago

I do not observe problems, all actions are performed.

0xJayShen commented 5 years ago

@serderovsh can you show me code?include address and private_key(test_net)

serderovsh commented 5 years ago
from tronapi import Tron

full_node = 'https://api.shasta.trongrid.io'
solidity_node = 'https://api.shasta.trongrid.io'
event_server = 'https://api.shasta.trongrid.io'

tron = Tron(full_node=full_node,
            solidity_node=solidity_node,
            event_server=event_server)

tron.private_key = 'da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0'
tron.default_address = tron.address.from_private_key(tron.private_key).base58
print(tron.trx.send('TGEJj8eus46QMHPgWQe1FJ2ymBXRm96fn1', 0.001))

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18)

serderovsh commented 5 years ago

Your implementation is also correct!

0xJayShen commented 5 years ago

@serderovsh your code is right,mine is wrong,But I don't know why

serderovsh commented 5 years ago
tron = Tron(full_node=full_node,
        solidity_node=solidity_node,
        event_server=event_server)
balance = tron.trx.get_balance(address="418f48df84f242a7828ccb07e1ad6d087490277c9b")
# result = tron.trx.get_transaction('TxId')
tron.private_key = '3a1d6b03cd151bfbaa360fdaedb9943d275a7a0a86e3f1ebdee77e715485f8a7'
tron.default_address = 'TP2pvob6fEyfycEQydmjwc8L1VwLS7izV6'

# added message
send = tron.trx.send_transaction('41a858daf83d105dd94c6e9cca1b50894c9c773b17', 1000.0)

Check out

serderovsh commented 5 years ago

It makes no sense to specify the format of the address "41", use the standard formats "T". If necessary, the plugin itself converts it into the required format.

0xJayShen commented 5 years ago

@serderovsh what is default_address,That's why I was wrong

serderovsh commented 5 years ago

418f48df84f242a7828ccb07e1ad6d087490277c9b -> HEX TP2pvob6fEyfycEQydmjwc8L1VwLS7izV6 -> Base58

# It was
tron.default_address = '418f48df84f242a7828ccb07e1ad6d087490277c9b'
# changed to
tron.default_address = 'TP2pvob6fEyfycEQydmjwc8L1VwLS7izV6'
0xJayShen commented 5 years ago

@serderovsh thanks !It helps.

serderovsh commented 5 years ago

This defect will be fixed soon. And then there will be no problems with address formats.

0xJayShen commented 5 years ago

@serderovsh Thank you for doing that