Is it possible to use this with non JSON endpoints?
Closed this issue · 4 comments
Swader commented
For example, I'd like to use this with @polkadot/api@beta, instead of the current setup of my store as below:
import { readable } from 'svelte/store';
const { ApiPromise, WsProvider } = require('@polkadot/api');
const wsProvider = new WsProvider('wss://kusama-rpc.polkadot.io/');
let api = ApiPromise.create({ provider: wsProvider });
export const getTotalIssuance = readable(null, async function start(set) {
set(await (await api).query.balances.totalIssuance());
return function stop() {};
});
export const getGenesisHash = readable(null, async function start(set) {
set((await api).genesisHash.toHex());
return function stop() {};
});
arlac77 commented
Maybe it is better to build your own store around the @polkadot/api
where You can feed the calls like query.balances.totalIssuance()
const { ApiPromise, WsProvider } = require('@polkadot/api');
export function polkadotStore( url, query) {
const wsProvider = new WsProvider(url);
const api = ApiPromise.create({ provider: wsProvider });
return readable(null, async function start(set) {
set(await query(await api));
return function stop() {};
});
const totalIssuanceStore = polkadotStore('wss://kusama-rpc.polkadot.io/', api => api.query.balances.totalIssuance());
Swader commented
Would this make sure the api connection is made once and only once across my app and all the components that need it?
arlac77 commented
no You have to build a singleton (Map lookup for url ?) for wsProvider / api
Swader commented
Okay, thanks. Closing this issue.