Skip to content

Public peer-to-peer note transactions

In this section, we show you how to execute transactions and send funds to another account using the Miden client and public notes.

Prerequisite steps

Create a second client

Tip

Remember to use the Miden client documentation for clarifications.

This is an alternative to the private P2P transactions process.

In this tutorial, we use two different clients to simulate two different remote users who don’t share local state.

To do this, we use two terminals with their own state (using their own miden-client.toml).

  1. Create a new directory to store the new client.

    mkdir miden-client-2
    cd miden-client-2
    
  2. Initialize the client. This creates the miden-client.toml file line-by-line.

    miden-client init 
    

    Accept the defaults for Protocol, Node RPC Port, and Sqlite file pathby clicking enter.

    When Host comes up, enter 18.203.155.106

    Host (default: localhost): 18.203.155.106
    
  3. On the new client, create a new basic account:

    miden-client account new basic-mutable -s on-chain
    

    We refer to this account as Account C. Note that we set the account’s storage mode to on-chain, which means that the account details are public and its latest state can be retrieved from the node.

  4. List and view the account with the following command:

    miden-client account -l
    

Transfer assets between accounts

  1. Now we can transfer some of the tokens we received from the faucet to our new account C. Remember to switch back to miden-client directory, since you’ll be making txn from Account ID A.

    To do this, from the first client run:

    miden-client tx new p2id --note-type public <basic-account-id-A> <basic-account-id-C> <faucet-account-id> 50 
    

    Note

    The faucet account id is 0xad904b3138d71d3e and can also be found on the Miden faucet website under the title Miden faucet.

    This generates a Pay-to-ID (P2ID) note containing 50 tokens, transferred from one account to the other. As the note is public, the second account can receive the necessary details by syncing with the node.

  2. First, sync the account on the new client.

    miden-client sync
    
  3. At this point, we should have received the public note details.

    miden-client input-notes list 
    

    Because the note was retrieved from the node, the commit height will be included and displayed.

  4. Have the second account consume the note.

    miden-client tx new consume-notes <regular-account-ID-C> <input-note-id> 
    

    Tip

    It’s possible to use a short version of the note id: 7 characters after the 0x is sufficient, e.g. 0x6ae613a.

That’s it!

Account C has now consumed the note and there should be new assets in the account:

miden-client account show <account-ID-C> -v

Comments