These are chat archives for Nethereum/Nethereum

19th
Jun 2018
Isaac Wooden
@iwooden
Jun 19 2018 01:00
@juanfranblanco Thanks for your help! Think I found a workaround... next question :)
Is there a way to get the Function DTO from a contract ABI? I want to decode function inputs from a transaction, but I won't know enough about the ABI ahead of time to code the DTO by hand
Juan Blanco
@juanfranblanco
Jun 19 2018 06:05
You can create a function (you still need to know the ABI eventually) and call Decode Input.
Btw feel free to do a pull (if you find anything you do interesting)
JEN
@chukwuemekanweke
Jun 19 2018 07:26
@juanfranblanco once again thanks for this awesome library. It's been of immense value to our team. So today we're taking one of our apps to the live network. I know i just have to change the Chain i'm using. but i don't know which to go with Mainnet or ClassicMainnet?
Juan Blanco
@juanfranblanco
Jun 19 2018 07:31
@chukwuemekanweke I am glad :) Regarding ETH or ETC I cannot make that decision.
JEN
@chukwuemekanweke
Jun 19 2018 07:38
We're just interested in ETH. So we'd go with just Mainnet then?
Juan Blanco
@juanfranblanco
Jun 19 2018 08:15
Yeah different chains
kolvin2016
@kolvin2016
Jun 19 2018 08:19
Hi ,i am study Nethereum now .there is any way to sign a transaction offline for icon coin?
document is poor
kolvin2016
@kolvin2016
Jun 19 2018 08:51
@juanfranblanco .Is there any example code for sign a contract transaction for ico?
kolvin2016
@kolvin2016
Jun 19 2018 08:58
@mvdv thanks
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 08:59
I found solution
using
TransactionBase.DEFAULT_GAS_PRICE - > 20 gwei
TransactionBase.DEFAULT_GAS_LIMIT
instead
estimate gas and
var gasPrice = await _web3.Eth.GasPrice.SendRequestAsync(); - > always return 10 gwei ? bug?
that's why it does not pass the transaction
not correct gas price
kolvin2016
@kolvin2016
Jun 19 2018 09:05
@mvdv There is no documents for code,i don't know how to use it step by step.can u provider some simple code ?
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:09

Hi guys .

I want to make transaction send all eth , and I had error Message = "insufficient funds for gas * price + value"

For example:
My balance : 10.985379999999999999
I want to send 10.985379999999999999 - > error "insufficient funds for gas price + value"
I want to send 100 eth -> same error "insufficient funds for gas
price + value"

Should I estimate transaction fee and decrease amount to send or should I do something else ?

var gasPrice = await _web3.Eth.GasPrice.SendRequestAsync();
var gas = await _web3.Eth.Transactions.EstimateGas.SendRequestAsync(new CallInput("0x" + transactionEncoded, destanitionAddress));
var feeAmount = gasPrice.Value * gas.Value;
I try sending all balance
and give the error
Michael van der Veeken
@mvdv
Jun 19 2018 09:10
I haven't done it, but there is a MessageSigner class in Nethereum.Signer that should help? What exactly are you trying to accomplish?
@Ilchuk-Mihail : if cannot send the full amount, you need a little for gas. If you have 10 ETH, and are trying to send 10 ETH you will not be able to pay for the transaction
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:12
allBalance = 10 eth;
amountToSend = allBalance - fee; // for example 9.9999...
i trying calculate fee
and now
I make calculation
amountToSend = allBalance - TransactionBase.DEFAULT_GAS_PRICE * TransactionBase.DEFAULT_GAS_LIMIT
DEFAULT_GAS_PRICE return 20 Gwei
var gasPrice = await _web3.Eth.GasPrice.SendRequestAsync(); - return 10 gwei
because of this there was a mistake
kolvin2016
@kolvin2016
Jun 19 2018 09:13
@mvdv I want to create a raw transaction and use local private key to sign the transaction,at last call eht_sendrawtransaction to broadcast transaction.
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:14
BigInteger.Multiply
and
BigInteger.Subtract
for correct calculation
kolvin2016
@kolvin2016
Jun 19 2018 09:14
i want for eth and eth contract ,for example eth ,eos coins....
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:15

DEFAULT_GAS_PRICE return 20 Gwei
var gasPrice = await _web3.Eth.GasPrice.SendRequestAsync(); - return 10 gwei

why different results ?
20 Gwei and 10 Gwei

