How to Make a “T” to “Z” Transfer in Zcash


Informal twitter poll of zcash knowledge

The Zcash value proposition is in private transactions, however, private transactions are not the default and many users simply do not know how to initially create shielded (private) transactions, aka a “t” => “z”. In simple terms, it is important to have a large pool of shielded transactions provides for a larger anonymity set for private transactions; it is harder to pick out any one zebra in a large zeal than it is to point out a single animal in a small cluster. This process, and having more people familiar with it, provides greater value to my work on cross chain atomic swaps (x-cats in zcash speak) so I have attempted to unravel the apparent mystery below. No math, dark magic, animal sacrifice required.

Side note: If you would like to contribute to the greatest good, while exerting minimum effort for the zcash ecosystem, hold you coins in a “z” address. this benefits everyone using zk transactions and increases the size of the anonymity set. Currently, as shown below, this is an uncommon practice.

https://zcha.in/statistics/value

How

© 2018 ZEROCOIN ELECTRIC COIN COMPANY

The general process for shielding ZEC is as follows:

  1. Generate both a “t” address and “z” address

The “t” address works the same as a bitcoin address. When you send from your transparent address the change from the transaction will be sent to a new t address you control and all the transactions will be visible on block explorers. “Z” addresses are the private ones and you will only be able to see the balance in the wallet. When sending to and from a Z address, only the exact amount (minus fees) is sent, the change remains with the same “z” address. No one observing the transaction will see any information about the “z” address, except during shielding and deshielding.

2) Fund the “t” address

Funding your “t” address means sending ZEC to it. Zcash can be traded for or purchased many places. Gemini allows US customers to purchase ZEC with US Dollars.

3) Send from your “t” => “z” using a zcash wallet such as zcashd or winzec

It is actually as easy as that sounds. Sending from “t” to “z” or “z” to “z” or “z” to “t” is all the same procedure. This step is overlooked in the zcash documentation because it is so trivial. Maybe they will add it in future versions to avoid confusion. https://github.com/zcash/zcash/wiki/1.0-User-Guide

Notes

“t” addresses send change to new accounts, “z” notes do not

do not send from “z” => same “t” or the change account, always use a ‘clean’ “t” address when deshielding

avoid sending the same amount into and out of shielding transactions. While 10 zec in and out is less traceable than 2.3123 zec, 10 zec in and a random amount of zec out is better

Methods

Hard

0. Get zcashd running

