Code Monkey home page Code Monkey logo

tronnet's People

Contributors

stoway avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tronnet's Issues

Received http2 header with status: 503

I am running my website on Windows Server IIS 10 and I am using .NET 5 integrated with Angular.

I have some problem using any APIs of TronNet on production environment.
everything work fine on localhost but when I deploy on server I get below error:

Grpc.Core.RpcException: Status(StatusCode="Cancelled", Detail="Received http2 header with status: 503")

at TronNet.Contracts.TRC20ContractClient.BalanceOfAsync(String contractAddress, ITronAccount ownerAccount)

On the other hand, I simply GetBalanceAsync of an address, in one of my web page work correctly and get balances, but on other pages I get the error !

Also, in those pages that I have problem to getting the balance for example, it work on the first try, but when I refresh the page I get the error !

The code that I get contract balance is :

private async Task<decimal> GetContractBalance(string contractAddress, string privateKey)
{
            decimal balance = 0;
            var contractClient = _contractClientFactory.CreateClient(ContractProtocol.TRC20);
            ITronAccount tronAccount = _tronWalletClient.GetAccount(privateKey);

            balance = await contractClient.BalanceOfAsync(contractAddress, tronAccount); // Error

            return balance;
}

How to get USDT and TRX balance?

Hi,
I have tested this library on mainnet as well as testnet and it's working perfectly on both. I'm able to transfer TRX and USDT from one account to another, I have one question though, how can I know the balance of TRX and USDT? couldn't find any example.

Thanks.

UPDATE:
I'm able to get USDT account balance using this code

var account = _wallet.GetAccount(fromKey); var contractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; var contractClient = _contractClientFactory.CreateClient(ContractProtocol.TRC20); return contractClient.BalanceOfAsync(contractAddress, account);

Still not able to get TRX balance.

When query contract balance, got error: Value was either too large or too small for an Int64.

[ERR] Value was either too large or too small for an Int64.
System.OverflowException: Value was either too large or too small for an Int64.
at System.Numerics.BigInteger.op_Explicit(BigInteger value)
at TronNet.ABI.Decoders.IntTypeDecoder.DecodeLong(Byte[] encoded)
at TronNet.ABI.Decoders.IntTypeDecoder.Decode(Byte[] encoded, Type type)
at TronNet.ABI.FunctionEncoding.ParameterDecoder.DecodeOutput(Byte[] outputBytes, ParameterOutput[] outputParameters)
at TronNet.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes(Byte[] output, Object result, PropertyInfo[] properties)
at TronNet.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes(String output, Object result, PropertyInfo[] properties)
at TronNet.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes[T](String output, T result, PropertyInfo[] properties)
at TronNet.ABI.FunctionEncoding.FunctionCallDecoder.DecodeFunctionOutput[T](T functionOutputResult, String output)
at TronNet.ABI.FunctionEncoding.FunctionCallDecoder.DecodeFunctionOutput[T](String output)
at TronNet.Contracts.TRC20ContractClient.BalanceOfAsync(String contractAddress, ITronAccount ownerAccount)

按交易哈希查询交易GetTransactionById

按交易哈希查询交易GetTransactionById,如何解析这个接口返回的数据 我要取得发送地址,接收地址和金额,有偿。
这下面是返回的 要解析parameter.value.data的数据
{
"ret":[
{
"contractRet":"SUCCESS"
}
],
"signature":[
"4a7e494686ee3f0e3e288fabee9612a4d83f30b99e4b543b4f5da053dd481b91c35ebdf5568e325136371ed47303a8e6acd1ca419532d77c494636324fb42a7201"
],
"txID":"d1c8d6461bd5a67e79359c27480745329c4f53cb82ff8ee1379f9eaa5dd17709",
"raw_data":{
"contract":[
{
"parameter":{
"value":{
"data":"7688415300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000002710000000000000000000000000af8a80171afcca0a76d33ec56f6e3000bceab5ef0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000f09afffc8b64bca573deb35d12ff9b9c69497075",
"owner_address":"419e1d445505e6acea6372c69c4afbe6c0c76f8587",
"contract_address":"412e598a00d210f294d54bb7b1b8d008558d67d2e7"
},
"type_url":"type.googleapis.com/protocol.TriggerSmartContract"
},
"type":"TriggerSmartContract"
}
],
"ref_block_bytes":"7497",
"ref_block_hash":"1fc27e8ca4b6cc9f",
"expiration":1626706053000,
"fee_limit":300000000,
"timestamp":1626705994921
},
"raw_data_hex":"0a02749722081fc27e8ca4b6cc9f40888ff2f9ab2f5a9002081f128b020a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412d5010a15419e1d445505e6acea6372c69c4afbe6c0c76f85871215412e598a00d210f294d54bb7b1b8d008558d67d2e722a4017688415300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000002710000000000000000000000000af8a80171afcca0a76d33ec56f6e3000bceab5ef0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000f09afffc8b64bca573deb35d12ff9b9c6949707570a9c9eef9ab2f900180c6868f01"
}

