Namada tinkerer notes

2pilot
Coinmonks
Published in
10 min readNov 26, 2023

--

It’s tinkering time

This tutorial is for those who want to tinker with namada and understand some if it core features like operations with transparent and multisig accounts, as well as shielded transfers. I’m using campfire dev chain for this guide and assume that you have already built or downloaded namada binaries and your node is synced and running. If your node is not up try this or campfire guide to set it up.

What’s namada

Namada is cosmos and ethereum compatible L1 blockchain that provides a privacy layer via multi-asset shielded pool (MASP).

You can transfer your assets to MASP from one wallet and withdraw to another. This way you achieve effect similar to when you withdraw from CEX, but without sacrificing your data to any third party.

One cool thing about MASP is that it can support any kind of token: fungible and non-fungible. So if you send your NFT to a shielded pool where only eth tokens where stored, for the outside world your nft transfers within MASP will be indistinguishable from any other transactions.

The other cool thing is that not only you protect your privacy with Namada you also get rewards by shielding and storing your funds in MASP.

Namada is also much more, but we’ll focus on the basics here.

Transparent accounts

Before we start, we need to create 2 accounts which we will use during this whole article. And the only thing we need is to come up with the names…

You thinking what I’m thinking ?

Let’s export all necessary variables to reuse them later

export ACCOUNT_KEY_1="B1" && \
export ACCOUNT_KEY_2="B2" && \
export MULTISIG_ADDRESS=banana-bro-power && \
export SPENDING_KEY_1=$ACCOUNT_KEY_1-spending-key && \
export SPENDING_KEY_2=$ACCOUNT_KEY_2-spending-key && \
export PAYMENT_ADDRESS_1=$ACCOUNT_KEY_1-payment-address && \
export PAYMENT_ADDRESS_2=$ACCOUNT_KEY_2-payment-address && \
export RPC="localhost:26657" && \
export BASE_DIR="$HOME/.local/share/namada" && \
export TOKEN=NAM

Don’t worry about too much variables at the moment. We will tackle them one by one.

I’m fine

At the top export ACCOUNT_KEY_1=”B1" && export ACCOUNT_KEY_2=”B2" are the account names we are going to use. At the bottom export RPC=”localhost:26657" is the default rpc address. Note that you can use different host and port depending on your node configuration. You can also use some publicly available RPC and in that case you don’t to set up your node at all.

export BASE_DIR=”$HOME/.local/share/namada” is the default dir with configuration for namada node

export TOKEN=NAM — is the name of the token we are going to use

The rest of the variables will be described and used later.

To create our account keys

namada wallet key gen --alias $ACCOUNT_KEY_1

During the process you will get the following prompt

You would need to come up with your encryption password which you will need every time you perform a transaction with this account and you need to remember the 24 words mnemonic phrase was given to you to be able to restore your account.

Let’s create the second account

namada wallet key gen --alias $ACCOUNT_KEY_2

You can view your accounts by running namada wallet key listand the output will be

Each account has associated address with it. To view it run namada wallet address list

You might see a bigger list of addresses, just make sure you didn’t loose your banana addresses.

What we just created is called implicit account. You don’t need initialize them on chain and can send any tokens to the corresponding tnam address straight away.

You can also check your implicit account balance by running

namada --base-dir $BASE_DIR client balance \
--ledger-address $RPC \
--token $TOKEN \
--owner $ACCOUNT_KEY_1

Right now it is empty

But after funding it with the help of a faucet or your fellow comrades from discord it should look something like this

Let’s share some tokens with your BFF B2 by performing transfer transaction

namada --base-dir $BASE_DIR client transfer \
--source $ACCOUNT_KEY_1 \
--target $ACCOUNT_KEY_2 \
--token $TOKEN \
--amount 10 \
--ledger-address $RPC \
--signing-keys $ACCOUNT_KEY_1

You will be asked to enter your passphrase which you provided when creating b1 account to decrypt first account and you will see the following output

Let’s check our updated balances

Cool, now B2 is closer to bying it’s dream car. Or at least a toy car…

The car B2 deserves but not the one it needs

Note that first account was deducted more than 10 nam, to cover transaction gas fees. To check how much you will pay you can ad --dry-run-wrapper flag at the end of transfer command

namadac transfer \
--source $ACCOUNT_KEY_1 \
--target $ACCOUNT_KEY_2 \
--token NAM \
--amount 1 \
--signing-keys $ACCOUNT_KEY_1 \
--dry-run-wrapper

