Move the extension-dapp to docs (#509)
Co-authored-by: Github Actions <action@github.com>
This commit is contained in:
@@ -68,8 +68,9 @@ The repo is split into a number of packages -
|
||||
|
||||
## Dapp developers
|
||||
|
||||
The actual in-depth technical breakdown is given in the next section for any dapp developer wishing to work with the raw objects injected into the window. However, convenience wrappers are provided that allows for any dapp to use this extension (or any other extension that conforms to the interface) without
|
||||
having to manage any additional info.
|
||||
The actual in-depth technical breakdown is given in the next section for any dapp developer wishing to work with the raw objects injected into the window. However, convenience wrappers are provided that allows for any dapp to use this extension (or any other extension that conforms to the interface) without having to manage any additional info.
|
||||
|
||||
The documentation for Dapp development is available [in the polkadot-js doc](https://polkadot.js.org/docs/extension).
|
||||
|
||||
This approach is used to support multiple external signers in for instance [apps](https://github.com/polkadot-js/apps/). You can read more about the convenience wrapper [@polkadot/extension-dapp](packages/extension-dapp/) along with usage samples.
|
||||
|
||||
|
||||
@@ -1,40 +1,3 @@
|
||||
# @polkadot/extension-dapp
|
||||
|
||||
A basic extractor that manipulates the `window.injectedWeb3` to retrieve all the providers added to the page. It has a number of utilities -
|
||||
|
||||
- `web3Enable(dappName: string): Promise<InjectedExtension[]>` - to be called before anything else, retrieves the list of all injected extensions/providers
|
||||
- `web3Accounts(): Promise<InjectedAccountWithMeta[]>` - returns a list of all the injected accounts, accross all extensions (source in meta)
|
||||
- `web3AccountsSubscribe(cb: (accounts: InjectedAccountWithMeta[]) => any): Promise<Unsubcall>` - subscribes to the accounts accross all extensions, returning a full list as changes are made
|
||||
- `web3FromAddress(address: string): Promise<InjectedExtension>` - Retrieves a provider for a specific address
|
||||
- `web3FromSource(name: string): Promise<InjectedExtension>` - Retrieves a provider identified by the name
|
||||
- `isWeb3Injected: boolean` - boolean to indicate if `injectedWeb3` was found on the page
|
||||
- `web3EnablePromise: Promise<InjectedExtension[]> | null` - `null` or the promise as a result of the last call to `web3Enable`
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { web3Accounts, web3Enable, web3FromAddress, web3ListRpcProviders, web3UseRpcProvider } from '@polkadot/extension-dapp';
|
||||
|
||||
// returns an array of all the injected sources
|
||||
// (this needs to be called first, before other requests)
|
||||
const allInjected = await web3Enable('my cool dapp');
|
||||
|
||||
// returns an array of { address, meta: { name, source } }
|
||||
// meta.source contains the name of the extension that provides this account
|
||||
const allAccounts = await web3Accounts();
|
||||
|
||||
// finds an injector for an address
|
||||
const injector = await web3FromAddress('5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE');
|
||||
|
||||
// sets the signer for the address on the @polkadot/api. The alternative approach it to pass the signer through
|
||||
// options to signAndSend in the next step where we are sending (and skip this injection here), e.g
|
||||
// `.signAndSend(<address>, { signer: injector.signer }, (status) => { ... })`
|
||||
api.setSigner(injector.signer);
|
||||
|
||||
// sign and send our transaction - notice here that the address of the account (as retrieved injected)
|
||||
// is passed through as the param to the `signAndSend`, the API then calls the extension to present
|
||||
// to the user and get it signed. Once complete, the api sends the tx + signature via the normal process
|
||||
api.tx.balances
|
||||
.transfer('5C5555yEXUcmEJ5kkcCMvdZjUo7NGJiQJMS7vZXEeoMhj3VQ', 123456)
|
||||
.signAndSend('5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE', (status) => { ... });
|
||||
```
|
||||
Documentation available [in the polkadot-js doc](https://polkadot.js.org/docs/extension).
|
||||
|
||||
Reference in New Issue
Block a user