TronNet suddenly stop working !

It was working, suddenly has stopped with no reason !

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter "Illegal character ‏ at 0")
at TronNet.Crypto.Base58Encoder.Decode(String input)
at TronNet.Crypto.Base58Encoder.DecodeFromBase58Check(String addressBase58)
at TronNet.Contracts.TRC20ContractClient.TransferAsync(String contractAddress, ITronAccount ownerAccount, String toAddress, Decimal amount, String memo, Int64 feeLimit)

在VS中发布时选择生成单个文件,运行时会报异常

在VS中发布时选择生成单个文件,运行时会报异常
查找相关资料,是引用的GRPC包引起的,在更新的GRPC版本中修复了该问题
System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.IO.Path.Combine(String path1, String path2)
at Grpc.Core.Internal.NativeExtension.LoadUnmanagedLibrary()
at Grpc.Core.Internal.NativeExtension.LoadNativeMethods()
at Grpc.Core.Internal.NativeExtension..ctor()
at Grpc.Core.Internal.NativeExtension.Get()
at Grpc.Core.Internal.NativeMethods.Get()
at Grpc.Core.GrpcEnvironment.GrpcNativeInit()
at Grpc.Core.GrpcEnvironment..ctor()
at Grpc.Core.GrpcEnvironment.AddRef()

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

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);
        }
    }
}

How to recover an address from signature

Hey, this isn't a bug issue. Is it possible to recover an Address from a signed message and the original message? I looked at the ECKey class and that seemed to have the methods I want, but I don't see where it would verify a user's address.

能帮忙解决下这个签名验证的问题 :前端用 tronweb.sign(), 后台怎么进行地址验证

     var data= window.tronWeb.toHex('key');
     console.log(data);
     window.tronWeb.trx.sign(data).then((sign) => {
        console.log(sign)
        var url="/Public/login";
        var data={
              address:App.address,
              password:this.password,
              intro:this.intro,
              sign:sign
             };
        $.post(url,data,function(res){
              if(res.status==0)
              tips(res.info)
              else
              {
               window.sessionStorage.setItem('login',1)
                window.sessionStorage.setItem('loginAddress',App.address)
               window.location=res.url
              }
                 
        })    
     })

Query balance overflow

TRC20ContractClient

var balance = Convert.ToDecimal(result.Balance);
if (decimals > 0)
{
balance /= Convert.ToDecimal(Math.Pow(10, decimals));
}

Change to

var balance = Nethereum.Web3.Web3.Convert.FromWeiToBigDecimal(result.Balance);

            return decimal.Parse(balance.ToString());

Get recent transactions for an account

How to get the last transactions for an account? I'm trying to check if a payment posted I would like a list of the transactions for an account. I haven't been able to figure out how to.

Contract validate error : Smart contract is not exist.

When I use demo with 'TransferAsync',but found some wrong with it!
var contractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
wallet.TriggerConstantContract()
{{ "code": "CONTRACT_VALIDATE_ERROR", "message": "Q29udHJhY3QgdmFsaWRhdGUgZXJyb3IgOiBTbWFydCBjb250cmFjdCBpcyBub3QgZXhpc3Qu" }}
Thanks!

Contract transfer not working properly

I can successfully sign and broadcast TRX transactions and get account balance, but transferring tokens is not working for me.
My code:

public async Task<string> TransactionToken(string contractAddress, string privateKey, string toAddress, decimal amount)
{
    try
    {
        var account = _walletClient.GetAccount(privateKey);
        var contractClient = _contractClientFactory.CreateClient(ContractProtocol.TRC20);
        var result = await contractClient.TransferAsync(contractAddress, account, toAddress, amount, string.Empty, 5 * 1000000L);

        return result;
    }
    catch (Exception)
    {
        return null;
        throw;
    }
}

I get a txid in the response and it seems that everything's working fine, but the transaction is not happening on the network and I can't find the txid on tronscan.

balace of account

First of all thanks for your library. Is there a sample to get balace of account for tron and tron's tokens like usdt?
I can not find any ducument for TronNet.

sigerror

