Skip to content

Commit

Permalink
Cleanup and format
Browse files Browse the repository at this point in the history
  • Loading branch information
perfectmak committed Jun 24, 2019
1 parent 1813c6a commit 5b6a57e
Show file tree
Hide file tree
Showing 39 changed files with 4,257 additions and 2,207 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
node_modules
node_modules
.DS_Store
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
}
74 changes: 74 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,79 @@ To install with npm run:
npm install libra-core
```

## Usage

You would most likely interact with these two modules

```javascript
import { LibraWallet, LibraClient } from 'libra-core';
```

### Creating an Account

In order to create a libra account, you would need to instantiate the `LibraWallet` like:

```javascript
import { LibraWallet } from 'libra-core';

// please don't use this mnemonic outside of this sample code
const wallet = new LibraWallet({
mnemonic: 'upgrade salt toy stable drop paddle'
});

const account = wallet.newAccount();

// you can see your address by:
console.log(account.getAddress().toHex());
```

### 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

```javascript
import { LibraClient, LiberaNetwork } from 'libra-core';

async function main() {
const client = new LibraClient({ network: LiberaNetwork.Testnet });

const account = wallet.newAccount();

// mint 2 libracoins to users accounts
await client.mintWithFaucetService(account.getAddress(), 20e6)
}

await main();

```

### Checking an address balance

```javascript
async function main() {
const client = new LibraClient({ network: LiberaNetwork.Testnet });

const accountAddress = '854563c50d20788fb6c11fac1010b553d722edb0c02f87c2edbdd3923726d13f';
const accountState = await client.getAccountState(accountsAddress);

// log account balance
console.log(accountState.balance.toString())

// Account state has other information that you could be interested in such as `sequenceNumber`.
}

await main();
```

### Transferring Libra Coins

You will eventually be able to transfer libra coins from your account to another account using `client.transferCoins()` function, but it is still a work in progress.
You are welcome to help contribute to making this work.

### Executing Transactions with Custom Program
You will eventually be able to transfer libra coins from your account to another account using `client.execute()` function, but it is also still a work in progress.
You are welcome to help contribute to making this work as well.

## Contribution
Feel free to contribute by opening issues or PR's to this repository
24 changes: 12 additions & 12 deletions lib/Transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ interface LibraGasConstraint {
}

export class LibraTransaction {

public static createTransfer(receipientAddress: string, numAccount: BigNumber): LibraTransaction {
throw new Error('Method not implemented. Still working on compiling and encoding programs');
}
public program: LibraProgram;
public gasContraint: LibraGasConstraint;
public expirationTime: BigNumber;
Expand All @@ -26,28 +30,24 @@ export class LibraTransaction {

/**
* Create a new Transaction
*
* @param program
* @param gasConstraint
* @param expirationTime
* @param sendersAddress
* @param sequenceNumber
*
* @param program
* @param gasConstraint
* @param expirationTime
* @param sendersAddress
* @param sequenceNumber
*/
constructor(
program: LibraProgram,
gasConstraint: LibraGasConstraint,
expirationTime: string | BigNumber,
sendersAddress: Uint8Array,
sequenceNumber: string | BigNumber
sequenceNumber: string | BigNumber,
) {
this.program = program;
this.gasContraint = gasConstraint;
this.expirationTime = new BigNumber(expirationTime);
this.sendersAddress = new AccountAddress(sendersAddress);
this.sequenceNumber = new BigNumber(sequenceNumber);
}

static createTransfer(receipientAddress: string, numAccount: BigNumber): LibraTransaction {
throw new Error('Method not implemented. Still working on compiling and encoding programs');
}
}
}
45 changes: 22 additions & 23 deletions lib/__generated__/access_path_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 47 additions & 51 deletions lib/__generated__/account_state_blob_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5b6a57e

Please sign in to comment.