stoway / TronNet

.net sdk of tron
MIT License
69 stars 43 forks source link

The account is out of energy, or the contract's fee limit has been exceeded. #12

Closed daustany closed 3 years ago

daustany commented 3 years ago

I have a main account with about 1500TRX and enough energy & bandwidth in it.

I went through several steps:

1) Generate a new address and get its private key 2) Trying to transfer some TRC20 contracted token to above new generated address by below code:

@) When I transfer some token by my tronlink wallet to this new generated address, transfer will succeed, but when I'm using below code I get error :

The account is out of energy, or the contract's fee limit has been exceeded. https://tronscan.io/#/transaction/714c0a87220765b223c429802814ce8f0eb5a5dfb1e7eb60243ab5ab008a9119?lang=en

BUT I have enough energy !

using TronNet;
using System.Threading.Tasks;
using Google.Protobuf;
using Microsoft.Extensions.Options;

namespace TronNetTest
{
    class Class1
    {
        private readonly IWalletClient _wallet;
        private readonly IContractClientFactory _contractClientFactory;

        public Class1(IWalletClient wallet, IContractClientFactory contractClientFactory)
        {
            _wallet = wallet;
            _contractClientFactory = contractClientFactory;
        }

        public async Task TransferAsync()
        {
            var privateKey = "000000000000-PRIVATE-KEY-EXAMPLE-00000000000";
            var account = _wallet.GetAccount(privateKey);

            var contractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; //USDT Contract Address
            var to = "00000000-NEW-GENERATED-ADDRESS-0000000000";
            var amount = 10; //USDT Amount
            var feeAmount = 5 * 1000000L;
            var contractClient = _contractClientFactory.CreateClient(ContractProtocol.TRC20);

            var result = await contractClient.TransferAsync(contractAddress, account, to, amount, string.Empty, feeAmount);
        }
    }
}
stoway commented 3 years ago

You need change feeAmount value, because tron fee amount is increase.