Hello,
I am getting sigerror error.
Sample 3: I tried Contract TRC20 Transfer (USDT) and there was no transaction.
I tried Sample 2: Transaction Sign Offline but it didn't work there either. There is a problem with the trongrid.io installer.
How do they do this.

program.cs
using TronNet;
builder.Services.AddTronNet(x =>
{
x.Network = TronNetwork.MainNet;
x.Channel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50051 };
x.SolidityChannel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50052 };
x.ApiKey ="myapikey";
});

homecontroller.cs
using TronNet;
var privateKey = "8e812436a0e3323166e1f0e8ba79e19e217b2c4a53c970d4cca0cfb1078979df";
string fromAddress = "TFbrUmaS8Zqdbsw92GDoqx6nH2U9GoosrS";
var account = new Lottery.WebUi.Models.TronAccount()
{
Address = fromAddress,
PrivateKey = privateKey,
PublicKey = "04a5bb3b28466f578e6e93fbfd5f75cee1ae86033aa4bbea690e3312c087181eb366f9a1d1d6a437a9bf9fc65ec853b9fd60fa322be3997c47144eb20da658b3d1"
};
var ecKey = new TronECKey(privateKey, _options.Value.Network);
var from = "TFbrUmaS8Zqdbsw92GDoqx6nH2U9GoosrS";
var to = "TDRK6kQnc55EWkFL4bvv8Fefdbt3HfsiE9";
var amount = 5_000_000L;
var transactionExtension = await _transactionClient.CreateTransactionAsync(from, to, amount);
var transactionSigned = _transactionClient.GetTransactionSign(transactionExtension.Transaction, privateKey);
var result = await _transactionClient.BroadcastTransactionAsync(transactionSigned); // return false, sigerror

2023-05-20_14h31_27
2023-05-20_14h32_31
2023-05-20_14h33_12

TRC20 event listener

Hi. can I use this package to listen to trc20 contract of a tron wallet address?

Why am I getting this warning?

image

Regardless how I re-package and build it. I got this warning when I try to debug.

Is the DLL hidden somewhere deep inside? I am afraid a bogus DLL trying to steal our private key.

Scan 100,000 wallets and get notified after receiving coins

I have a question.
I have 100,000 wallet addresses and I want to be notified immediately if a token is deposited into it, like a webhook / event listener or something like that.
Is there a way that is basic and we can do it? Like wallet applications, in the past I used to regularly query and compare transactions, but this is not good at all.

Example:
https://api.trongrid.io/v1/accounts/{address}/transactions/trc20?only_confirmed=true&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t&only_to=true&limit=200

for each address

Balances

Hello. I'm new to tron. I have problems acquiring balances. I've registred on trongrid.io, issued an apikey and generated an account using wallet.GenerateAccount().

  1. protocol.GetAccountAsync returns empty account, whith nothing whithin it, I have no balances, but everything is null or 0, is it ok?
  2. contractClient.BalanceOfAsync throws exception with message "Contract validate error : Smart contract is not exist.". Do I need to create something to use usdt over tron network?

This is full code of my test program:

        static decimal GetTRXBalance(IWalletClient _walletClient, string address)
        {
            var protocol = _walletClient.GetProtocol();
            var addr = _walletClient.ParseAddress(address);
            var result = Task.Run(async () => await protocol.GetAccountAsync(new Account
            {
                Address = addr
            }));

            var account = result.GetAwaiter().GetResult();

            var balance = Convert.ToDecimal(account.Balance) / 1_000_000L;

            return balance;
        }

        static decimal GetUSDTBalance(IWalletClient _walletClient, IContractClient _contractClient, string privatekey, string contractAddress)
        {
            var tronacc = _walletClient.GetAccount(privatekey);
            Task<decimal> result = Task.Run(async () => await _contractClient.BalanceOfAsync(contractAddress, tronacc));
            var account = result.GetAwaiter().GetResult();

            return account;
        }

        static void test()
        {
            IServiceCollection services = new ServiceCollection();
            services.AddTronNet(x =>
            {
                x.Network = TronNetwork.MainNet;
                x.Channel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50051 };
                x.SolidityChannel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50052 };
                x.ApiKey = "apikey";
            });
            services.AddLogging();
            var service = services.BuildServiceProvider();

            var wallet = service.GetService<IWalletClient>();
            var contract = service.GetService<IContractClientFactory>().CreateClient(ContractProtocol.TRC20);

            //TJy97mgrgBmko6Nuzjx3RYG6oN6LqW8ykr
            //b6b5f0d3ca6b26ac143b70116454a273b26952c4b2fe8e4615e7175f95495b8e
            //04df8eb6ea14fbd72ca3cd121fdf1ad530f80c93091ed7c6e1a47a018ab1a276fcadb74beaf92775d54767c4694dd5351dbe7aaceea2df7144aeb9246f44c44244
            //var tronacc = wallet.GenerateAccount();

            decimal trx = GetTRXBalance(wallet, "TJy97mgrgBmko6Nuzjx3RYG6oN6LqW8ykr");
            decimal usdt = GetUSDTBalance(wallet, contract, "b6b5f0d3ca6b26ac143b70116454a273b26952c4b2fe8e4615e7175f95495b8e", "TJy97mgrgBmko6Nuzjx3RYG6oN6LqW8ykr");

            ;
        }

        static void Main(string[] args)
        {
            test();
        }

