MetacoSA / QBitNinja

An Open Source and powerful blockchain API
MIT License
68 stars 42 forks source link

IS there any way to calculate fee #41

Closed cryptodeveloperin closed 6 years ago

cryptodeveloperin commented 6 years ago

Is there any way to auto calculate the fee during withdrawn transaction?

Because if i get some thing static then withdrawn take long time. so please assist.

or is there any way to get total number of byte of current transaction?

NicolasDorier commented 6 years ago

Either use your own Bitcoin Core node and call RPC estimatesmartfee or use a third party service like https://estimatefee.com/api

cryptodeveloperin commented 6 years ago

i have check estimate fee but i want to know how the byte will be calculated for our transaction? means what's the total byte for my transaction? so as per that i can increase my fee. i want to inquire about total byte fro current transaction, so i can pay more but i could not found any way currently.

NicolasDorier commented 6 years ago

Use TransactionBuilder and use SendEstimatedFee(feeRate) where feeRate is taken from this service.

cryptodeveloperin commented 6 years ago

ok thanks..i will check now.

cryptodeveloperin commented 6 years ago

I have already taken fee from service but my transaction bytes are more then 1000 and so i transaction taken long time to confirm. so i need to check byte before broadcast, and i can upgrade transaction fee for those bytes.

Please help me , how can i make proper fee for my single transaction but as per the byte. i am using fee from "https://bitcoinfees.21.co/api/v1/fees/recommended" also check from above recommendation. But my main problem is Byte of transaction. It was bigger then i am expecting

Money minerFee = new Money(fee, MoneyUnit.BTC);

var keys = new List(); foreach (var userAutoId in txBalanceListToUse.Select(x => x.UserAutoId).Distinct()) keys.Add(masterKey.ExtKey.Derive((uint)userAutoId));

        transaction.Sign(keys.ToArray(), coinList.ToArray());

        var builder = new TransactionBuilder();
        NBitcoin.Policy.TransactionPolicyError[] error = null;
        builder.AddCoins(coinList.ToArray());            
        bool verifyTransactionHash = builder.Verify(transaction, out error);

        if (verifyTransactionHash == true && error.Length == 0)
        {
            // Broadcast your transaction to all miners
            BroadcastResponse broadcastResponse = client.Broadcast(transaction).Result;
            if (!broadcastResponse.Success)
                throw new Exception(broadcastResponse.Error.Reason);

}

cryptodeveloperin commented 6 years ago

I got the solution. Thanks.