I connected to Infura ropsten test network
and I use the keypoint - > for sending the entire balance of an account to another regular account (not a contract account), where the gas is always 21,000.
Michael van der Veeken
@mvdv
Jun 19 2018 09:22
The default gas price is hard coded and the estimation is done by geth?
public static readonly BigInteger DEFAULT_GAS_PRICE = BigInteger.Parse("20000000000");
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:24
ok
then why estimate 10 Gwei -> and transaction not correct Message = "insufficient funds for gas * price + value"
when need 20 Gwei
?
Michael van der Veeken
@mvdv
Jun 19 2018 09:25
not sure
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:28
Maybe create ticket for this ?
need this
for gas price
ChinhP
@Chinh-P
Jun 19 2018 09:31
are you using TransactionInput that Juan mentioned above
if yes, then the only thing you need to make sure it's correct is the fee
I think you are heading to the correct direction
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:34

I realized that I do not need estimate gas limit
because - > for sending the entire balance of an account to another regular account (not a contract account), where the gas is always 21,000.

I need only get gas price

dynamically
ChinhP
@Chinh-P
Jun 19 2018 09:35
you are confuse about 20 Gwei and 10 Gwei, 10Gwei is the current gas price in ropsten testnet, rinkeby now is 1Gwei and mainet is 4Gwei. 20Gwei is hard coded as "safty price"
yes, it's dynamic
21000 is actually the smallest amount of gas that a transaction can use
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:37
ok,
then why I could not send this transaction ?
and send it for 20 Gwei gas price
OK
How to send all amount Eher
for example 5.553 ETH
?
ChinhP
@Chinh-P
Jun 19 2018 09:39
yes, then the Value should be deducted by 20000 * 21000 wei
Michael van der Veeken
@mvdv
Jun 19 2018 09:39
Even if you calculate the gas price low, the transaction should still go through ? There must be something wrong with the 'balance - (gasprice * gasusage)' calc there?
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:40
yes, this error "insufficient funds for gas * price + value"
ChinhP
@Chinh-P
Jun 19 2018 09:40
so, if you have 5.553, maximum amount you can send will be 5.553 - 0.0004200 if im not mistaken
Michael van der Veeken
@mvdv
Jun 19 2018 09:41
what I'm saying is that even if you set the price to 5gw, the transaction should still be valid.
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:41
20000 * 21000 wei - > you also use constants :smile:
how to dynamicaly get correct gas price
Michael van der Veeken
@mvdv
Jun 19 2018 09:41
so the error is in the value minus the cost of the transaction
IMO
ChinhP
@Chinh-P
Jun 19 2018 09:42
var currentGasPrice = await web3.Eth.GasPrice.SendRequestAsync();
then it will be dynamic
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:43
@mvdv no, you get error insufficient funds for gas * price + value
@ChinhPLQ this return 10 gwei and after calculation i get same error
when i use 20 gwei -> i have correct result
ChinhP
@Chinh-P
Jun 19 2018 09:45
you mean, if you set the value = your total amount - 10000 * 21000 wei, it will through exception?
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:45
yes
Michael van der Veeken
@mvdv
Jun 19 2018 09:45
can you post your code ?
ChinhP
@Chinh-P
Jun 19 2018 09:45
then try to use EstimateGasAsync function, maybe it cost more than 21000 gas
Michael van der Veeken
@mvdv
Jun 19 2018 09:47
@Ilchuk-Mihail : What I'm saying is that the price you pay for gas is not a fixed price, it is a market determined price. If you set it lower than the current average price it will still be a valid transaction.
are you calling a contract ?
ChinhP
@Chinh-P
Jun 19 2018 09:48
yes, it's true
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:49
no, I send to regular account
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 09:50
hi, i want to tranfer some token to an address, can some one tell me how to reduce tx fee, default is 20 Gwei and fee=0,5$ it too expensive
public static async Task TransferAsync(string privatekey,string ContractAddress, string ToAddress,int amount,string gas)
{
//Replace with your own
//var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
//var receiverAddress = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe";
//var privatekey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
//var url = "https://rinkeby.infura.io/";
var url = "https://mainnet.infura.io/dW9nzrZ4ad6kCn0sHzD9";
Account ac = new Account(privatekey);
var web3 = new Web3(ac, url);
var transactionMessage = new TransferFunction()
{
FromAddress = ac.Address,
To = ToAddress,
TokenAmount = amount,
};
var transferHandler = web3.Eth.GetContractTransactionHandler<TransferFunction>();
/// this is done automatically so is not needed.
var estimate = await transferHandler.EstimateGasAsync(transactionMessage, ContractAddress);
transactionMessage.Gas = estimate.Value;
var transactionHash = await transferHandler.SendRequestAsync(transactionMessage, ContractAddress);
Console.WriteLine(transactionHash);
}
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 09:53
        private async Task<string> CreateTransaction(BigInteger weiAmount, string destanitionAddress)
        {
            var txCount = await _web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(_myAddress);
            var encoded = Web3.OfflineTransactionSigner.SignTransaction(_myPrivateKey, destanitionAddress, weiAmount, txCount.Value);

            return "0x" + encoded;
        }

        private async Task<BigInteger> EstimateFeeAsync(string transactionEncoded, string destanitionAddress)
        {
            // var a1 = TransactionBase.DEFAULT_GAS_PRICE;
            var gas = await _web3.Eth.Transactions.EstimateGas.SendRequestAsync(new CallInput(transactionEncoded, destanitionAddress));

            var gasPrice = await _web3.Eth.GasPrice.SendRequestAsync();
            var feeAmount = BigInteger.Multiply(gasPrice.Value, gas.Value); 

            return feeAmount;
        }

