# How to check deposit from users

**URL:** <https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151>\
**Category:** Technical Support\
**Created:** [January 6, 2021, 5:04am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151 "2021-01-06T05:04:48Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 6, 2021, 5:04am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/1 "2021-01-06T05:04:48Z")

</div>

Hi guys!  
I have a system app.  
I want to receive zcash from users and move them to the zcash master address.  
So, I have a master zcash address and this is the main flow:

1. If the user request a deposit, the system will **gen a new temp address** (use **z\_getnewaddress** function and **sapling** format).
2. Then **the user send some zcash** to the temp address.
3. Then the system **(cron job) will check the balance** of the temp address (use **z\_getbalance** function).
4. The system **moves all balances** of the temp address to the master address.
5. Bla bla…
6. Transfer: send to the user: use the method: sendtoaddress or z\_sendmany?

**So everything is ok for me?**  
And how do I move all balances from temp address to master address?  
_Is there a way to move them quickly_? ( **do not use the transfer function** ) .  
Thank you so much!

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 7, 2021, 9:29am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/2 "2021-01-07T09:29:05Z")

</div>

hello! Can you help!

---

<div class="post-metadata">

**Author:** ![Shawn](https://sea2.discourse-cdn.com/zcash/user_avatar/forum.zcashcommunity.com/shawn/32/187_2.png) [@Shawn](https://forum.zcashcommunity.com/u/Shawn)\
**Post date:** [January 7, 2021, 4:42pm UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/3 "2021-01-07T16:42:46Z")

</div>

> [@goat](#):
>
> how do I move all balances from temp address to master address?

To move ZEC to a new address you will need to send like any other transaction.

`z_sendmany`

> **[z\_sendmany - Zcash 4.5.1-1 RPC Docs](https://zcash-rpc.github.io/z_sendmany.html)**
>
> Zcash 4.5.1-1 RPC Docs - z\_sendmany

---

<div class="post-metadata">

**Author:** ![str4d](https://sea2.discourse-cdn.com/zcash/user_avatar/forum.zcashcommunity.com/str4d/32/64_2.png) [@str4d](https://forum.zcashcommunity.com/u/str4d)\
**Post date:** [January 7, 2021, 5:23pm UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/4 "2021-01-07T17:23:43Z")

</div>

> [@goat](#):
>
> If the user request a deposit, the system will **gen a new temp address** (use **z\_getnewaddress** function and **sapling** format).

This is going to quickly cause a big slowdown in your node, because `z_getnewaddress` gets a new spending key, and the speed of node scanning is linear in the number of spending keys.

For your given workflow, I would instead recommend generating diversified addresses. This allows you to generate multiple payment addresses backed by the same spending key. You would generate a diversified address for each user (could be one per user, or a fresh one every time), and then when a user sends you funds, you can detect which address the funds came from (to determine which user sent the funds).

> [@goat](#):
>
> And how do I move all balances from temp address to master address?  
> _Is there a way to move them quickly_ ? ( **do not use the transfer function** ) .

With diversified addresses, there is no need to move funds to the master address, because the funds are already there 🙂

`zcashd` doesn’t support generating diversified addresses, but it _does_ support receiving funds from them. So what I’d recommend is that you export your Sapling full viewing key from `zcashd`, and use the [Rust libraries to generate diversified addresses from it](https://docs.rs/zcash_primitives/0.4.0/zcash_primitives/zip32/struct.ExtendedFullViewingKey.html#method.address) to give to users.

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 8, 2021, 3:53am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/5 "2021-01-08T03:53:39Z")

</div>

GOOOOOOD!  
You are very best. Thank you so so so much!

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 8, 2021, 3:55am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/6 "2021-01-08T03:55:46Z")

</div>

> [@str4d](#):
>
> So what I’d recommend is that you export your Sapling full viewing key from `zcashd` , and use the [Rust libraries to generate diversified addresses from it](https://docs.rs/zcash_primitives/0.4.0/zcash_primitives/zip32/struct.ExtendedFullViewingKey.html#method.address) to give to users.

Do you know the libs write by GOLANG? or the full code to gen diversified address by rust language (I don’t know rust language)

---

<div class="post-metadata">

**Author:** ![str4d](https://sea2.discourse-cdn.com/zcash/user_avatar/forum.zcashcommunity.com/str4d/32/64_2.png) [@str4d](https://forum.zcashcommunity.com/u/str4d)\
**Post date:** [January 8, 2021, 4:08pm UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/7 "2021-01-08T16:08:32Z")

</div>

I’ve put together an example Rust binary showing how to do this:

> <https://github.com/zcash/librustzcash/pull/325>
>
> Usage:
> \`\`\`
> cargo run --example diversify-address -- SAPLING\_VIEWING\_KEY \[DIVER…SIFIER\_INDEX\]
> \`\`\`
> 
> If \`DIVERSIFIER\_INDEX\` is not specified, it defaults to zero (which generates the default diversified address).
> 
> As not all diversifier indices correspond to a valid Sapling address, the binary starts looking from the given index, and returns the first valid Sapling address it can find, along with its corresponding diversifier index.

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 12, 2021, 10:22am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/8 "2021-01-12T10:22:46Z")

</div>

I have 3 cmd, but can’t gen a diversified address from the viewing key.  
the error: **Invalid mainnet Sapling viewing key**  
But I want to gen a testnet diversified address  
Can you check for me? Many many thanks!

**1. list address:**

```
./src/zcash-cli z_listaddresses
[
  "ztQYRe97Xu3o86VDKjPQRYNL6XwU5EChvUNkNSS4dXo6GwRm8FtBs1BL2PcPwxrGFd8cSjHbJdwW3nabRd4YDKyy3Vn3MZ4",
  "ztestsapling1xjqv349c4hk0625j975g5fcyy6eyezxucxyztaga0eqznww9jesd8a9nzwjgy8mqwa9g5u4dpht",
  "ztestsapling1t4cemg84hzjyh466qru7gfdusd3f53639g5g4t4xxz9gpdza2z9mv6n39gw83kkdzhcw7s44xpv",
  "ztestsapling13w57wcx9446pef2t2l292hje8yw8vhy2pc4rz23wk3qt7pxl0a8p4tfc7scqdr00ay5kvkvlef4",
  "ztestsapling14f874qp8a0fu74rwjgfwwt57tv89fu6345zdatp9k9re3adz3jhptaxqwyxdzjxqp72uyr8m54m"
]

```

* * *

**2. export viewing key:**

```
./src/zcash-cli z_exportviewingkey ztestsapling14f874qp8a0fu74rwjgfwwt57tv89fu6345zdatp9k9re3adz3jhptaxqwyxdzjxqp72uyr8m54m

zxviewtestsapling1qv9ufts9qqqqpq94gjtgvss3065thw4e8sftpa4q20r9zjw8rafr0cyqnm6cxvu5l907cq9mgxdcvqvlcpjfmzkp46870yeu4w2e2fv66fs3udzasy6utye99a50ndskpks65y6mugcyq3n3ee5sedazejn00dx8yev8lqaw6cq2hr7m3wwmazfak3czl0eehjpdp0y2urrs7fj7zha4ahhz202qrlmzh0h2sep7v24f7v0l8pnrlf9thn5sc6dyvj75zl3quh792nc4jjcka

```

* * *

**3. gen diversified:**

`cargo run --example diversify-address -- zxviewtestsapling1qv9ufts9qqqqpq94gjtgvss3065thw4e8sftpa4q20r9zjw8rafr0cyqnm6cxvu5l907cq9mgxdcvqvlcpjfmzkp46870yeu4w2e2fv66fs3udzasy6utye99a50ndskpks65y6mugcyq3n3ee5sedazejn00dx8yev8lqaw6cq2hr7m3wwmazfak3czl0eehjpdp0y2urrs7fj7zha4ahhz202qrlmzh0h2sep7v24f7v0l8pnrlf9thn5sc6dyvj75zl3quh792nc4jjcka 0`

```
**Compiling** zcash_client_backend v0.4.0 (/Users/Downloads/librustzcash-master/zcash_client_backend)

**Finished** dev [unoptimized + debuginfo] target(s) in 3.12s

**Running** `/Users/Downloads/librustzcash-master/target/debug/examples/diversify-address zxviewtestsapling1qv9ufts9qqqqpq94gjtgvss3065thw4e8sftpa4q20r9zjw8rafr0cyqnm6cxvu5l907cq9mgxdcvqvlcpjfmzkp46870yeu4w2e2fv66fs3udzasy6utye99a50ndskpks65y6mugcyq3n3ee5sedazejn00dx8yev8lqaw6cq2hr7m3wwmazfak3czl0eehjpdp0y2urrs7fj7zha4ahhz202qrlmzh0h2sep7v24f7v0l8pnrlf9thn5sc6dyvj75zl3quh792nc4jjcka 0`

/Users//Downloads/librustzcash-master/target/debug/examples/diversify-address: invalid argument to option `viewing_key`: Invalid mainnet Sapling viewing key

```

---

<div class="post-metadata">

**Author:** ![str4d](https://sea2.discourse-cdn.com/zcash/user_avatar/forum.zcashcommunity.com/str4d/32/64_2.png) [@str4d](https://forum.zcashcommunity.com/u/str4d)\
**Post date:** [January 12, 2021, 1:01pm UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/9 "2021-01-12T13:01:21Z")

</div>

There was a bug in my example that meant it only worked for mainnet viewing keys 😅

Fixed in [zcash\_client\_backend: Fix testnet bug in diversify-address example by str4d · Pull Request #327 · zcash/librustzcash · GitHub](https://github.com/zcash/librustzcash/pull/327)

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 13, 2021, 4:31am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/10 "2021-01-13T04:31:36Z")

</div>

woa, it works for me. Thank you I love you.  
ah how to build this to an execute file.  
ex:  
`cargo run --example diversify-address --<viewing_key> <index>`  
to:  
`./gen_diversify_address --<viewing_key> <index>`

---

<div class="post-metadata">

**Author:** ![str4d](https://sea2.discourse-cdn.com/zcash/user_avatar/forum.zcashcommunity.com/str4d/32/64_2.png) [@str4d](https://forum.zcashcommunity.com/u/str4d)\
**Post date:** [January 13, 2021, 3:59pm UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/11 "2021-01-13T15:59:46Z")

</div>

`cargo run` just calls `cargo build` and then runs the resulting binary. To get the binary yourself:

`cargo build --example diversify-address --release`

and then the binary should be at `target/release/examples/diversify-address`.

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 14, 2021, 3:46am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/12 "2021-01-14T03:46:05Z")

</div>

> [@goat](#):
>
> diversify

love you so much!

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 15, 2021, 8:24am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/13 "2021-01-15T08:24:56Z")

</div>

> [@goat](#):
>
> gen\_diversify\_address

hi 🙂  
I builded and run it for the testnet.  
But the index of address I set different with the result, you can see some ex:

./diversify-address – zxviewtestsapling1qv9ufts9qqqqpq94gjtgvss3065thw4e8sftpa4q20r9zjw8rafr0cyqnm6cxvu5l907cq9mgxdcvqvlcpjfmzkp46870yeu4w2e2fv66fs3udzasy6utye99a50ndskpks65y6mugcyq3n3ee5sedazejn00dx8yev8lqaw6cq2hr7m3wwmazfak3czl0eehjpdp0y2urrs7fj7zha4ahhz202qrlmzh0h2sep7v24f7v0l8pnrlf9thn5sc6dyvj75zl3quh792nc4jjcka **0**  
_result:_

# **Diversifier index: 3**

## ztestsapling14f874qp8a0fu74rwjgfwwt57tv89fu6345zdatp9k9re3adz3jhptaxqwyxdzjxqp72uyr8m54m

./diversify-address – zxviewtestsapling1qv9ufts9qqqqpq94gjtgvss3065thw4e8sftpa4q20r9zjw8rafr0cyqnm6cxvu5l907cq9mgxdcvqvlcpjfmzkp46870yeu4w2e2fv66fs3udzasy6utye99a50ndskpks65y6mugcyq3n3ee5sedazejn00dx8yev8lqaw6cq2hr7m3wwmazfak3czl0eehjpdp0y2urrs7fj7zha4ahhz202qrlmzh0h2sep7v24f7v0l8pnrlf9thn5sc6dyvj75zl3quh792nc4jjcka **1**  
_result:_

# Diversifier index: **3**

## ztestsapling14f874qp8a0fu74rwjgfwwt57tv89fu6345zdatp9k9re3adz3jhptaxqwyxdzjxqp72uyr8m54m

./diversify-address – zxviewtestsapling1qv9ufts9qqqqpq94gjtgvss3065thw4e8sftpa4q20r9zjw8rafr0cyqnm6cxvu5l907cq9mgxdcvqvlcpjfmzkp46870yeu4w2e2fv66fs3udzasy6utye99a50ndskpks65y6mugcyq3n3ee5sedazejn00dx8yev8lqaw6cq2hr7m3wwmazfak3czl0eehjpdp0y2urrs7fj7zha4ahhz202qrlmzh0h2sep7v24f7v0l8pnrlf9thn5sc6dyvj75zl3quh792nc4jjcka 2

_result:_

# Diversifier index: 3

ztestsapling14f874qp8a0fu74rwjgfwwt57tv89fu6345zdatp9k9re3adz3jhptaxqwyxdzjxqp72uyr8m54m

hoangphuong@PhuongMacBookPro examples % ./diversify-address – zxviewtestsapling1qv9ufts9qqqqpq94gjtgvss3065thw4e8sftpa4q20r9zjw8rafr0cyqnm6cxvu5l907cq9mgxdcvqvlcpjfmzkp46870yeu4w2e2fv66fs3udzasy6utye99a50ndskpks65y6mugcyq3n3ee5sedazejn00dx8yev8lqaw6cq2hr7m3wwmazfak3czl0eehjpdp0y2urrs7fj7zha4ahhz202qrlmzh0h2sep7v24f7v0l8pnrlf9thn5sc6dyvj75zl3quh792nc4jjcka **3**

# Diversifier index: **3**

ztestsapling14f874qp8a0fu74rwjgfwwt57tv89fu6345zdatp9k9re3adz3jhptaxqwyxdzjxqp72uyr8m54m

* * *

./diversify-address – zxviewtestsapling1qv9ufts9qqqqpq94gjtgvss3065thw4e8sftpa4q20r9zjw8rafr0cyqnm6cxvu5l907cq9mgxdcvqvlcpjfmzkp46870yeu4w2e2fv66fs3udzasy6utye99a50ndskpks65y6mugcyq3n3ee5sedazejn00dx8yev8lqaw6cq2hr7m3wwmazfak3czl0eehjpdp0y2urrs7fj7zha4ahhz202qrlmzh0h2sep7v24f7v0l8pnrlf9thn5sc6dyvj75zl3quh792nc4jjcka **100**

# Diversifier index: **102**

ztestsapling1qct4jge6tq89cvgahgu4knypgas6x5kqlhswq48l2y4k09nst5fxn5m82c46exr25f5csjw5chj

---

<div class="post-metadata">

**Author:** ![str4d](https://sea2.discourse-cdn.com/zcash/user_avatar/forum.zcashcommunity.com/str4d/32/64_2.png) [@str4d](https://forum.zcashcommunity.com/u/str4d)\
**Post date:** [January 15, 2021, 1:50pm UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/14 "2021-01-15T13:50:36Z")

</div>

Yes, this is expected: not every diversifier index results in a valid Sapling address (on average half of the 288 diversifiers will be invalid).

The example tool starts searching for the next Sapling address starting from the index you provide, and it returns the closest index for which it could find a valid address. You will need to account for this in your code.

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 17, 2021, 6:47am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/15 "2021-01-17T06:47:26Z")

</div>

Ok I see, thank you!

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 19, 2021, 11:39am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/17 "2021-01-19T11:39:27Z")

</div>

hi, so I user want to withdraw, I will send some zec to the user ( **one user** not many user).  
what’s the method I should use?

# sendtoaddress

or

# z\_sendmany

thank you!

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 20, 2021, 4:24am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/18 "2021-01-20T04:24:11Z")

</div>

./src/zcash-cli sendtoaddress ztestsapling1e7ncn23xnh5av9rsag5zyvn8gv6akzgl0nx9m6p5gxe27vdlx7mcquc6dd6djsyhqz4ucmkn35j 0.01 “xxx” “yyy” true

I have an error:  
Invalid Zcash address

---

<div class="post-metadata">

**Author:** ![goat](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@goat](https://forum.zcashcommunity.com/u/goat)\
**Post date:** [January 20, 2021, 7:29am UTC](https://forum.zcashcommunity.com/t/how-to-check-deposit-from-users/38151/19 "2021-01-20T07:29:04Z")

</div>

hi @str4d  
I have some code to transfer, but happen error, can you help me to check?

```
   ./src/zcash-cli getaccountaddress ""
tmFzUb6c8cP9kBR5w2L9vSZ2uMN2sgy5m5P

-------

./src/zcash-cli getbalance ""
0.12687863

------------------

./src/zcash-cli z_sendmany "tmFzUb6c8cP9kBR5w2L9vSZ2uMN2sgy5m5P" '[{"address": "ztestsapling1e7ncn23xnh5av9rsag5zyvn8gv6akzgl0nx9m6p5gxe27vdlx7mcquc6dd6djsyhqz4u
cmkn35j", "amount": 0.0001}]'
opid-8a715bef-ddf4-4a17-bdf3-b5dab15dc5ab

-------
./src/zcash-cli z_getoperationstatus '["opid-8a715bef-ddf4-4a17-bdf3-b5dab15dc5ab"]'
[
  {
    "id": "opid-8a715bef-ddf4-4a17-bdf3-b5dab15dc5ab",
    "status": "failed",
    "creation_time": 1611126515,
    "error": {
      "code": -6,
      "message": "Insufficient transparent funds, no UTXOs found for taddr from address."
    },

```
