0

I’ve been using TronWeb for a while to collect and summarize information about my Tron addresses, and that works fine. Now I want to start creating transactions, so I figured a simple one would be to send some TRX between addresses. I got as far creating a transaction (not even signing or broadcasting it) before I ran into a problem, in that creating a transaction to send TRX to an uninitialized address sometimes fails when I think it should succeed.

Here’s the test JavaScript I’ve been using:

async function testTronWeb() {
    const initAddr = 'initialized address';
    const newAddr = 'uninitialized address';
    const fromAddrs = ['addr1', 'addr2', 'addr3', 'addr4',];
    const tronWeb = new TronWeb({fullHost: 'https://api.trongrid.io'});
    const amount = 100000;
    let r, s, t;

    for (let a of fromAddrs) {
        r = await tronWeb.trx.getAccount(a);

        s = a + ' (' + r.balance / 1e6 + ') ' + amount / 1e6 + ' => ';
        t = s + 'initialized address ';

        try {
            r = await tronWeb.transactionBuilder.sendTrx(initAddr, amount, a);

            console.log(t + 'succeeded');
        }
        catch (r) { console.log(t + 'failed', r);}

        t = s + 'uninitialized address ';

        try {
            r = await tronWeb.transactionBuilder.sendTrx(newAddr, amount, a);

            console.log(t + 'succeeded');
        }
        catch (r) { console.log(t + 'failed', r); }
    }
}

When I run it, here’s the console output (edited as I’ll explain below):

addr1 (0.177875) 0.1 => uninitialized address failed
addr2 (0.781572) 0.1 => uninitialized address failed
addr3 (1.134105) 0.1 => uninitialized address succeeded
addr4 (5.000012) 0.1 => uninitialized address succeeded

addr1 (0.177875) 0.5 => uninitialized address failed
addr2 (0.781572) 0.5 => uninitialized address failed
addr3 (1.134105) 0.5 => uninitialized address failed
addr4 (5.000012) 0.5 => uninitialized address succeeded

I’ve dropped the log entries for sending to an initialized address, as they all work as expected (or fail as expected in the one case it should fail). I’ve also dropped the result when creating the transaction fails, because it’s always:

class org.tron.core.exception.ContractValidateException : Validate TransferContract error, balance is not sufficient.

So, the crux of the issue—I don’t understand why the failed transaction creations fail. The sending addresses have enough TRX, and the amount being sent should be enough to initialize the receiving address. Any ideas?

Here are the answers to a few questions I can see being asked:

  • I don’t want to share the addresses so I can’t present an actual runnable version. I realize that might limit the answers I receive (if any).
  • All the addresses are valid base58 addresses. I tried the equivalent hex addresses as well, with (as expected) no change in behavior.
  • All the addresses are initialized (have had TRX sent to them at some point) except the one called 'uninitialized address' here.
  • All the addresses (again, except for the uninitialized one, but I’m not sending from that) have plenty of bandwidth (I don’t know if just creating a transaction checks the bandwidth available or not. I wouldn’t think so, but if it does they do). They have lots of energy too, but that shouldn’t be relevant just sending TRX.
  • When I get to signing I’ll be using TronLink. I’ve played around with it and it seems to work as expected.
blm
  • 2,379
  • 2
  • 20
  • 24

0 Answers0