This article will guide you through executing your first transaction on the Libra Blockchain.
Clone the Libra Core Repository:
git clone https://github.com/libra/libra.git
Change to the libra directory
cd libra
Setup Libra Core:
To setup Libra Core, run the setup script to install the dependencies
./scripts/dev_setup.sh
The setup script performs these actions:
- Installs rustup — rustup is an installer for the Rust programming language, which Libra Core is implemented in.
- Installs the required versions of the rust-toolchain.
- Installs CMake — to manage the build process.
- Installs protoc — a compiler for protocol buffers.
- Installs Go — for building protocol buffers.
Build Libra CLI Client and Connect to the Testnet
To connect to a validator node running on the Libra testnet, run the client as shown below.
./scripts/cli/start_cli_testnet.sh
Once the client connects to a node on the testnet, you will see the following output.
Check If the CLI Client Is Running on Your System:
To see the help information for the account
command enter “account” as shown below:
Create Alice’s Account
To create Alice’s account, enter this command:
libra% account create
Sample output on success:
>> Creating/retrieving next account from wallet
Created/retrieved account #0 address 5993ea6f4632fb962be6e7ac019f4257c2f14fdf14e5a4ee3be0f681e54a7b5e
#0 is the index of Alice’s account, and the hex string is the address of Alice’s account.
Create Bob’s Account:
To create Bob’s account, repeat the account creation command:
libra% account create
Sample output on success:
>> Creating/retrieving next account from wallet
Created/retrieved account #1 address cff7b9ba48d423dfc04e0a7d0b7ecdd035e6df08157782fd70405430c63ca2d1
#1 is the index for Bob’s account, and the hex string is the address of Bob’s account.
List Accounts:
libra% account list
Sample output on success:
User account index: 0, address: 5993ea6f4632fb962be6e7ac019f4257c2f14fdf14e5a4ee3be0f681e54a7b5e, sequence number: 0, status: Local
User account index: 1, address: cff7b9ba48d423dfc04e0a7d0b7ecdd035e6df08157782fd70405430c63ca2d1, sequence number: 0, status: Local
The sequence number for an account indicates the number of transactions that have been sent from that account.
Add 110 Libra to Alice’s Account:
libra% account mint 0 110
- 0 is the index of Alice’s account.
- 110 is the amount of Libra to be added to Alice’s account.
Sample output on success:
>> Minting coins
Mint request submitted
Add 52 Libra to Bob’s Account
libra% account mint 1 52
Sample output on success:
>> Minting coins
Mint request submitted
Check the Balance:
To check the balance in Alice’s account, enter this command:
libra% query balance 0
Sample output on success:
Balance is: 110
To check the balance in Bob’s account, enter this command:
libra% query balance 1
Sample output on success:
Balance is: 52
Query the Accounts’ Sequence Numbers
libra% query sequence 0
>> Getting current sequence number
Sequence number is: 0libra% query sequence 1
>> Getting current sequence number
Sequence number is: 0
A sequence number of 0 for both Alice’s and Bob’s accounts indicates that no transactions from either Alice’s or Bob’s account have been executed so far.
Submit a Transaction
Before we submit a transaction to transfer Libra from Alice’s account to Bob’s account, we will query the sequence number of each account. This will help us understand how executing a transaction changes the sequence number of each account.
libra% query sequence 0
>> Getting current sequence number
Sequence number is: 0libra% query sequence 1
>> Getting current sequence number
Sequence number is: 0
Transfer Money
libra% transfer 0 1 10
Sample output on success:
>> Transferring
Transaction submitted to validator
To query for transaction status, run: query txn_acc_seq 0 0 <fetch_events=true|false>
0 is the index of Alice’s account.
1 is the index of Bob’s account.
10 is the number of Libra to transfer from Alice’s account to Bob’s account.
Retrieve the information about the transaction :
libra% query txn_acc_seq 0 0 true
Sample output on success:
Getting committed transaction by account and sequence number
Committed transaction: SignedTransaction {
raw_txn: RawTransaction {
sender: 5993ea6f4632fb962be6e7ac019f4257c2f14fdf14e5a4ee3be0f681e54a7b5e,
sequence_number: 0,
payload: {,
transaction: peer_to_peer_transaction,
args: [
{ADDRESS: cff7b9ba48d423dfc04e0a7d0b7ecdd035e6df08157782fd70405430c63ca2d1},
{U64: 10000000},
]
},
max_gas_amount: 10000,
gas_unit_price: 0,
expiration_time: 1560880276s,
},
public_key: 09434588784ea49844e622c023df9e1fa3c52ff7ca7e51f970fc80c2bd2e759c,
signature: Signature( R: CompressedEdwardsY: [202, 230, 255, 181, 94, 160, 144, 218, 61, 165, 204, 18, 156, 164, 154, 222, 187, 79, 165, 183, 153, 32, 183, 47, 187, 95, 208, 182, 159, 226, 127, 91], s: Scalar{
bytes: [100, 247, 195, 92, 83, 157, 100, 112, 110, 203, 47, 167, 86, 75, 239, 138, 8, 119, 71, 255, 15, 87, 157, 158, 59, 154, 160, 45, 42, 24, 101, 4],
} ),
}
Events:
ContractEvent { access_path: AccessPath { address: 5993ea6f4632fb962be6e7ac019f4257c2f14fdf14e5a4ee3be0f681e54a7b5e, type: Resource, hash: “217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97”, suffix: “/sent_events_count/” } , index: 0, event_data: AccountEvent { account: cff7b9ba48d423dfc04e0a7d0b7ecdd035e6df08157782fd70405430c63ca2d1, amount: 10000000 } }
ContractEvent { access_path: AccessPath { address: cff7b9ba48d423dfc04e0a7d0b7ecdd035e6df08157782fd70405430c63ca2d1, type: Resource, hash: “217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97”, suffix: “/received_events_count/” } , index: 0, event_data: AccountEvent { account: 5993ea6f4632fb962be6e7ac019f4257c2f14fdf14e5a4ee3be0f681e54a7b5e, amount: 10000000 } }
libra%
Query Sequence Number After Transfer
libra% query sequence 0
>> Getting current sequence number
Sequence number is: 1libra% query sequence 1
>> Getting current sequence number
Sequence number is: 0
The sequence number of 1 for Alice’s account (index 0) indicates that one transaction has been sent from Alice’s account so far.
Check the Balance in Both Accounts After Transfer
libra% query balance 0
Balance is: 100libra% query balance 1
Balance is: 62
Congratulations!
You have successfully executed your transaction on the Libra testnet and transferred 10 Libra from Alice’s account to Bob’s account!
If you want to learn about move programming language read my latest written blog: https://deqode.com/blog/move-language-tutorial/