Created
February 10, 2022 23:11
-
-
Save drbh/9c588858434985a1e9509e27a98e6c35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApiPromise, Keyring, WsProvider } from "@polkadot/api"; | |
async function main() { | |
const wsProvider = new WsProvider("wss://rpc.parallel.fi"); | |
const api = await ApiPromise.create({ provider: wsProvider }); | |
// no blockHash is specified, so we retrieve the latest | |
const signedBlock = await api.rpc.chain.getBlock(); | |
// the information for each of the contained extrinsics | |
signedBlock.block.extrinsics.forEach((ex, index) => { | |
// the extrinsics are decoded by the API, human-like view | |
console.log(`index: ${index}`); | |
console.log(ex.toHuman()); | |
}); | |
} | |
// run | |
main() | |
.catch(console.error) | |
.finally(() => process.exit()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApiPromise, Keyring, WsProvider } from "@polkadot/api"; | |
async function main() { | |
const wsProvider = new WsProvider("wss://rpc.parallel.fi"); | |
const api = await ApiPromise.create({ provider: wsProvider }); | |
const ADDR = 'p8FhJ2kCvAtetismfbfgLBeGwBknFuqT77L9nJXdLTvct35HD'; | |
// Retrieve the last timestamp | |
const now = await api.query.timestamp.now(); | |
// Retrieve the account balance & nonce via the system module | |
const result: any = await api.query.system.account(ADDR); | |
const nonce = result.nonce; | |
const free = result.data.free / 1e12; | |
console.log(`${now}: balance of ${free} and a nonce of ${nonce}`); | |
} | |
// run | |
main() | |
.catch(console.error) | |
.finally(() => process.exit()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApiPromise, Keyring, WsProvider } from "@polkadot/api"; | |
async function main() { | |
const wsProvider = new WsProvider("wss://rpc.parallel.fi"); | |
const api = await ApiPromise.create({ provider: wsProvider }); | |
// Retrieve the latest header | |
const lastHeader = await api.rpc.chain.getHeader(); | |
// fetch last block using the last block's hash | |
const block: any = await api.rpc.chain.getBlock(lastHeader.hash); | |
console.log(block) | |
} | |
// run | |
main() | |
.catch(console.error) | |
.finally(() => process.exit()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment