ghost-portal/packages/app-js/src/snippets/queries.ts
Stefanie Doll 061f346fd6
Sd 668 app console (#684)
* [app-js] fixed copyright

* [app-js] css fixes

* [app-js] Add api to window object

* Make CSS columns resizable (FF & Chrome)

* Window Interface export

* formatting

* Make columns responsive, added Dropdown

* Added code snippets

* Strip down output to functional component

* removed component state, removed onEdit, update on select

* Editor styling

* Added snippets and local storage

* output formatting

* Example dummies

* Cleanup & examples

* Added util & keyring @polkadot modules to window object

* Moved intro to component to make it translatable

* Added more RPC examples

* small fix

* WIP exaples

* Styles for resizer, fixed flex overflow misbehaviour

* remove code from snippets for options,

* Added labels to dropdown

* Examples

* More examples and removed deprecated examples

* Added labels to dropdown -> missing type decl.

* correst link to ui-keyring package

* Make tslint happy

* Pull api clone/disconnect into sd-668 (#686)

* JS playground & console (start something...)

* It runs...

* WIP

* Use codeflask

* Highlights

* Small updates, console v0.1 is ok to play with

* Bump

* Only shadow, no border (article)

* Allow API to be disposed of between runs

* Clone and disconnect API

* Move id generation (no need for constructor)

* Small updates

* Small type adjustments

* smaller fixes after code review

* updated yarn.lock

* move options calculation out of return

* Remove exposure of api to window object

* Expand JS console logging (#691)

* Expand JS console logging

* Log extrinsics directly

* switch to getDerivedStateFromProps()

* roll back ts versions

* react-i18next rollback to 9.0.2

* Lock  react-i18next to 9.0.2
2019-02-11 18:02:34 +01:00

30 lines
1.3 KiB
TypeScript

// Copyright 2017-2019 @polkadot/app-123code authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export default `// This example set shows how to make queries and retrieve info on query keys
const ALICE = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ';
// retrieve the balance, once-off at the latest block
const currBalance = await api.query.balances.freeBalance(ALICE);
console.log('Alice has a current balance of', currBalance);
// retrieve balance updates with an optional value callback
const balanceUnsub = await api.query.balances.freeBalance(ALICE, (balance) => {
console.log('Alice has an updated balance of', balance);
});
// retrieve the balance at a block hash in the past
const header = await api.rpc.chain.getHeader();
const prevHash = await api.rpc.chain.getBlockHash(header.blockNumber.subn(42));
const prevBalance = await api.query.balances.freeBalance.at(prevHash, ALICE);
console.log('Alice had a balance of', prevBalance, '(42 blocks ago)');
// useful in some situations - the value hash and storage entry size
const currHash = await api.query.balanace.freeBalance.hash(ALICE);
const currSize = await api.query.balanace.freeBalance.size(ALICE);
console.log('Alice balance entry has a value hash of', currHash, 'with a size of', currSize);`;