parent
a80088483b
commit
507db86522
@ -72,11 +72,14 @@ interface Signer extends SignerInterface {
|
||||
}
|
||||
```
|
||||
|
||||
The app can use all or any of these, depending on needs. To instantiate the `@polkadot/api` with the provider (app does not have it's own) and the signer (allowing the extension to sign messages) can be done via -
|
||||
The app can use all or any of these, depending on needs. To instantiate the `@polkadot/api` signer (allowing the extension to sign messages) can be done via (assuming a known, single extension) -
|
||||
|
||||
```js
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
|
||||
const { signer } = window.injectedWeb3;
|
||||
const api = await Api.create({ signer });
|
||||
const pjsx = await window.injectedWeb3['polkadot-js'].enable('my dapp');
|
||||
const accounts = await pjsx.accounts.get();
|
||||
const api = await Api.create({ signer: pjsx.signer });
|
||||
```
|
||||
|
||||
Generally, you would probably want to have access to all extensions available and have a slighly higher-level interface to work with. For these cases, [extension-dapp](packages/extension-dapp/) provides a cleaner interface around the injected object, making it simpler to work with from a dapp perspective.
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
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)` - to be called before anything else, retrieves the list of all injected extensions/providers
|
||||
- `web3Accounts()` - returns alist of all the injected accounts, accross all extensions (source in meta)
|
||||
- `web3Accounts()` - returns a list of all the injected accounts, accross all extensions (source in meta)
|
||||
- `web3FromAddress(address: string)` - Retrieves a provider for a specific address
|
||||
- `web3FromSource(name: string)` - Retriebes a provider identified by the name
|
||||
- `isWeb3Injected` - boolean to indicate if `injectedWeb3` was found on the page
|
||||
@ -19,10 +19,12 @@ import { web3Accounts, web3Enable, web3FromAddress } from '@polkadot/extension-d
|
||||
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
|
||||
api.setSigner(injector.signer);
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user