apitrontrx

transfer TRC20 asset from a 'noncontract' TRX wallet to another by API


I need to transfer TRC20 token from this TRX wallet to another by API.

Since it is doesn't have TRC20 smartcontract created, I can't trigger triggersmartcontract. Is there a way how can I automatically initiate a transfer?


Solution

  • Found solution This TriggerSmartContract API with the transfer() method in USDT contract, this will create the transaction, then you'll need to sign and broadcast it. https://developers.tron.network/reference/triggersmartcontract

    and here is code example using IEXBase library

    <?php
    ini_set('display_errors', 'On');
    include_once 'vendor/autoload.php';
    
    $provider_url = 'https://nile.trongrid.io';
    
    use IEXBase\TronAPI\Tron;
    
    
    try {
        $fullNode = new \IEXBase\TronAPI\Provider\HttpProvider($provider_url);
        $solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider($provider_url);
        $eventServer = new \IEXBase\TronAPI\Provider\HttpProvider($provider_url);
    } catch (\IEXBase\TronAPI\Exception\TronException $e) {
        echo $e->getMessage();
    }
    
    
    try {
        $tron = new Tron($fullNode, $solidityNode, $eventServer);
        $tron->setPrivateKey(private_key_here);
        $contract = $tron->contract('TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj');  // Tether USDT https://tronscan.org/#/token20/TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
    
        echo  $contract->transfer('TRYQ8gSqk8BY6kqJ868UCnDqPC7LtAgaaA', '5000', 'TXKXYoNvAjHBG4vd4EJjAXuVnozrt47tnd');
    
    
    } catch (\IEXBase\TronAPI\Exception\TronException $e) {
        echo $e->getMessage();
    }