Get the latest copy of zcashd (https://github.com/zcash/zcash/releases) or use a docker container (docker pull bcrd/zcash)

  1. Generate “t” and “z” addresses

To generate a t address you use the commands

$ ./src/zcash-cli getnewaddress

To generate a z address use the command:

$ ./src/zcash-cli z_getnewaddress

2 . Fund your t address

Send ZEC to the t address created above

3. Send many

If you are like me, you hate typing or even pasting long inscrutable numbers. In linux you can save strings with shortcuts like this:

TADDR=”yourAddress”

But actually type or paste your address. after that you can recall it by typing the letters with a dollar sign in front of it:

$TADDR

So assuming you funded your t address with 1.001 zec the `z_sendmany` command will allow you to shield that value:

$ ./src/zcash-cli z_sendmany "$TADDR" "[{\"amount\": 1.0, \"address\": \"$ZADDR\"}]"

Be mindful of the quotes and backslashes, they matter.

This will return you an opid code which is used in your wallet for tracking the shielding process. You can check the progress using:

$ ./src/zcash-cli z_getoperationresult

Status success is what you are wanting. After you get a success you can verify the funds using:

$ ./src/zcash-cli z_listreceivedbyaddress "$ZADDR"

Easy Mode

0. Get winZec

Download the “unofficial” windows version of zcash. It can be found at http://winzec.com/

1. Create addresses

click the new T (transparent) address button

click the new Z (private) address button

2. Fund

Fund your “t” address

3. Send

winzec

On the send cash tab, select your funded t address. enter your z address in the destination address and the amount to shield.

Click send and watch the progress bar to see when it completes

That’s it!

Note: When you are sending, there are two fee boxes. The first is the network fee, you must pay this to have your transaction included in a block. The second is the wallet dev fee, this is an optional donation to ralfstx to support the windows and mac wallet development. If you have used both methods, you will quickly realize the importance of gui and its continued funding. Open source development is often a thankless process, so money is always nice way of saying thank you.


Tips:

zchbDpcotZTCScgwa2HU2hxhn62yebYphrwDhpK43YAeo158Mo5R8ACiJY1nFjeeMUBf6JYGCoH4Yx4b8YvDW7r5dKtGWnv

Simple Locking Contracts: Part 2

The Ballad of Saint Hodl

Inactivity strikes us as intelligent behavior. Neither we nor most business managers would dream of feverishly trading highly profitable subsidiaries because a small move in the Federal Reserve’s discount rate was predicted or because some Wall Street pundit had reversed his views on the market. Why, then, should we behave differently with our minority positions in wonderful businesses? — Warren Buffet

In part 1 of the series we learned about conditionally locking contracts that allow for two parties to transact value on an ethereum chain using a secret hashed password funds could be kept in public view and then retrieved at a future time. In this article, we will allow a user to send coins to a contract for safe keeping until some point in the future. In crypto trading terms this is know as “Hodling” and is an optimal strategy in investing in general( see: Warren Buffet)

The History of Hodl

In 2013, a user named GameKyuubi posted a now infamous, admittedly drunken, post on his poor luck as a trader.

I AM HODLING

I AM HODLING

I AM HODLINGbitcointalk.org

GameKyuubi understood the importance of holding assets long term as a value investor, however, they lacked the strength of will to do so with the ease of trading options that were available. It is by this example that we will work on a chaincode that will allow the block chain to do the hard work “Hodling” for us.

The Saint Hodl Contracts

Saint Hodl
'-._ ```"""---.._
,-----.:___ `\ ,;;;,
'-.._ ```"""--.._ |,%%%%%% _
, '. `\;;;; -\ _ _.'/\
.' `-.__ \ ,;;;;" .__{=====/_)==:_ ||
,===/ ```";,,,,,,,;;;;;'`-./.____,'/ / '.\/
'---/ ';;;;;;;;' `--.._.' /
,===/ '-. `\/
'---/ ,'`. |
; __.-' \ ,'
jgs \______,,.....------'''`` `---`

TL;DR

Send funds, get later. All of the following contracts will be made available for use on SaintHodl.com for ease of access and are also available as an open source resource on github. You can use your Jaxx.io,MEW, or any Ethereum Classic wallet to interact with them, for free!

The Most Important Part

A time locked contract cannot be opened early. You cannot negotiate with the blockchain, your locked funds are safely tucked away until the predetermined amount of blocks have passed. No backsies.

So in the time locked contract (TLC) this variable is made public and is listed first. Anyone viewing the contract should easily be able to view this number and know what they are getting into ahead of time. In sainthodl’s contract it is written as:

uint public freezeBlocks = 20;

This sets the contract freeze time up for 20 blocks, which is ~280 seconds or 4.67 minutes. Not a long time, but enough for testing. (There is a 2 million block option on site if you are looking for something more 😉 )

Freeze blocks viewed on

Lockers

In part one, hash boxes were publicly view-able. The same will be true with our TLC contracts. Each ‘box’ will consist of 3 details: the owner, how long to hold coins, and how many coins are being held.

struct locker{      
uint freedom;
uint bal;
}
mapping (address => locker) public lockers;

Every address will now be mapped to a unique locker.

Sending funds to a Locker

Whenever anyone sends coins to our TLC contract we want it to add funds to their locker and set the freeze time to some block in the future. To do this we will be using the fall back function in the solidity contract:

function() payable public {        
locker storage l = lockers[msg.sender];
l.freedom = block.number + freezeBlocks;
l.bal = l.bal + msg.value;
}

The locker will be identified by the user sending funds( locker “l” is the locker of the message sender). We then use the latest block.number and add the predetermined number of freeze blocks to get our “freedom block”. The lockers balance will be calculated from its current balance (0 normally) and the value that was sent with the message. If you use the abi from the github with MyEtherWallet.com you will now be able to see everything in the locker (Balance will be in Wei)

Using Mew Contract interface

The Second Most Important Part: Withdrawing

Finally, the urge to panic sell has passed, and you can now safely be trusted to get your funds back. Unlike the hashlocked contract where anyone with the preimage could claim the funds, only the owner of a locker is able to withdraw their funds from the TLC. A word of caution; when allowing strangers to withdraw from a contract it is important to avoid opening up to recursive calls. The Dao contract failed because of this design flaw. This would work by someone calling the withdraw function from a contract that had its fallback function set to also call the withdraw function. To avoid this we will set the lockers balance to zero before we send any funds; this way if a contract calls back it would only be able to withdraw zero.

function withdraw() public { 
locker storage l = lockers[msg.sender];
require (block.number > l.freedom && l.bal > 0);
// avoid recursive call
uint value = l.bal;
l.bal = 0;
msg.sender.transfer(value);
}

Similar to the first function, locker “l” is the locker of the message sender. We then require that both the current block number be greater than the lockers freedom block and that the lockers balance be greater than zero. If either of these conditions are not met, the function will ‘fail’ i.e. not do anything. If both conditions are met; the lockers balance is saved as ‘value’, the original balance is set to zero, and then value is sent to the locker owner.

Withdraw function on Mew

Events

If you read through the contract you will notice two “events” that show up:

event Locked(address indexed locker, uint indexed amount);    
event Released(address indexed locker, uint indexed amount);

These events are displayed in wallets that watch for events and can be used to trigger things like posting to twitter.

Contract as viewed in Parity

Conclusion

With this simple contract anyone is able to commit and retrieve coins on the chain for as short or as long as they like. Part 3 will combine the functions of part 1 & 2 to create a hash-time locked contract to do some really cool things!