<blockquote>
  <p>but how? bitcoin is hard to mine, how can this method mine nblocks immediately?</p>
</blockquote>

<p><code>generate</code> is only used on the regtest network, where blocks can be mined instantly. </p>

CC BY-SA 4.0
2018-11-12T05:44:32.837Z
thank you, how about the maxtries param in input, what it is used for?
Shiming
CC BY-SA 4.0
2018-11-12T06:16:20.593Z
@huahuayu Maximum nonce perhaps?
Mason Ticehurst
CC BY-SA 4.0
2018-11-12T04:26:05.700Z
2018-11-12T04:26:05.700Z
Claris
<p>If you issue</p>
<pre><code>generatetoaddress 11 myaddress
</code></pre>
<p>on testnet you'll get 0 generated.</p>
<p>If you do the same on regtest you'll get the expected 11 blocks.</p>
<p>Example on regtest:</p>
<pre><code>10:20:01 getnewaddress
10:20:01 bcrt1qgwev460zqprwlvnv45nq3tyuwgj4t8ukx8qs53
10:21:55 getblockcount
10:21:55 113
10:22:17 generatetoaddress 11 bcrt1qgwev460zqprwlvnv45nq3tyuwgj4t8ukx8qs53
10:22:17 [
  &quot;724e85de66945bb2bb3de206e73b2016bd40f43822281c7b8ffa05e1d52641a9&quot;,
  &quot;68a1bcc819e8fcb571014f65ab21dcfb2ccda7deda941660b3dd85b55623c82d&quot;,
  &quot;3f4c8ebb4e83e0fd37f1974bc802b2ef987a19c5baa1c82d22ccea8d1bda10a5&quot;,
  &quot;55c5d2d212c41924c16e8db1f0e4ce11bd59c5b62a5d94c1c249aee1bc8636e1&quot;,
  &quot;1ea44161f9475dc585d4376163bfd23017d6f6848cbe7f4a29b6cddeb16c538c&quot;,
  &quot;6217e867f0e46a2aa1651a041a8affc5b907416215734b143c7069ae9633f9f0&quot;,
  &quot;0be6f3cdf857541543e5d1ac7c9afa018d5f6e3d94cc9a21b5959bf5d380e325&quot;,
  &quot;181b065ea58434e3a12bdf1245243b07eef3fb62d931658cf3b39a3c82b71b25&quot;,
  &quot;431f29b1de0c8ba10e54b8c115203a8635a5bc66af67ee7425ae3f7264c71bea&quot;,
  &quot;287ad0d6eda9d5f267743cde7b7fce0d3ab53ad84f0fc33e04c79cf82ed0429b&quot;,
  &quot;1fb51410422b2bb7482db31beefc7508bcd66b3c22be88508616602658e65cb0&quot;
]

10:22:21 getblockcount
10:22:21 124
</code></pre>
<p>Example on testnet:</p>
<pre><code>10:20:01 getnewaddress
10:20:01 tb1qt0axt7scf4snvrlvhd6snnp5lf839ht9swy2y3

10:21:55 getblockcount
10:21:55 113
10:22:17 generatetoaddress 11 tb1qt0axt7scf4snvrlvhd6snnp5lf839ht9swy2y3
10:22:17 [
]

10:22:21 getblockcount
10:22:21 113
</code></pre>
<p>The documentation on generatetoaddress is a little confusing as it doesn't explain that this command only works effectively on regtest.</p>

CC BY-SA 4.0
2024-03-14T03:31:58.737Z
I have a follow up question on this. How do you determine the number of blocks here? Suppose I want to generate 1 bitcoin to an address. Is there a function to determine that?
XCEPTION
CC BY-SA 4.0
2021-08-02T17:28:29.070Z
2022-03-25T18:07:22.007Z
2022-03-25T18:07:22.007Z
JDOaktown
<p>can anyone explain what are this rpc methods used for:<br>
1.<strong>generate</strong><br>
<a href="https://bitcoincore.org/en/doc/0.16.3/rpc/generating/generate/" rel="nofollow noreferrer">https://bitcoincore.org/en/doc/0.16.3/rpc/generating/generate/</a><br>
from the introduction of generate mehod: </p>

<blockquote>
  <p>Mine up to nblocks blocks immediately</p>
</blockquote>

<p>but how? bitcoin is hard to mine, how can this method mine nblocks immediately?</p>

<pre><code>generate nblocks ( maxtries )

Mine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.

Arguments:
1. nblocks      (numeric, required) How many blocks are generated immediately.
2. maxtries     (numeric, optional) How many iterations to try (default = 1000000).

Result:
[ blockhashes ]     (array) hashes of blocks generated

Examples:

Generate 11 blocks
&gt; bitcoin-cli generate 11
</code></pre>

<p>2.<strong>generatetoaddress</strong><br>
<a href="https://bitcoincore.org/en/doc/0.16.3/rpc/generating/generatetoaddress/" rel="nofollow noreferrer">https://bitcoincore.org/en/doc/0.16.3/rpc/generating/generatetoaddress/</a></p>

<p>the same question as generate method</p>

<pre><code>generatetoaddress nblocks address (maxtries)

