HomeGuidesAPI ReferenceChangelog
GuidesAPI ReferenceCommunityDiscordBlogFAQBug BountyAnnouncementsChange Log
Guides

TRC10 & TRX Transfer

Introduction

There are 4 types of contracts in TRON for TRX and TRC10 transfers:

  • TransferContract
  • TransferAssetContract
  • CreateSmartContract
  • TriggerSmartContract

Transactions that have been packaged into the blockchain can use the GetTransactionbyId interface to get the details of the transaction, you can use GetTransactionInfoById to get the execution result of the specified transaction.How to confirm a transaction:https://developers.tron.network/docs/transaction

TransferContract for external account transfer trx assets to external accounts,TransferAssetContract for external account transfer TRC10 assets to external accounts.

TransferContract

  • owner_address (Bytes) TRX sender address

  • to_address (Bytes) TRX recipient address

  • amount (int64) the amount of TRX to send

TransferAssetContract

  • asset_name (String) TRC10 ID

  • owner_address (Bytes) TRC10 sender address

  • to_address (Bytes) TRC10 recipient address

  • amount (int64) the amount of TRX to send

CreateSmartContract is used to deploying smart contracts,Deploying smart contracts can also transfer trx and TRC10 assets to contracts.TriggerSmartContract is used to call contract functions,Transferring the contract to the trx and TRC10 assets while calling the contract.

CreateSmartContract

  • owner_address (Bytes) Contract caller address

  • SmartContract.contract_address (Bytes) Contract address

  • SmartContract.call_value (int64) The amount of TRX sent to smart contract

  • call_value (int64) The amount of TRX sent to smart contract

  • call_token_value (int64) The amount of TRC10 sent to Smart

  • token_id (String) TRC10 ID

TriggerSmartContract

  • owner_address (Bytes) Smart Contract Deployer Address

  • contract_address (Bytes) Contract address

  • call_value (int64) The amount of TRX sent to smart contract

  • call_token_value (int64) The amount of TRC10 sent to Smart

  • token_id (String) TRC10 ID.

External address transfer TRX and TRC10 to contract address

After the Java-tron 3.6.5 update and after #32 proposal is passed.the external address can not transfer TRC10 and TRX asset to the contract using TransferContract and TransferAssetContract.

If the user still transfers TRC10 and TRX to the contract using TransferContract and TransferAssetContract, an exception of type ContractValidateException will be returned.The exception messages are "Cannot transfer TRX to a smartContract. and "Cannot transfer asset to smartContract"

These two return values can help the user to determine that a wrong transfer is being made to a contract.

Note:You can also use the /wallet/getaccount interface to determine if an address is a contract address,Then decide what method to use to transfer asset to the address.If there is a “type” field in the interface return value,and the value of the field is "Contract" indicating that the address is a contract address

If the external address needs to be transfer TRX and TRC10 to the contract address, you can use the following methods:

1.The contract has a payback modified fallback method

You can transfer the contract by calling the contract's fallback method,The following example,Specify function_selector as "()":

curl -X POST \
  https://api.shasta.trongrid.io/wallet/triggersmartcontract \
    -d '{
    "contract_address": "417FFF5C4448DD213EDAF4BEA5A342265BB0E364FD",
    "function_selector": "()",
    "parameter": "",
    "fee_limit": 1000000,
    "call_value": 1000,
    "call_token_id":1000123,
    "call_token_value":1,
    "owner_address": "41173EBB4F23DBDC69F31065D7F8D2DACAB32E004F"
}'

2. The contract does not exist any payable entry

In principle, it is recommended that the developer reserve the function of the transfer for the contract.For contracts that have already been deployed, the following contract code can be deployed,Forced transfer of target contracts by suicide,selfdestruct function destroys a contract and forces the transfer of the TRX or TRC10 balance to toAddress::

// solidity source code
pragma solidity 0.5.8;
contract ForceTransfer{
       constructor(address payable toAddress) public payable{
              selfdestruct(toAddress);
       }
}

Call wallet/deploycontract to deploy the contract and trigger selfdestruct to force the transfer:

curl -X POST \
  https://api.shasta.trongrid.io/wallet/deploycontract \
  -d '{
    "owner_address": "4108c5b06bc93d2f6749991057f8189a31d525e392",
    "fee_limit": 1000000000,
    
    "consume_user_resource_percent": "100",
    "origin_energy_limit": "1000000",
    "abi": "[{\"inputs\":[{\"name\":\"toAddress\",\"type\":\"address\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"}]",
    "bytecode": "6080604052604051602080604c83398101806040526020811015602157600080fd5b81019080805190602001909291905050508073ffffffffffffffffffffffffffffffffffffffff16fffe",
    "parameter": "00000000000000000000000008c5b06bc93d2f6749991057f8189a31d525e392",
    "name": "ForceTransfer",
    "call_value": 10,
    "token_id": 1000008,
    "call_token_value": 100
}'