Tron 离线签名交易

{ "code": "TAPOS_ERROR", "message": "VGFwb3MgY2hlY2sgZXJyb3I=" } 报双花问题,请问这个怎么解决

How can I use multiple API keys in a project?

Hi Stoway,

As you mention before about IP frequency limits of using the TronGrid GRPC service that is 15QPS,
I read about it on
https://developers.tron.network/docs/faq#10how-to-solve-the-error-of-trongrid-503-service-temporarily-unavailable
So I realized that we have 15QPS per API keys.

Is there any possibility to use multiple API keys in one project?
I think if I devide my requests and send them to specific API key I may have more ability to manage my requests.

I use below configuration on my .NET 5 startup.cs:

services.AddTronNet(x =>
            {
                x.Network = TronNetwork.MainNet;
                x.Channel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50051 };
                x.SolidityChannel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50052 };
                x.ApiKey = _appConfiguration["Tron:APIKey"].ToString();
            });

Corrupted nuget package

Nuget package seems to be broken and have unresolved dependency to its other projects.
also there is an unnecessary dependency to StowayNet.Extensions.DependencyInjection project which can be removed and use dotnet core build-in di.

Error When Calling BalanceOfAsync

I got an error when calling BalanceOfAsync
ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'index')
Google.Protobuf.Collections.RepeatedField.get_Item(int index)
TronNet.Contracts.TRC20ContractClient.GetDecimals(WalletClient wallet, byte[] contractAddressBytes)
TronNet.Contracts.TRC20ContractClient.BalanceOfAsync(string contractAddress, ITronAccount ownerAccount)
CryptoPayment.WebUI.Controllers.WeatherForecastController.Get(IWalletClient _wallet, IContractClientFactory

my code:
var balance = await contractClient.BalanceOfAsync("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", wallet);

Send USDT Not Working

Hello All,
My Code:

 IServiceCollection services = new ServiceCollection();
            services.AddTronNet(x =>
            {
                x.Network = TronNetwork.MainNet;
                x.Channel = new GrpcChannelOption { Host = "grpc.trongrid.io"};
                x.SolidityChannel = new GrpcChannelOption { Host = "grpc.trongrid.io"};
                x.ApiKey = "3334986a-****";
            });


            services.AddLogging();

            var service = services.BuildServiceProvider();
            var walletClient = service.GetService<IWalletClient>();

            var account = walletClient.GetAccount(walletPrivateKey);

            //USDT TOKEN
            var contractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";

            //收的錢包
            var to = "TLhTDxNcm9XaSq35mghq6Az35LeHdcn77S";

            var amount = 1;
            //手續費 10 TRX
            var feeAmount = 20 * 1_000_000L;

            var contractClientFactory = service.GetService<IContractClientFactory>();

            var contractClient = contractClientFactory.CreateClient(ContractProtocol.TRC20);

            //備註只能用英文
            var result = contractClient.TransferAsync(contractAddress, account, to, amount, "Test", feeAmount);

            Console.WriteLine("-- RESULT --");
            Console.WriteLine(JsonConvert.SerializeObject(result));

result = Id = 1, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"

Some issues need to be fixed!

  1. BalanceOfFunctionOutput unit256 should convert to BigInteger instead of long

    public class BalanceOfFunctionOutput : IFunctionOutputDTO
    {
    [Parameter("uint256", 1)]
    public BigInteger Balance { get; set; }
    }

  2. BalanceOfAsync() should allow to pass in an Account with only PublicKey. There is no reason we need to have access to PrivateKey just to query for the balance. Look into the code and you should notices that the PrivateKey passed in is not used at all.

and since #1 had been changed to BigInteger, the following line in BalanceOfAsync() shall change to

 // var balance = Convert.ToDecimal(result.Balance);
 var balance = (decimal)result.Balance;
  1. The following code won't compile without explicitly cast the result to (byte)

    internal byte GetPublicAddressPrefix()
    {
        return (byte)(_network == TronNetwork.MainNet ? 0x41 : 0xa0);
    }
    

"code": "SIGERROR", "message" when broadcast my transaction ?

{{ "code": "SIGERROR", "message": "VmFsaWRhdGUgc2lnbmF0dXJlIGVycm9yOiA3Y2I2OTRkZTQwMTI2MWUwMmRjOWU2MjZlNzU3MWJjMGRkNzliNGI5YjJlZmE0MDhmMmU5YzlkNzUwMTRiM2UxMGIzOTEwZDA1ZTIwYjJjY2VhMDAzZTRmZjk2YTA5NWNmZTY2ZDVlMzA2YzE2NzNiZGJmYTY4MTIwNDBiYTZmODAwIGlzIHNpZ25lZCBieSBUVFdrRjFYdnBxZE5qazNFWUZDb1BjSEZydUdOQlNKVkJzIGJ1dCBpdCBpcyBub3QgY29udGFpbmVkIG9mIHBlcm1pc3Npb24u" }}

GenerateKey function

There is a sample code like below in your github page but there not GenerateKey() function in the TronClient classs.

    public void GenerateAddress()
    {
        var key = _tronClient.GenerateKey();

        var address = key.GetPublicAddress();
    }

I can't send usdt from trc20.

Hello,
I can't find where the error is in my work in core 6 :(
I searched many articles and when I finally ran it, the result was "b8107a19cb24e2ffe69b2b45a9499c1bf1bc78f0a54223569a48b6e311df3903". I don't know where to use this incoming information. How do I access the txID? Is this the result of the txID?
I wonder if it is due to the api settings in trongrid.io. Can you help me.

program.cs
builder.Services.AddTronNet(x =>
{
x.Network = TronNetwork.MainNet;
x.Channel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50051 };
x.SolidityChannel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50052 };
x.ApiKey ="myapikey"
});