From the output bellow you can see that 7616 gas is required for this transaction

Next we can specify gas limit for this transaction. It could be useful if your account is low on budget and the default gas limit will be too much for your balance. Just keep in mind, if you specify gas limit less than is actually required your transaction will be reverted and you will still pay partial gas fees.

namadac transfer \
--source $ACCOUNT_KEY_1 \
--target $ACCOUNT_KEY_2 \
--token NAM \
--amount 1 \
--signing-keys $ACCOUNT_KEY_1 \
--gas-limit 7616

Multisignature accounts

Namada also supports multisignature accounts which is a variation of a transparent account that gives you better security and recovery options. To create multisig account

namadac init-account \
--alias $MULTISIG_ADDRESS \
--public-keys $ACCOUNT_KEY_1,$ACCOUNT_KEY_2 \
--signing-keys $ACCOUNT_KEY_1,$ACCOUNT_KEY_2 \
--gas-payer $ACCOUNT_KEY_1 \
--threshold 2

Let’s make sure we have newly created address by typing

namada wallet address list

and indeed we have it

You might have noticed that this account has a different type —established. We created it with init transaction and tnam address was generated on chain. Before init transaction finishes, address is not known by anyone.

This address will have all the features standard addresses have. Let’s verify that by transfering some tokens into it.

namada --base-dir $BASE_DIR client transfer \
--source $ACCOUNT_KEY_1 \
--target $MULTISIG_ADDRESS \
--token NAM \
--amount 5 \
--ledger-address $RPC \
--signing-keys $ACCOUNT_KEY_1

And confirm it now has a positive balance by running

namada --base-dir $BASE_DIR client balance \
--ledger-address $RPC \
--token $TOKEN \
--owner $MULTISIG_ADDRESS

Now, if it behaves like a standard account, what’s the catch ? The difference comes into place when we need to sign and submit any transaction from it. We cannot send tx straight away like we did with standard account. We need approval of both keys ( in our case B1 and B2 ) that participated in multisig address creation. This provides better security to your account, because if one of the source keys was compromised, it won’t be possible to drain your funds without second key approval.

Together. Stronger.

To do this, first we need to generate transaction data and save it to a file. Lets create a folder for transaction data

mkdir tx_dumps

save tx data into file

namadac transfer \
--source $MULTISIG_ADDRESS \
--target $ACCOUNT_KEY_2 \
--token NAM \
--amount 4 \
--signing-keys $ACCOUNT_KEY_1,$ACCOUNT_KEY_2 \
--gas-payer $ACCOUNT_KEY_1 \
--dump-tx \
--output-folder-path tx_dumps

in my case the following file was generated, but in your case name will be different

Let’s export tx data file path into variable ( but keep in mind your filename will be different )

export TX_PATH="tx_dumps/8DE73F0F6DC401C96A6867B45BF00F404CC0B28EB4DFF1B45CCC1A0F795DEA7A.tx"

and sign tx data with 2 keys


namadac sign-tx \
--tx-path $TX_PATH \
--signing-keys $ACCOUNT_KEY_1 \
--owner $MULTISIG_ADDRESS && \
namadac sign-tx \
--tx-path $TX_PATH \
--signing-keys $ACCOUNT_KEY_2 \
--owner $MULTISIG_ADDRESS

This will output for you two signatures ( I’ve highlighted the first one )

which you will use next to send the transaction ( remember to update signature values for your own ones )

namadac tx \
--tx-path $TX_PATH \
--signatures offline_signature_8DE73F0F6DC401C96A6867B45BF00F404CC0B28EB4DFF1B45CCC1A0F795DEA7A_tpknam1qzatwwvlsda4k8zlzemu343lzq6aktgc9v2fxlvpd7pcz3x036f0k5arv0j.tx \
--signatures offline_signature_8DE73F0F6DC401C96A6867B45BF00F404CC0B28EB4DFF1B45CCC1A0F795DEA7A_tpknam1qq6u9v9x28063djep2c2jsk6luh66pxrnz4x7nsc5zg442a0whzv7y5zvd3.tx \
--owner $MULTISIG_ADDRESS \
--gas-payer $ACCOUNT_KEY_1

Cool. Now your b2 account now has 4 extra NAM tokens.

Shielded accounts

Have you ever had this feeling that someone is watching all your wallet transactions and knows everything about your financial situation ?

Somebody’s watching me

We all do. But fret not, it’ll be fixed in a moment.

