5.7.1 Java  Script
5.7.1.1 Types
5.7.1.2 loader.mjs
5.7.1.3 Accounts
5.7.1.4 Contracts
5.7.1.5 Network Utilities
5.7.1.6 Provider Selection
5.7.1.7 Utilities
5.7.1.8 ask.mjs
5.7.1.3 Accounts
On this page:
get  Default  Account
new  Account  From  Secret
new  Account  From  Mnemonic
new  Test  Account
create  Account
fund  From  Faucet
connect  Account
network  Account
get  Address
set  Debug  Label
token  Accept
token  Metadata
balance  Of
transfer
5.7.1.3.1 Ethereum-specific
set  Gas  Limit
5.7.1.3 Accounts

These functions create and interact with account representations.

getDefaultAccount() => Promise<acc> 

Returns a Promise for a Reach account abstraction for a "default" account on the consensus network. The meaning of "default account" varies between contexts. When running in the browser, the default account will be connected to a wallet such as MetaMask or AlgoSigner. When running in node.js while connected to one of reach’s standard devnets, the default account will be connected to a faucet on the devnet. This promise will be rejected with an exception if no sensible default account can be accessed for the current context.

newAccountFromSecret(secret: string) => Promise<acc> 

Returns a Promise for a Reach account abstraction for an account on the consensus network specified by the given secret. The details of the secret encoding are specified uniquely to the consensus network.

newAccountFromMnemonic(phrase: string) => Promise<acc> 

Returns a Promise for a Reach account abstraction for an account on the consensus network specified by the given mnemonic phrase. The details of the mnemonic phrase encoding are specified uniquely to the consensus network.

newTestAccount(balance) => Promise<acc> 

Returns a Promise for a Reach account abstraction for a new account on the consensus network with a given balance of network tokens. This can only be used in private testing scenarios, as it uses a private faucet to issue network tokens.

bigNumberify is transparently applied to the balance argument.

createAccount() => Promise<acc> 

Returns a Promise for a Reach account abstraction for a new account on the consensus network. The account will have an empty balance of network tokens.

fundFromFaucet(account, balance) => Promise<void>

Adds the given balance of network tokens to a Reach account abstraction. This can only be used in private testing scenarios, as it uses a private faucet to issue network tokens.

bigNumberify is transparently applied to the balance argument.

connectAccount(networkAccount) => Promise<acc> 

Returns a Promise for a Reach account abstraction for an existing account for the consensus network based on the connector-specific account specification provided by the networkAccount argument.

// network => networkAccount type
ETH        => ethers.Wallet
ALGO       => {addr: string, sk: UInt8Array(64)}

acc.networkAccount => networkAccount 

Returns the connector-specific account specification of a Reach account abstraction.

acc.getAddress() => string

Returns the account’s address as a string. The format of this string varies across connectors.

acc.setDebugLabel(string) => acc 

An account may set a distinguishing label to use in debug logs. If no label is provided, then the first four digits of the account address will be used.

acc.tokenAccept(token) => Promise<void>

Returns a Promise that completes when the Reach account abstraction is ready to accept non-network tokens specified by the token. This does nothing on some consensus networks, but should always be used to ensure your frontend is blockchain agnostic.

acc.tokenMetadata(token) => Promise<object>

Returns a Promise of the metadata for a non-network tokens specified by the token.

balanceOf(acc, token?) => Promise<amount> 

Returns a Promise for the balance of network tokens (or non-network tokens if token is provided) held by the account given by a Reach account abstraction provided by the acc argument.

transfer(from:acc, to:acc, amount, token?) => Promise<void> 

Performs a transfer of amount from from to to, which are accounts, such as those returned by connectAccount. If token is not provided, then the transfer is of network tokens; otherwise, it is of the designated non-network token. The returned Promise will only be resolved after the transfer completes.

bigNumberify is transparently applied to the amount argument.

5.7.1.3.1 Ethereum-specific

When connected to an EVM-based consensus network, the standard library provides additional functionality.

acc.setGasLimit(n) => void 

Modifies the gas limit for each transaction originating from the given account for the rest of the program. n must be a value that bigNumberify will accept.

On EVM-based consensus networks, the Reach standard library will automatically estimate the required gas necessary to execute transactions, i.e. make publications. However, sometimes this estimation process is inaccurate, especially when Reach programs interact with remote objects. In those cases, it is sometimes useful to specify a particular gas limit. It is common on Ethereum to use gas limits like 5000000 in testing. If you do this, you should inform your clients that they should pay attention to the gas stipend issued.