## z-address geneneration

z-address i.e. shielded address, is the address format that TRONZ uses. It is determined by an `sk` and `d` key. One can publish its z-address and receive shielded transactions.

`sk` is the hidden private key. `d` is an identifier of different addresses generated from `sk`, can be used to implement HD-wallets. All other keys are used in different occasions.

Take an address as an example: `ztron1m445gx74mjuuyhkyru5hrx886jszfga4a7dk3mg4uarrl0cru649jz4928tm6rqul2pg645hqv5`. The address is in [bech32](🔗) format. `ztron1` is the fixed prefix. The remains are encoded value of `pkD` and `d`.

Comparing to the original TRON address format `T-....`, one can call it a transparent address or T-address.

Key and z-address related APIs are:

There are 3 main tasks related to shielded transaction:

  • transfer from T-address to z-address, `mint` for shielded trc20

  • transfer between z-addresses, `transfer` for shielded trc20

  • transfer from z-address to T-address, `burn` for shielded trc20

## Shielded TRC20 Contract

## Usage

### Prerequisite - a shielded TRC20 contract

The shielded contract is at <https://raw.githubusercontent.com/tronprotocol/java-tron/feature/shieldedUSDT/deploy/ShieldedTRC20.sol>.

It can only be compiled with solidity variation from TRON: <https://github.com/tronprotocol/solidity>, and the code branch is `develop`.

Deploy the code with constructor parameter `(TF17BgPaZYbz8oxbjhriubPDsA7ArKoLX3, 18)`. We got a shielded TRC20 address TNnFMMykZzwhPZkurKtNMyVGvgeSkCrnPi.

Where TF17BgPaZYbz8oxbjhriubPDsA7ArKoLX3 is the TRC20 address of JST token in Nile Testnet, `1` is the exponent of the scaling factor.

### Transfer to z-address - mint

Before any transferring, use the `approve` method of the original TRC20 to approve the required amount of tokens to the shielded TRC20 contract.

Suppose we want to transfer tokens to the address `ztron1s2s9fpf2v2l3d8mgzf7dqnfptkrlmyekvaqlw50lpf8dz8xkdgphjuxaysh4h0wvml8qzjzrv36`.

First, create `rcm`:

Then, construct the shielded contract parameters:

  • `from_amount` is of string type

  • `value` is `from_amount` divided by `scalingFactor`

Then we got the response, the only one we care is `trigger_contract_input`:

Concat `[855d175e]`(signature of mint()) with `trigger_contract_input`, we got the calling parameter. Sign the `TriggerSmartContract` transaction with the T-address and broadcast.

Here is an example of the parameters of `TriggerSmartContract`.

Transaction: <https://nile.tronscan.org/#/transaction/d05078358d359450aa8f57df7722d2d338e53af15362f852b1d7e6b5c4b8f47b>

### Query incoming notes

Use `wallet/scanshieldedtrc20notesbyivk` with `ivk`, `ak`, `nk`. You can only scan 1000 blocks at once.

The returned note has a field called `is_spent`.

### Transfer between z-addresses - transfer

All transfers are based on `note`. You can transfer 1-2 notes to 1-2 notes. The total balanced must be matched.

`alpha` and `rcm` are generated by `wallet/getrcm` API.

### Query outgoing notes

Use `wallet/scanshieldedtrc20notesbyovk` with `ovk`.

### Is a note spent

Use `wallet/isshieldedtrc20contractNoteSpent` with `ak`, `nk`.

### Transfer from z-address to T-address - burn

Almost the same as a `transfer`. The `TriggerSmartContract` transaction can be broadcasted by anyone.

## References

The detailed usage document is [Here](🔗).