First let’s generate spending keys

namadaw masp gen-key --alias $SPENDING_KEY_1 && \
namadaw masp gen-key --alias $SPENDING_KEY_2

Next let’s generate payment address.

namadaw masp gen-addr \
--key $SPENDING_KEY_1 \
--alias $PAYMENT_ADDRESS_1 && \
namadaw masp gen-addr \
--key $SPENDING_KEY_2 \
--alias $PAYMENT_ADDRESS_2

Spending key allows to you to spend and view balance of the corresponding shielded address ( SPENDING_KEY_1 for PAYMENT_ADDRESS_1 and SPENDING_KEY_2 for PAYMENT_ADDRESS_2 ). Every time you execute gen-addr with the same spending key you will get new shielded address. It could be reused or discarded and there is no relationship between those addresses. That’s a great way disguise your transaction history !

To view masp keys and addresses we can use

namadaw masp list-keys 

and

namadaw masp list-addrs

The output will be

Let’s shield your assets now by transfering some of NAM tokens to the shielded address

namadac transfer \
--source $ACCOUNT_KEY_1 \
--target $PAYMENT_ADDRESS_1 \
--token NAM \
--amount 2

Check your shielded balance

namadac balance --owner $SPENDING_KEY_1

Note that we are using SPENDING_KEY_1 to view the balance. Only shielded address owner can do it. From now on all your transactions will be hidden for unwanted observers.

Your tx history inside MASP

No one is watching you and your transactions inside MASP are untraceable. For example let’s perform shielded transfer to your second payment address

namadac transfer \
--source $SPENDING_KEY_1 \
--target $PAYMENT_ADDRESS_2 \
--token NAM \
--amount 1 \
--signing-keys $ACCOUNT_KEY_1

check balance is updated

namadac balance --owner $SPENDING_KEY_2

output

Your balance at epoch 328

You will also get rewards for storing your assets in shielded pool every new epoch. The longer you stay —the more profit you’ll get !

When you feel it’s time to leave your safe harbor just unshield you funds and go see the bigger world.

namadac transfer \
--source $SPENDING_KEY_2 \
--target $ACCOUNT_KEY_2 \
--token NAM \
--amount 0.5 \
--signing-keys $ACCOUNT_KEY_2

Just keep in mind that from now on you are operating with transparent address and you history is recorded. You can tranfer to a new wallet without any history and start from scratch though.

Let’s try one last thing…

Last time, when we made unshielded transfer, B2 account covered our gas fees. What if all our NAM tokens were in MASP to receive shielded pool rewards and B2 address didn’t have any NAM tokens. It is possible to pay the fees with MASP from your shielded address without the need to unshield them

Let’s check our account balance

namadac balance --owner $ACCOUNT_KEY_2

In my case it was 15.95 NAM

Try transfer full b2 balance to b1

namadac transfer \
--source $ACCOUNT_KEY_2 \
--target $ACCOUNT_KEY_1 \
--token NAM \
--amount 15.95 \
--gas-payer $ACCOUNT_KEY_2

Transaction will be reverted as you do not have enough NAM tokens to send after applying gas fees. Now your balance is reduced, but you haven’t send your tokens

Farewell to gas fees spent for nothing

Transfer full amount again, but use spending key from your shielded address with balance

namadac transfer \
--source $ACCOUNT_KEY_2 \
--target $ACCOUNT_KEY_1 \
--token NAM \
--amount 15.925 \
--gas-payer $ACCOUNT_KEY_2 \
--gas-spending-key $SPENDING_KEY_1

Now you transfered full balance from b2 to b1 and payed for gas fees using spending key. Keep in mind that tokens required to cover gas fees will be unshielded from shielded address and transfered to gas payer account ( B2 in our case ), so you’ll pay a little bit more.

If you want to disguise a gas payer you can use--disposable-gas-payer flag

namadac transfer \
--source $ACCOUNT_KEY_2 \
--target $ACCOUNT_KEY_1 \
--token NAM \
--amount 15.925 \
--gas-spending-key $SPENDING_KEY_1 \
--disposable-gas-payer

which will generate a disposable transparent address that will cover gas fees.

Imagine a universe where

  • Individuals have the freedom to decide which information they wish to share with the public and what they prefer to keep private
  • Usage of privacy is rewarded as a public good

Namada is a portal to such place.

Happy travels

See you in part 2 where we discuss governance, staking and delegation rewards.

--

--