//
  var transactionEncoded = await CreateTransaction(weiAmount, destanitionAddress);
  var feeAmount = await EstimateFeeAsync(transactionEncoded, destanitionAddress);

 var weiAmount = BigInteger.Subtract(weiAmount, feeAmount); //amount to send all balance
  var txId = await _web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(transactionEncoded); - > Exception
@Ilchuk-Mihail : Don't you have to pass in the gas price and gas limit to the SignTransaction function?
or it will use defaults
so that might be why the calculation is off
you calculate the fee amount based on the calculated prices, but the transaction is using the defualts
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 10:04
yes
you right
   var encoded = Web3.OfflineTransactionSigner.SignTransaction(_myPrivateKey, destanitionAddress, weiAmount, txCount.Value, new BigInteger(1000000000), gas);
image.png
But I send 28148 gas limit for regular account
Gas Used By Txn: 21000
what happens to the difference
?
Michael van der Veeken
@mvdv
Jun 19 2018 10:07
you should have 7148 * 1gwei as balance left over in your account
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 10:08
Balance: 0.000007148 Ether
yes
but , I send all balance
Michael van der Veeken
@mvdv
Jun 19 2018 10:08
but you set the gas limit too high, whatever gas you don't use you don't pay for
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 10:08
and so it turned out that not all
Michael van der Veeken
@mvdv
Jun 19 2018 10:08
set the gas limit lower (to 21000)
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 10:09
Stop
Michael van der Veeken
@mvdv
Jun 19 2018 10:09
I believe this is the default limit
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 10:12

I use 10 gwei price
and estimated 28148 gas, when i realy need 21000

If i use 21000 and 10 gwei - exception
if I use 28148 and 10 gwei -> it's ok , but I have small remainder 0.000007148 Ether
if I use 21000 and 20gwei -> always ok, But you not recomend this

I will ask again
How to send all balance to another account ?
Michael van der Veeken
@mvdv
Jun 19 2018 10:22
I don't see how you can get an exception with 21000 * 10gwei if you set it right when signing the transaction ?
Michael van der Veeken
@mvdv
Jun 19 2018 10:27
in your above example I believe you have 1gwei instead of 10
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 10:27
@mvdv can you explain more i don't know how to reduce tx fee when i make a transaction to transfer token
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 10:28
@mvdv yes . 1gwei
this tarnsaction is succsess
var encoded = Web3.OfflineTransactionSigner.SignTransaction(_myPrivateKey, destanitionAddress, weiAmount, txCount.Value, new BigInteger(1000000000), new BigInteger(21000));
but Balance: 0.000007284 Ether
not zero
Michael van der Veeken
@mvdv
Jun 19 2018 10:40
is your estimateFreeAsync and CreateTransaction using the same values for the gaslimit and gas price?
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 10:42

Sorry, i mistake
i used old estimated gas value not 21000

If I use 21000 and 1 gwei - > always ok
and balance zero

