Browse Source

Update managing-accounts.md

feat/new-clarity-onboarding
Dominic Wong 4 years ago
committed by Alexander Graebe
parent
commit
1d652baaf3
  1. 18
      src/pages/understand-stacks/managing-accounts.md

18
src/pages/understand-stacks/managing-accounts.md

@ -75,15 +75,15 @@ const stacksAddress = getAddressFromPrivateKey(
TransactionVersion.Testnet // remove for Mainnet addresses TransactionVersion.Testnet // remove for Mainnet addresses
); );
(async () => { async function getAccountInfo() {
const accounts = new AccountsApi(apiConfig); const accounts = new AccountsApi(apiConfig);
const accountInfo = await accounts.getAccountInfo({ const accountInfo = await accounts.getAccountInfo({
principal: stacksAddress principal: stacksAddress
}); });
console.log(accountInfo); return accountInfo;
})(); }
``` ```
-> Note: A "principal" is any entity that can have a token balance. Find more details in the [Principals guide](/write-smart-contracts/principals). -> Note: A "principal" is any entity that can have a token balance. Find more details in the [Principals guide](/write-smart-contracts/principals).
@ -106,10 +106,14 @@ The `balance` property represents the Stacks token balance, as hex-encoded strin
Proofs, provided as hex-encoded strings, can be removed from the responses by setting the `proof` parameter: Proofs, provided as hex-encoded strings, can be removed from the responses by setting the `proof` parameter:
```js ```js
async function getAccountInfo() {
const accountInfo = await accounts.getAccountInfo({ const accountInfo = await accounts.getAccountInfo({
principal: stacksAddress, principal: stacksAddress,
proof: 0, proof: 0,
}); });
return accountInfo;
};
``` ```
## Step 4: Reviewing account history ## Step 4: Reviewing account history
@ -117,11 +121,13 @@ const accountInfo = await accounts.getAccountInfo({
The following step make requires associated accounts transactions. For simplicity, let's run the faucet for the new account: The following step make requires associated accounts transactions. For simplicity, let's run the faucet for the new account:
```js ```js
async function runFaucetStx() {
const faucets = new FaucetsApi(apiConfig); const faucets = new FaucetsApi(apiConfig);
const faucetTx = await faucets.runFaucetStx({ const faucetTx = await faucets.runFaucetStx({
address: stacksAddress, address: stacksAddress,
}); });
};
console.log(faucetTx); console.log(faucetTx);
``` ```
@ -141,11 +147,13 @@ The API will respond with a new transaction ID and confirmation that the faucet
Assuming the faucet transaction was successfully processed, you can review the account history. We are expecting at least one transactions to show up in the account history. Assuming the faucet transaction was successfully processed, you can review the account history. We are expecting at least one transactions to show up in the account history.
```js ```js
async function getAccountTransactions() {
const history = await accounts.getAccountTransactions({ const history = await accounts.getAccountTransactions({
principal: stacksAddress, principal: stacksAddress,
}); });
console.log(history); console.log(history);
}
``` ```
The API will respond with a paginatable list of transactions associated with the account: The API will respond with a paginatable list of transactions associated with the account:
@ -198,11 +206,13 @@ To make API responses more compact, lists returned by the API are paginated. For
In order to paginate throughout the full result set, we can use the `limit` and `offset` request properties. Here is an example where we request transactions 50-100 for an account: In order to paginate throughout the full result set, we can use the `limit` and `offset` request properties. Here is an example where we request transactions 50-100 for an account:
```js ```js
async function getAccountTransactions() {
const history = await accounts.getAccountTransactions({ const history = await accounts.getAccountTransactions({
principal: stacksAddress, principal: stacksAddress,
limit: 50, limit: 50,
offset: 50, offset: 50,
}); });
}
``` ```
## Step 5: Getting account balances ## Step 5: Getting account balances
@ -210,11 +220,13 @@ const history = await accounts.getAccountTransactions({
As mentioned above, any Stacks address can have a variety of tokens and associated balances. In order to get balances for all Stacks, fungible, and non-fungible tokens, we can use the `getAccountBalance` method: As mentioned above, any Stacks address can have a variety of tokens and associated balances. In order to get balances for all Stacks, fungible, and non-fungible tokens, we can use the `getAccountBalance` method:
```js ```js
async function getAccountBalance() {
const balances = await accounts.getAccountBalance({ const balances = await accounts.getAccountBalance({
principal: stacksAddress, principal: stacksAddress,
}); });
console.log(balances); console.log(balances);
}
``` ```
The API will respond with the following breakdown of token balances: The API will respond with the following breakdown of token balances:

Loading…
Cancel
Save