keyring docs with more examples and FAQ (#68)

This commit is contained in:
YJ
2019-02-07 12:18:42 +08:00
committed by GitHub
parent c0c882e2f5
commit fca46e5f04
+47 -1
View File
@@ -3,8 +3,10 @@
A wrapper extending the base @polkadot/keyring interface for usage in the browser:
Key management of user accounts including generation and retrieval of keyring pairs from a variety of input combinations.
## Usage Example
## Usage Examples
All module methods are exposed through a single default export.
### Regular
```
import keyring from @polkadot/ui-keyring
@@ -21,8 +23,52 @@ render () {
// save account from pair
keyring.saveAccount(pair, password);
// save address without unlocking it
keyring.saveAddress(address, { ...meta });
}
```
### Observables
```
import React from 'react';
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
class MyReactComponent extends React.Component {
componentDidMount () {
accountObservable.subscribe((observedAccounts) => {
this.setState({
accounts: observedAccounts
});
})
}
render () {
const { accounts } = this.state;
return (
<h1>All Accounts</h1>
{
Object.keys(accounts).map(address => {
return <p> {address} </p>;
})
}
)
}
}
```
## FAQ
- Difference between Keyring Accounts and Addresses?
- From the perspective of the keyring, it saves a particular user's unlocked identities as an account, a la keyring.saveAccount(pair, password). So with these accounts you are able to send and sign transactions.
- To save addresses without unlocking them (i.e. because a user might want to have easy access to addresses they frequently transact with), use keyring.saveAddress(address, meta)
- What are 'external' accounts, i.e. when to set the `isExternal` meta key to true?
- An external account is one where the keys are not managed by keyring, e.g. in Parity Signer or Ledger Nano.
- SS58 Encode / Decode?
- SS58 is a simple address format designed for Substrate based chains. You can read about its specification in more detail in the [Parity Wiki](https://wiki.parity.io/External-Address-Format-(SS58)).
**If you have any unanswered/undocumented questions, please raise an issue [here](https://github.com/polkadot-js/ui/issues).**
## Users
Keyring is core to many polkadot/substrate apps.