thanks
@mvdv and you recommend used
var gasPrice = await _web3.Eth.GasPrice.SendRequestAsync();
and default gas 2100 for regular transactions
?
do not need estimate regular transaction
Michael van der Veeken
@mvdv
Jun 19 2018 11:40
a transaction is always 21000
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 12:02
:+1:
Michael Ilchuk
@Ilchuk-Mihail
Jun 19 2018 14:41
How to check is valid address?
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 16:19
@mvdv hi , how can i tranfer amount of token is double, ex: 89.989. i only can tranfer with integer ex: 89
Michael van der Veeken
@mvdv
Jun 19 2018 16:31
a token or Ether?
e.g. an ERC20 token?
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 16:33
@mvdv yes ERC20 token
Michael van der Veeken
@mvdv
Jun 19 2018 16:55
You would not use decimals as Solidity does not support it
Have a look at a standard ERC20 contract to see how it is managed
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 17:01
var transactionMessage = new TransferFunction()
{
FromAddress = ADDRESS,
To = TO_ADDRESS,
TokenAmount =89.98,//can not pass into TokenAmount
};
sr for my english but this is my code
Michael van der Veeken
@mvdv
Jun 19 2018 17:02
amount * decimalplaces
so if the decimal places of the ERC20 contract is 2, then 89.98 * 2
@Ilchuk-Mihail There is also an AdresUtil in Nethereum.Util
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 17:47
@mvdv so if decimal is 0 then TokenAmount=0?
@mvdv TokenAmount is BigInteger and if i try BigInteger.parse("89.98") then result is 89
Juan Blanco
@juanfranblanco
Jun 19 2018 17:54
@DangNghia123_twitter you will need to use the Web3.Convert.ToWei(89.98, "numberOfdecimalsInyourContract");
it will be normally 18
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 18:03
@juanfranblanco tranfer.AMOUNT = Web3.Convert.ToWei(89.98,"0"); has an error: can not convert from string to Nethereum.Ulti.UnitConvertsion.EthUnit
Enigmatic
@EnigmaticUnreal_twitter
Jun 19 2018 18:05
Hmm. Your token does not have decimals, @DangNghia123_twitter ?
Usually we specify 18 decimals.
Do you want to try Web3.Convert.ToWei(89.98,18) and see if it works for you?
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 18:08
im on rinkeby testnet , i have just tried:
tranfer.AMOUNT = Web3.Convert.ToWei(89.98, UnitConversion.EthUnit.Wei);
@EnigmaticUnreal_twitter txthash: 0xc178f5728ad0db88cda83aafcd98b96404ca4d2b22ce140fe0dbc5f29830a993
@EnigmaticUnreal_twitter amount is still 89
Enigmatic
@EnigmaticUnreal_twitter
Jun 19 2018 18:10
Try tranfer.AMOUNT = Web3.Convert.ToWei(89.98) and see the results?
Michael van der Veeken
@mvdv
Jun 19 2018 18:10
use a BigInteger with the number of decimals the ERC20 supports
Enigmatic
@EnigmaticUnreal_twitter
Jun 19 2018 18:14
Oh. So you indeed did not specify any decimals on your contract. If you'd want to send tokens with decimals, you'll need to put a number there.
            name = "Test ERC20";                          
            decimals = 18; 
            symbol = "TERC20";
            totalSupply = 50000000 * 10 ** uint256(decimals); 
            owner = msg.sender;
Truong Dang Nghia
@DangNghia123_twitter
Jun 19 2018 18:16
@EnigmaticUnreal_twitter yes, i just tried on mainnet and it successfull
thank all for support
Aify
@Aify
Jun 19 2018 20:32
@juanfranblanco During testing, I noticed that Nethereum will throw OverflowException when trying to get the name or symbol of certain transactions
For example, trying to use the contract handler to queryAsync Name or Symbol (using the TransactionReceipt Object that has this transaction hash 0x49cf4a2fa4fb5f1b3e35d437072bc586246efb09300244b3d686b3064896a7be ) will throw the exception.
Aify
@Aify
Jun 19 2018 20:56

Some other hashes I found that this happens on are
0x3ac6132405fb6fce3cf04f947ac8e91da92b48a2ae4666e377535eaf1f2c7d48
0x0cc22c7f31c2b5db63ce26b01bfe78af8ad2e632c2fd4e7e3a04ab9b0a610a6f
0xb4de9f39cf7b6218d51ded0174007d4f9344ddfa690f9c94af00b4d18b7d3bb0

I only went through one block, so I don't know if there are others

El Amen
@ela4men_twitter
Jun 19 2018 22:29
@juanfranblanco Thank you for your help.
El Amen
@ela4men_twitter
Jun 19 2018 22:47
Please am getting "base fee exceeds gas limit" exception on method.SendTransactionAsync(service.AccountAddress, value) call and my research is not helping me solve it. Any help please.