Open replaysMike opened 6 years ago
Your code seems good.
I think your problem is that NBXplorer may have indexed the unspent coins long time ago. Then you restarted bitcoind (or restarted it from scratch?) before mining the transaction. So bitcoind is unable to find your unspent coin.
Here is a full example working
[Fact]
public void CanSendFromNBXPlorer()
{
var provider = new NBXplorerNetworkProvider(NetworkType.Regtest);
var nbxplorer = new ExplorerClient(provider.GetBTC());
var rpc = new RPCClient(Network.RegTest);
rpc.Generate(1);
var status = nbxplorer.GetStatus();
Assert.True(status.IsFullySynched);
// Comment if you mined already 101 blocks
//rpc.Generate(network.Consensus.CoinbaseMaturity + 1);
var rootKey = new ExtKey();
var accountKey = rootKey.Derive(new KeyPath("49'/1'/0'"));
var expectedScriptPukey =
accountKey.Derive(new KeyPath("0/0"))
.PrivateKey
.PubKey
.WitHash.ScriptPubKey // P2WPKH
.Hash.ScriptPubKey; // P2SH
var factory = new DerivationStrategyFactory(Network.RegTest);
var derivationScheme = factory.Parse($"{accountKey.Neuter().ToString(Network.RegTest)}-[p2sh]");
nbxplorer.Track(derivationScheme);
KeyPathInformation unused = nbxplorer.GetUnused(derivationScheme, DerivationFeature.Deposit);
Assert.Equal(expectedScriptPukey, unused.ScriptPubKey);
var listening = nbxplorer.CreateNotificationSession();
listening.ListenAllDerivationSchemes();
listening.ListenNewBlock();
rpc.SendToAddress(unused.ScriptPubKey.GetDestinationAddress(Network.RegTest), Money.Coins(1.0m));
// NBXplorer.Models.NewBlockEvent
// NBXplorer.Models.NewTransactionEvent
listening.NextEvent();
var utxos = nbxplorer.GetUTXOs(derivationScheme, null);
Assert.Single(utxos.Unconfirmed.UTXOs);
var minerAddress = rpc.GetNewAddress();
Key[] keys = utxos.GetKeys(accountKey);
Coin[] coins = utxos.GetUnspentCoins();
var feeRate = rpc.TryEstimateSmartFee(1)?.FeeRate ?? new FeeRate(Money.Satoshis(100), 1);
var tx = new TransactionBuilder()
.SetConsensusFactory(network)
.AddCoins(coins)
.AddKeys(keys)
.Send(minerAddress, Money.Coins(0.1m))
.SetChange(nbxplorer.GetUnused(derivationScheme, DerivationFeature.Change).ScriptPubKey)
.SendEstimatedFees(feeRate)
.BuildTransaction(true);
Assert.True(new TransactionBuilder().SetConsensusFactory(network).AddCoins(coins).Verify(tx));
var result = nbxplorer.Broadcast(tx);
Assert.True(result.Success);
}
Hi Nicolas thanks for the response. I'm not quite sure I fully understand what you're saying, but the coins deposited into the source account were a few weeks old at most. So yes, definitely there would have been multiple restarts of NBXplorer and Bitcoin core. I noticed that when using NBXplorer I at least get an error, but with the Node client it silently passed on the transaction.
I'll see if I can get my hands on more Testnet coins as I'm now out of them, it's been difficult to find new ones with all of the faucets down.
Ah you are testing on testnet that's why.
Have you checked that the coin you are trying to spend have been confirmed?
Indeed I have, 88+ confirmations on the coin.
but I think I'm going to dump my test wallet and try again when I can find a working faucet or something. It's not entirely unlikely that I screwed something up.
Can you try again your code? Because when you posted the issue, the coin did not had confirmation.
hmm interesting, I'll try again
any news?
same problem: I try use same inputs , outpus to create tx, but nbitcoin's signedtx retrun miss inputs;
here is the signed raw tx
testnet : use nbitcoin sign tx 0100000001a7c8aabeca0bef825e5d1177f4d60b7f071f2e0da97cf9012715c956d778815a020000006a47304402206dd14f6615cb4e0dc922e1b75b5968f15fdca73aebaed8af8369f72c8e69adee02204dce92ca07d440626f8e42694702a40d008622125d9c8e4adbc49752443fc4e80121026fe485b5ff7420da0be833560c1d179b02e8f9ea50b1b7d347004b9b50f097dfffffffff02c8f681020000000017a9142166c2c5d2a11ae6f1e6707195f57948973b726287f07e0e000000000017a9149a9f750a49dc4a553904b3c1a19318d74fabc1b88700000000
use bitcoin 0.17 sign tx 02000000000101a7c8aabeca0bef825e5d1177f4d60b7f071f2e0da97cf9012715c956d778815a02000000171600147bb4327ddea9180e90b1b788984326f03a6f5816ffffffff02f07e0e000000000017a9149a9f750a49dc4a553904b3c1a19318d74fabc1b887c8f681020000000017a9142166c2c5d2a11ae6f1e6707195f57948973b726287024730440220426b774bed54cfa4ff1f16c1ac41aa420264159d0fdb4b9fb56a91d9c6707197022060f6261629fcb7c529084b84e7f76e2602c6a791913f90b058c8326d30a189040121026fe485b5ff7420da0be833560c1d179b02e8f9ea50b1b7d347004b9b50f097df00000000
The coin is already spent https://testnet.smartbit.com.au/tx/a87909edd274c2942cd9c95b134e7315ea4ae0ff48d82aebe1930ec0bde04735
@lontivero yes,I have use the bitcoin 0.17 send it out. It is not spent when I test it.
Ive got the same issue. Was working great, then our node went down.
I've been working through how to get a transaction submitted successfully for a couple days now and I think I'm stuck.
Here I'm generating the transaction:
The broadcastResponse returns: RPC_TRANSACTION_ERROR Missing Inputs
and the transaction hex:
and decoded transaction:
I'm a little stuck here.