-2

我现在想弄清楚这三天。我认为我的问题不在于交易构建器,而在于.AddCoins部分。

TransactionBuilder builder = Network.TestNet.CreateTransactionBuilder();

var transaction = builder
                .AddCoins(coins)
                .AddKeys(myPrivateKey)
                .Send(addressThatIamSendingTo, Money.Coins(amountToSend))
                .SetChange(addressThatIamSendingFrom);
            
var fee = transaction.EstimateFees(new FeeRate(1m));
                
var finalTransaction = transaction.SendFees(fee).BuildTransaction(true);

我的硬币.AddCoins来自这里:

var balance = client.GetBalance(myBtcAddress); // client is from QBitNinjaClient client = new QBitNinjaClient(Network.TestNet);

var sum = 0m;
            
            
foreach (var operation in balance.Result.Operations)
{
    sum += operation.Amount.ToDecimal(MoneyUnit.BTC);
                
}
            
Console.WriteLine("Sum {0} is ", sum);
            
var amountToSend = 0.0002m;
var transaction = Network.TestNet.CreateTransaction();
transaction.Outputs.Add(new TxOut(Money.Coins(sum), myScriptPubKey));
            
Coin[] coins = transaction.Outputs.AsCoins().ToArray();

事情是这样builder.Verify(finalTransaction)说的,但是在使用或配置为命中的True广播之后,我得到了交易 ID,我在任何地方都看不到它,并且 BTC 没有被转移。QBitNinjaLocal NodeTestNet

4

2 回答 2

0

所以事实证明,我以错误的方式称呼这种该死的平衡。

client.GetBalance(myAddress, true)// 其中 true 是未使用的硬币 ....

然后交易币是.AddCoins(client.GetBalance(myAddress, true).Result.Operations.SelectMany(op => op.ReceivedCoins).ToArray())

于 2022-02-14T21:27:12.557 回答
0

https://github.com/holle197/BSharp

我刚刚做了一个小项目,发送比特币。在 github 上给我一颗星 ;)

于 2022-03-05T01:50:03.950 回答