Libra Core
Libra Core is a javascript library client that can be used to interact with libra nodes. It is built using typescript.
This is still under heavy testing, so please report any issues that you might encounter using it.
The end goal is to make it usable both in node and on browser clients too, but currently it is mostly compatible with node.
Table of Content
Prepare
- Node ^v12.0.0 is required for sha3-256. You can use nvm to download/use node v12 by following.
nvm install 12nvm use 12
Installation
To install with npm run:
npm install libra-core
Usage
You would most likely interact with these two modules
;
Creating an Account
In order to create a libra account, you would need to instantiate the LibraWallet
like:
// you may need to use require for node; // please don't use this mnemonic outside of this sample code// also mnemonics are optional. If you don't specify one a random mnemonic is generated and used.const wallet = mnemonic: 'upgrade salt toy stable drop paddle' ; // generate a new accountconst account = wallet; // or if you have your secret key you can create an account from it// const secretKey = 'pub-hex-secret-key-here' // const account = LibraAccount.fromSecretKey(secretKey); // you can see your address by:console;
Minting Amount
Currently minting only works for testnet and uses the faucet service.
To mint you need to create a LibraClient
and use it to mint
; { const client = network: LibraNetworkTestnet ; const account = wallet; // mint 2 libracoins to users accounts await client;} await ;
Checking an address balance
{ const client = network: LibraNetworkTestnet ; const accountAddress = '854563c50d20788fb6c11fac1010b553d722edb0c02f87c2edbdd3923726d13f'; const accountState = await client; // log account balance console; // Account state has other information that you could be interested in such as `sequenceNumber`.} await ;
Transferring Libra Coins
{ const client = network: LibraNetworkTestnet ; const wallet = mnemonic: 'lend arm arm addict trust release grid unlock exhibit surround deliver front link bean night dry tuna pledge expect net ankle process mammal great' ; const account = wallet; const account2Address = '854563c50d20788fb6c11fac1010b553d722edb0c02f87c2edbdd3923726d13f'; const response = await client; // wait for transaction confirmation await response;} await ;
Executing Transactions with Custom Program
You can execute a program using client.execute()
take a look at how client.transferCoins()
uses it for transfer transactions.
You are welcome to help contribute to making this documentation better.
Query Transaction with Sequence Number
{ const client = network: LibraNetworkTestnet ; const accountAddress = '7f58df27522872ecfac340c5c072427e6f8083ca3c79bb748cdd1ae073dacc42'; const sequenceNumber = 43; //can also use a string for really large sequence numbers; const transaction = await client;} await ;
Development
- Clone the repository
- Run
npm install
to install the dependency - Test with
npm test
- You might need to run
npm install -g grpc-tools
if you want to regenerate protobuffer classes
Contribution
- If you notices a bug or anomaly, please open an issue to track it.
- If you intend on working on a feature that doesn't have an issue yet. Please open an issue first so we can track its progress together.
License
MIT