Mine blocks immediately to a specified address (before the RPC call returns)

Arguments:
1. nblocks      (numeric, required) How many blocks are generated immediately.
2. address      (string, required) The address to send the newly generated bitcoin to.
3. maxtries     (numeric, optional) How many iterations to try (default = 1000000).

Result:
[ blockhashes ]     (array) hashes of blocks generated

Examples:

Generate 11 blocks to myaddress
&gt; bitcoin-cli generatetoaddress 11 "myaddress"
</code></pre>

<bitcoind>
generate/generatetoaddress what are this two rpc methods used for?
Shiming
# generate/generatetoaddress what are this two rpc methods used for?

(Asked by: username_0 on 2018-11-12)

can anyone explain what are this rpc methods used for:  
1.**generate**  
<https://bitcoincore.org/en/doc/0.16.3/rpc/generating/generate/>  
from the introduction of generate mehod:

> Mine up to nblocks blocks immediately

but how? bitcoin is hard to mine, how can this method mine nblocks immediately?

```
generate nblocks ( maxtries )

Mine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.

Arguments:
1. nblocks      (numeric, required) How many blocks are generated immediately.
2. maxtries     (numeric, optional) How many iterations to try (default = 1000000).

Result:
[ blockhashes ]     (array) hashes of blocks generated

Examples:

Generate 11 blocks
> bitcoin-cli generate 11

```

2.**generatetoaddress**  
<https://bitcoincore.org/en/doc/0.16.3/rpc/generating/generatetoaddress/>

the same question as generate method

```
generatetoaddress nblocks address (maxtries)

Mine blocks immediately to a specified address (before the RPC call returns)

Arguments:
1. nblocks      (numeric, required) How many blocks are generated immediately.
2. address      (string, required) The address to send the newly generated bitcoin to.
3. maxtries     (numeric, optional) How many iterations to try (default = 1000000).

Result:
[ blockhashes ]     (array) hashes of blocks generated

Examples:

Generate 11 blocks to myaddress
> bitcoin-cli generatetoaddress 11 "myaddress"

```

**Tags:** bitcoind


---

## 2 answers

### Answer by username_1 on 2018-11-12. Score: 3

> but how? bitcoin is hard to mine, how can this method mine nblocks immediately?

`generate` is only used on the regtest network, where blocks can be mined instantly.

> **Comments:**
> **username_0**: thank you, how about the maxtries param in input, what it is used for?  
> **username_2**: @huahuayu Maximum nonce perhaps?  

---

### Answer by username_3 on 2021-08-02. Score: 0

If you issue

```
generatetoaddress 11 myaddress

```

on testnet you'll get 0 generated.

If you do the same on regtest you'll get the expected 11 blocks.

Example on regtest:

```
10:20:01 getnewaddress
10:20:01 bcrt1qgwev460zqprwlvnv45nq3tyuwgj4t8ukx8qs53
10:21:55 getblockcount
10:21:55 113
10:22:17 generatetoaddress 11 bcrt1qgwev460zqprwlvnv45nq3tyuwgj4t8ukx8qs53
10:22:17 [
  "724e85de66945bb2bb3de206e73b2016bd40f43822281c7b8ffa05e1d52641a9",
  "68a1bcc819e8fcb571014f65ab21dcfb2ccda7deda941660b3dd85b55623c82d",
  "3f4c8ebb4e83e0fd37f1974bc802b2ef987a19c5baa1c82d22ccea8d1bda10a5",
  "55c5d2d212c41924c16e8db1f0e4ce11bd59c5b62a5d94c1c249aee1bc8636e1",
  "1ea44161f9475dc585d4376163bfd23017d6f6848cbe7f4a29b6cddeb16c538c",
  "6217e867f0e46a2aa1651a041a8affc5b907416215734b143c7069ae9633f9f0",
  "0be6f3cdf857541543e5d1ac7c9afa018d5f6e3d94cc9a21b5959bf5d380e325",
  "181b065ea58434e3a12bdf1245243b07eef3fb62d931658cf3b39a3c82b71b25",
  "431f29b1de0c8ba10e54b8c115203a8635a5bc66af67ee7425ae3f7264c71bea",
  "287ad0d6eda9d5f267743cde7b7fce0d3ab53ad84f0fc33e04c79cf82ed0429b",
  "1fb51410422b2bb7482db31beefc7508bcd66b3c22be88508616602658e65cb0"
]

10:22:21 getblockcount
10:22:21 124

```

Example on testnet:

```
10:20:01 getnewaddress
10:20:01 tb1qt0axt7scf4snvrlvhd6snnp5lf839ht9swy2y3

10:21:55 getblockcount
10:21:55 113
10:22:17 generatetoaddress 11 tb1qt0axt7scf4snvrlvhd6snnp5lf839ht9swy2y3
10:22:17 [
]

10:22:21 getblockcount
10:22:21 113

```

The documentation on generatetoaddress is a little confusing as it doesn't explain that this command only works effectively on regtest.

> **Comments:**
> **username_4**: I have a follow up question on this. How do you determine the number of blocks here? Suppose I want to generate 1 bitcoin to an address. Is there a function to determine that?  

---