TronAccount.cs
namespace .WebUi.Models
{
public class TronAccount : ITronAccount
{
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
public string Address { get; set; }
public byte GetAddressPrefix()
{
throw new NotImplementedException();
}
}
}

homecontroller.cs
using TronNet;

private readonly IWalletClient _wallet;
private readonly IContractClientFactory _contractClientFactory;

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

public async Task Index()
{
var privateKey = "8e812436a0e3323166e1f0e8ba79e19e217b2c4a53c970d4cca0cfb1078979df";
string fromAddress = "TFbrUmaS8Zqdbsw92GDoqx6nH2U9GoosrS";

var account = new WebUi.Models.TronAccount()
{
	Address = fromAddress,
	PrivateKey = privateKey
};

var contractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; //USDT Contract Address
var to = "TDRK6kQnc55EWkFL4bvv8Fefdbt3HfsiE9";
var amount = 5; //USDT Amount
var feeAmount = 5 * 1000000L;
var contractClient = _contractClientFactory.CreateClient(ContractProtocol.TRC20);

var result = await contractClient.TransferAsync(contractAddress, account, to, amount, string.Empty, feeAmount);
// result="b8107a19cb24e2ffe69b2b45a9499c1bf1bc78f0a54223569a48b6e311df3903

2023-05-18_03h41_40
"
}

Transfer USDT in tron network

Hi there,
Im trying to transfer USDT over tron network but there is an exception:

System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values. (Parameter 'Illegal character 0 at 1')'

Code:

        services.AddTronNet(x =>
        {
            x.Network = TronNetwork.TestNet;
            x.Channel = new GrpcChannelOption { Host = "grpc.nile.trongrid.io", Port = 50051 };
            x.SolidityChannel = new GrpcChannelOption { Host = "grpc.nile.trongrid.io", Port = 50061 };
            x.ApiKey = "8e79fb6f-e787-418b-8238-c666651b51ac";
        });
        
        var account = _wallet.GetAccount(privateKey);
        var contractAddress = "TSzM1BMMHidyodU9FBq2v2rGfoZnuX9L5T"; 
        var to = "TRw1rCgZzidsos7iYevHP73c6o79H8187v";
        var amount = 10;
        var feeAmount = 5 * 1000000L;
        var contractClient = _contractClientFactory.CreateClient(ContractProtocol.TRC20);
        var result = await contractClient.TransferAsync(contractAddress, account, to, amount, "TERC", feeAmount);

And if there is any other/better approach please help how to do it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.