0

I'm testing some wallet features on regtest. Here's the sequence so far:

cash-cli -regtest generate 101
cash-cli -regtest getbalance
500.00000000

cash-cli -regtest getnewaddress newAddress1
yeAPxkjsNk5RZnAyfHM6cjCtKM7oRUvhzX

cash-cli -regtest  sendtoaddress getrawtransaction 148b8ced78037cb8fe3b32b8814dbf6736c144448671a86da548bbdb5670750a 1
//...
{
      "value": 2.00000000,
      "valueSat": 200000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 c3bc1c481a15343ceb27d45d950c8770b7a0be1c OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914c3bc1c481a15343ceb27d45d950c8770b7a0be1c88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yeAPxkjsNk5RZnAyfHM6cjCtKM7oRUvhzX"
        ]
      }
    }, 
//...

dash-cli -regtest gettxout 148b8ced78037cb8fe3b32b8814dbf6736c144448671a86da548bbdb5670750a 0 false
//returns nothing as the transaction is not confirmed. Returns result if we change flag to true

How do I set transaction as confirmed in regtest mode so that dash-cli -regtest <txid> <outid> false would return the transaction output as a valid one?

2 Answers 2

1

A transaction is confirmed by including it in a block. This means that you have to mine a block which includes the transaction. You can do this using the generate command.

5
  • could you give me an example?
    – Ben
    Commented Aug 27, 2018 at 13:31
  • cash-cli -regtest generate 6 will create 6 blocks with the block reward going to your wallet.
    – Ava Chow
    Commented Aug 27, 2018 at 13:35
  • 4
    I create and send raw transaction then use generatetoaddress to mine blocks to get confirmations but the sent transactions stays unconfirmed. Any idea why?
    – Fontaine
    Commented Sep 19, 2019 at 3:42
  • 1
    @Fontaine did you ever find out what your problem was? I have the same, currently.
    – schlingel
    Commented Dec 10, 2019 at 6:14
  • 1
    Any news on this? I'm facing the same situation. Commented Oct 21, 2020 at 20:57
0

I'm running bitcoind along with Bitcore-node and I was having the same problem. I sent 250 transactions to myself, but the balance I got from BWC/BWS was:

{
  "totalAmount": 166250000000,
  "lockedAmount": 0,
  "totalConfirmedAmount": 0,
  "lockedConfirmedAmount": 0,
  "availableAmount": 166250000000,
  "availableConfirmedAmount": 0,
  "byAddress": [
    {
      "address": "mvaTRJ63NJrZ3qaZW1AbfVzMsei5HCiupb",
      "path": "m/0/0",
      "amount": 166250000000
    }
  ]
}

Apparently, bitcoind will hold a cache in memory and it takes some time (or more actions) to release it, passing its contents to the database.

When you close the process (say, with CTRL+C or CMD+C), you'll see a message like this:

2020-10-22T12:23:57Z FlushStateToDisk: write coins cache to disk (250 coins, 34kB) started 
2020-10-22T12:23:57Z FlushStateToDisk: write coins cache to disk (250 coins, 34kB) completed (0.05s)

Then, Bitcore-node will sync and save everything in MongoDb. So, if you close the bitcoind process and then restart, your transactions should become confirmed.

Here's exactly what I did:

  1. Start bitcoind in regtest mode:
    bitcoind -printtoconsole -regtest -fallbackfee=0.00001

  2. Start Bitcore-node. I assume you have it configured to point to your regtest node.
    npm run node

  3. Generate 250 transactions to myself:
    bitcoin-cli -regtest generatetoaddress 250 "mvaTRJ63NJrZ3qaZW1AbfVzMsei5HCiupb"

  4. Wait for Bitcore to sync with bitcoind.

  5. Close bitcoind with CTRL+C (or CMD+C).

  6. Close Bitcore-node with CTRL+C (or CMD+C).

  7. Restart bitcoind and Bitcore-node.

  8. Boom. Using BWC and BWS to fetch the wallet's balance I now receive this:

{
 "totalAmount":166250000000,
 "lockedAmount":0,
 "totalConfirmedAmount":166250000000,
 "lockedConfirmedAmount":0,
 "availableAmount":166250000000,
 "availableConfirmedAmount":166250000000,
 "byAddress":[
  {
   "address":"mvaTRJ63NJrZ3qaZW1AbfVzMsei5HCiupb",
   "path":"m/0/0",
   "amount":166250000000
  }
 ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.