Mr2C2R
Mr2C2R

Reputation: 105

send token by contract with python causing error: Validate TransferContract error, no OwnerAccount

I want to send a token by this (tron-api-python) library but I received an error When I send the Trx, there is no problem and it is sent, but when I want to send the desired token using the smart contract, I get an error.

from tronapi import Tron
from tronapi import HttpProvider

full_node = HttpProvider('https://nile.trongrid.io')
solidity_node = HttpProvider('https://nile.trongrid.io')
event_server = HttpProvider('https://nile.trongrid.io')

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

trx_kwargs = dict()
trx_kwargs["private_key"] = '59d4b72df50290d7f78e2c16fc27758d6e235f3959f2212f2497fc55da33e888'
trx_kwargs["default_address"] = 'TRNDt7bjFoTq7p52iw5u2BLNhsff1ux7Fc'
trron = Tron(**trx_kwargs)
kwargs = dict()
kwargs["contract_address"] = tron.address.to_hex("TLBaRhANQoJFTqre9Nf1mjuwNWjCJeYqUL") # USDT contract address
kwargs["function_selector"] = "transfer(address,uint256)" # function to call and types. for reference on tronscan it looks like this: transfer(address _to,uint256 _value)
kwargs["fee_limit"] = 5000000 # fee limit in tron (5 TRX here)
kwargs["call_value"] = 0 # I have no idea

Towallet = 'TTG8u8fUKqJwMtB59ppaWqgFVGDb5ojWPU'
Amount = 10.3

# added message
send = trron.trx.send_transaction(trron.address.to_hex(Towallet), Amount)

txid = send["txid"]
print(send)
print(f'your txid is {txid}')

I get this error Validate TransferContract error, no OwnerAccount.

full error:

Traceback (most recent call last):
  File "main.py", line 26, in <module>
    send = trron.trx.send_transaction(trron.address.to_hex(Towallet), Amount)
  File "/home/runner/newtrx/venv/lib/python3.8/site-packages/tronapi/trx.py", line 421, in send_transaction
    tx = self.tron.transaction_builder.send_transaction(
  File "/home/runner/newtrx/venv/lib/python3.8/site-packages/tronapi/transactionbuilder.py", line 68, in send_transaction
    response = self.tron.manager.request('/wallet/createtransaction', {
  File "/home/runner/newtrx/venv/lib/python3.8/site-packages/tronapi/manager.py", line 124, in request
    return self.full_node.request(url, json=params, method=method)
  File "/home/runner/newtrx/venv/lib/python3.8/site-packages/tronapi/providers/http.py", line 84, in request
    response = self._request(
  File "/home/runner/newtrx/venv/lib/python3.8/site-packages/tronapi/providers/http.py", line 133, in _request
    raise ValueError(data['Error'])
ValueError: class org.tron.core.exception.ContractValidateException : Validate TransferContract error, no OwnerAccount.

Upvotes: 3

Views: 1327

Answers (1)

Yilmaz
Yilmaz

Reputation: 49291

I think your private key is causing the error. Private is used to sign transactions and prove the ownership

I checked the tron docs

Account Activation

Newly created accounts do not exist on the chain, and need to be activated before they can be found via API queries or on blockchain explorer. Accounts can be activated by the following two ways:

Send any amount of TRX or TRC-10 tokens from an existing account to the new account; Call Java-tron's wallet/createaccount api to create a transaction from an existing account, then sign the transaction, and broadcast it to the TRON network. An account creation fee of 1 TRX is charged to activate a new account. Besides that, If the sender of the above two transactions has enough Bandwidth obtained by staking TRX, then creating an account will only consume bandwidth , otherwise, 0.1 TRX will be burned to pay for the bandwidth.

Alternatively, transferring TRX or TRC-10 tokens to an inactive account address in smart contract can also complete the activation of the account. In addition to the bandwidth and energy consumed by normal contract calls, this way will only consume an additional 25,000 energy, and will not consume the 1 TRX account creation fee and the 0.1 TRX bandwidth fee.

Looks like you have to activate the private key first

Upvotes: 2

Related Questions