Skip to content

Commit 86ba485

Browse files
committed
format snippets
1 parent 5b93c42 commit 86ba485

11 files changed

+46
-36
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
const metadata = await client.call.metadata.metadataAtVersion(15);
2-
console.log('Metadata V15', metadata)
2+
console.log('Metadata V15', metadata);

.snippets/code/develop/toolkit/api-libraries/dedot/client-initialization-via-smoldot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import type { PolkadotApi } from '@dedot/chaintypes';
33
import * as smoldot from 'smoldot';
44

55
// import `polkadot` chain spec to connect to Polkadot
6-
import { polkadot } from '@substrate/connect-known-chains'
6+
import { polkadot } from '@substrate/connect-known-chains';
77

88
// Start smoldot instance & initialize a chain
99
const client = smoldot.start();
1010
const chain = await client.addChain({ chainSpec: polkadot });
1111

1212
// Initialize providers & clients
1313
const provider = new SmoldotProvider(chain);
14-
const client = await DedotClient.new<PolkadotApi>(provider);
14+
const client = await DedotClient.new<PolkadotApi>(provider);

.snippets/code/develop/toolkit/api-libraries/dedot/client-initialization-via-ws.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import type { PolkadotApi } from '@dedot/chaintypes';
33

44
// Initialize providers & clients
55
const provider = new WsProvider('wss://rpc.polkadot.io');
6-
const client = await DedotClient.new<PolkadotApi>(provider);
6+
const client = await DedotClient.new<PolkadotApi>(provider);

.snippets/code/develop/toolkit/api-libraries/dedot/legacy-client-initialization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import { LegacyClient, WsProvider } from 'dedot';
22
import type { PolkadotApi } from '@dedot/chaintypes';
33

44
const provider = new WsProvider('wss://rpc.polkadot.io');
5-
const client = await LegacyClient.new<PolkadotApi>(provider);
5+
const client = await LegacyClient.new<PolkadotApi>(provider);
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { DedotClient, WsProvider } from 'dedot';
22
import type { PolkadotApi, KusamaApi } from '@dedot/chaintypes';
33

4-
const polkadotClient = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io'));
5-
const kusamaClient = await DedotClient.new<KusamaApi>(new WsProvider('wss://kusama-rpc.polkadot.io'));
6-
const genericClient = await DedotClient.new(new WsProvider('ws://localhost:9944'));
4+
const polkadotClient = await DedotClient.new<PolkadotApi>(
5+
new WsProvider('wss://rpc.polkadot.io')
6+
);
7+
const kusamaClient = await DedotClient.new<KusamaApi>(
8+
new WsProvider('wss://kusama-rpc.polkadot.io')
9+
);
10+
const genericClient = await DedotClient.new(
11+
new WsProvider('ws://localhost:9944')
12+
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
const ss58Prefix = client.consts.system.ss58Prefix;
2-
console.log('Polkadot ss58Prefix:', ss58Prefix);
2+
console.log('Polkadot ss58Prefix:', ss58Prefix);

.snippets/code/develop/toolkit/api-libraries/dedot/sign-and-send-tx-with-extension-signer.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ const injected = await window.injectedWeb3['polkadot-js'].enable('My dApp');
22
const account = (await injected.accounts.get())[0];
33
const signer = injected.signer;
44
const unsub = await client.tx.balances
5-
.transferKeepAlive(<destAddress>, 2_000_000_000_000n)
6-
.signAndSend(account.address, { signer }, async ({ status }) => {
7-
console.log('Transaction status', status.type);
8-
if (status.type === 'BestChainBlockIncluded') {
9-
console.log(`Transaction is included in best block`);
10-
}
11-
if (status.type === 'Finalized') {
12-
console.log(`Transaction completed at block hash ${status.value.blockHash}`);
13-
await unsub();
14-
}
15-
});
5+
.transferKeepAlive('INSERT_DEST_ADDRESS', 2_000_000_000_000n)
6+
.signAndSend(account.address, { signer }, async ({ status }) => {
7+
console.log('Transaction status', status.type);
8+
if (status.type === 'BestChainBlockIncluded') {
9+
console.log(`Transaction is included in best block`);
10+
}
11+
if (status.type === 'Finalized') {
12+
console.log(
13+
`Transaction completed at block hash ${status.value.blockHash}`
14+
);
15+
await unsub();
16+
}
17+
});

.snippets/code/develop/toolkit/api-libraries/dedot/sign-and-send-tx-with-keyring.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ const keyring = new Keyring({ type: 'sr25519' });
66
const alice = keyring.addFromUri('//Alice');
77
// Send transaction
88
const unsub = await client.tx.balances
9-
.transferKeepAlive(<destAddress>, 2_000_000_000_000n)
10-
.signAndSend(alice, async ({ status }) => {
11-
console.log('Transaction status', status.type);
12-
if (status.type === 'BestChainBlockIncluded') {
13-
console.log(`Transaction is included in best block`);
14-
}
15-
if (status.type === 'Finalized') {
16-
console.log(`Transaction completed at block hash ${status.value.blockHash}`);
17-
await unsub();
18-
}
19-
});
9+
.transferKeepAlive('INSERT_DEST_ADDRESS', 2_000_000_000_000n)
10+
.signAndSend(alice, async ({ status }) => {
11+
console.log('Transaction status', status.type);
12+
if (status.type === 'BestChainBlockIncluded') {
13+
console.log(`Transaction is included in best block`);
14+
}
15+
if (status.type === 'Finalized') {
16+
console.log(
17+
`Transaction completed at block hash ${status.value.blockHash}`
18+
);
19+
await unsub();
20+
}
21+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const balance = await client.query.system.account(<address>);
2-
console.log('Balance:', balance.data.free);
1+
const balance = await client.query.system.account('INSERT_ADDRESS');
2+
console.log('Balance:', balance.data.free);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const unsub = await client.query.system.number((blockNumber) => {
22
console.log(`Current block number: ${blockNumber}`);
3-
});
3+
});

0 commit comments

Comments
 (0)