Skip to content

Commit d57955e

Browse files
committed
prettier on code files
1 parent 97b1d62 commit d57955e

File tree

4 files changed

+99
-76
lines changed

4 files changed

+99
-76
lines changed
Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { DedotClient, WsProvider } from "dedot";
2-
import type { PolkadotAssetHubApi } from "@dedot/chaintypes";
3-
import { cryptoWaitReady } from "@polkadot/util-crypto";
4-
import { Keyring } from "@polkadot/keyring";
1+
import { DedotClient, WsProvider } from 'dedot';
2+
import type { PolkadotAssetHubApi } from '@dedot/chaintypes';
3+
import { cryptoWaitReady } from '@polkadot/util-crypto';
4+
import { Keyring } from '@polkadot/keyring';
55

6-
const POLKADOT_TESTNET_RPC = "INSERT_RPC_URL";
7-
const SENDER_MNEMONIC = "INSERT_MNEMONIC";
8-
const DEST_ADDRESS = "INSERT_DEST_ADDRESS";
6+
const POLKADOT_TESTNET_RPC = 'INSERT_RPC_URL';
7+
const SENDER_MNEMONIC = 'INSERT_MNEMONIC';
8+
const DEST_ADDRESS = 'INSERT_DEST_ADDRESS';
99
const AMOUNT = 1_000_000_000n; // 1 PAS (adjust decimals as needed)
1010

1111
async function main() {
@@ -16,10 +16,10 @@ async function main() {
1616
const provider = new WsProvider(POLKADOT_TESTNET_RPC);
1717
const client = await DedotClient.new<PolkadotAssetHubApi>(provider);
1818

19-
console.log("Connected to Polkadot Testnet");
19+
console.log('Connected to Polkadot Testnet');
2020

2121
// Set up keyring and get sender account
22-
const keyring = new Keyring({ type: "sr25519" });
22+
const keyring = new Keyring({ type: 'sr25519' });
2323
const sender = keyring.addFromMnemonic(SENDER_MNEMONIC);
2424
const senderAddress = sender.address;
2525

@@ -32,39 +32,55 @@ async function main() {
3232
console.log(`Sender balance: ${accountInfo.data.free}`);
3333

3434
// Sign and submit the transfer transaction
35-
console.log("\nSigning and submitting transaction...");
36-
35+
console.log('\nSigning and submitting transaction...');
36+
3737
// Wait for transaction to complete using a Promise
3838
await new Promise<void>((resolve, reject) => {
3939
client.tx.balances
4040
.transferKeepAlive(DEST_ADDRESS, AMOUNT)
4141
.signAndSend(sender, async ({ status, txHash, dispatchError }) => {
4242
console.log(`Transaction status: ${status.type}`);
43-
43+
4444
// Log transaction hash immediately
4545
if (txHash) {
46-
console.log(`Transaction hash: ${typeof txHash === 'string' ? txHash : txHash.toHex()}`);
46+
console.log(
47+
`Transaction hash: ${
48+
typeof txHash === 'string' ? txHash : txHash.toHex()
49+
}`
50+
);
4751
}
48-
49-
if (status.type === "BestChainBlockIncluded") {
50-
console.log(`Transaction included in block: ${status.value.blockHash}`);
52+
53+
if (status.type === 'BestChainBlockIncluded') {
54+
console.log(
55+
`Transaction included in block: ${status.value.blockHash}`
56+
);
5157
}
52-
53-
if (status.type === "Finalized") {
54-
console.log(`Transaction finalized in block: ${status.value.blockHash}`);
55-
58+
59+
if (status.type === 'Finalized') {
60+
console.log(
61+
`Transaction finalized in block: ${status.value.blockHash}`
62+
);
63+
5664
// Check for dispatch errors
5765
if (dispatchError) {
5866
if (dispatchError.type === 'Module') {
59-
const decoded = client.registry.findMetaError(dispatchError.value);
60-
console.error(`Dispatch error: ${decoded.section}.${decoded.name}: ${decoded.docs}`);
61-
reject(new Error(`Transaction failed: ${decoded.section}.${decoded.name}`));
67+
const decoded = client.registry.findMetaError(
68+
dispatchError.value
69+
);
70+
console.error(
71+
`Dispatch error: ${decoded.section}.${decoded.name}: ${decoded.docs}`
72+
);
73+
reject(
74+
new Error(
75+
`Transaction failed: ${decoded.section}.${decoded.name}`
76+
)
77+
);
6278
} else {
6379
console.error(`Dispatch error: ${dispatchError.type}`);
6480
reject(new Error(`Transaction failed: ${dispatchError.type}`));
6581
}
6682
} else {
67-
console.log("Transaction successful!");
83+
console.log('Transaction successful!');
6884
resolve();
6985
}
7086
}
@@ -74,7 +90,7 @@ async function main() {
7490

7591
// Disconnect the client after transaction completes
7692
await client.disconnect();
77-
console.log("Disconnected from Polkadot Hub");
93+
console.log('Disconnected from Polkadot Hub');
7894
}
7995

80-
main().catch(console.error);
96+
main().catch(console.error);
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { createClient } from "polkadot-api";
2-
import { getWsProvider } from "polkadot-api/ws-provider";
3-
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
4-
import { polkadotTestNet } from "@polkadot-api/descriptors";
5-
import { cryptoWaitReady } from "@polkadot/util-crypto";
6-
import { Keyring } from "@polkadot/keyring";
7-
import { getPolkadotSigner } from "polkadot-api/signer";
8-
9-
const POLKADOT_TESTNET_RPC = "INSERT_RPC_URL";
10-
const SENDER_MNEMONIC = "INSERT_MNEMONIC";
11-
const DEST_ADDRESS = "INSERT_DEST_ADDRESS";
1+
import { createClient } from 'polkadot-api';
2+
import { getWsProvider } from 'polkadot-api/ws-provider';
3+
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat';
4+
import { polkadotTestNet } from '@polkadot-api/descriptors';
5+
import { cryptoWaitReady } from '@polkadot/util-crypto';
6+
import { Keyring } from '@polkadot/keyring';
7+
import { getPolkadotSigner } from 'polkadot-api/signer';
8+
9+
const POLKADOT_TESTNET_RPC = 'INSERT_RPC_URL';
10+
const SENDER_MNEMONIC = 'INSERT_MNEMONIC';
11+
const DEST_ADDRESS = 'INSERT_DEST_ADDRESS';
1212
const AMOUNT = 1_000_000_000n; // 1 PAS (adjust decimals as needed)
1313

1414
async function main() {
1515
try {
1616
await cryptoWaitReady();
1717

18-
const keyring = new Keyring({ type: "sr25519" });
18+
const keyring = new Keyring({ type: 'sr25519' });
1919
const sender = keyring.addFromMnemonic(SENDER_MNEMONIC);
20-
20+
2121
console.log(`Sender address: ${sender.address}`);
2222

2323
// Create the client connection
@@ -27,32 +27,31 @@ async function main() {
2727

2828
// Get the typed API
2929
const api = client.getTypedApi(polkadotTestNet);
30-
console.log("Connected to Polkadot Testnet");
30+
console.log('Connected to Polkadot Testnet');
3131

3232
// Create signer using getPolkadotSigner
3333
const signer = getPolkadotSigner(
3434
sender.publicKey,
35-
"Sr25519",
35+
'Sr25519',
3636
async (input) => sender.sign(input)
3737
);
3838

3939
// Construct and submit the transfer transaction
4040
const tx = api.tx.Balances.transfer_keep_alive({
41-
dest: { type: "Id", value: DEST_ADDRESS },
41+
dest: { type: 'Id', value: DEST_ADDRESS },
4242
value: AMOUNT,
4343
});
4444

45-
console.log("\nSigning and submitting transaction...");
46-
const { txHash } = (await tx.signAndSubmit(signer));
45+
console.log('\nSigning and submitting transaction...');
46+
const { txHash } = await tx.signAndSubmit(signer);
4747
console.log(`Transaction submitted with hash: ${txHash}`);
48-
48+
4949
await client.destroy();
50-
console.log("Disconnected");
51-
50+
console.log('Disconnected');
5251
} catch (error) {
53-
console.error("Error:", error);
52+
console.error('Error:', error);
5453
process.exit(1);
5554
}
5655
}
5756

58-
main();
57+
main();
Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,62 @@
1-
import { ApiPromise, WsProvider } from "@polkadot/api";
2-
import { Keyring } from "@polkadot/keyring";
3-
import { cryptoWaitReady } from "@polkadot/util-crypto";
1+
import { ApiPromise, WsProvider } from '@polkadot/api';
2+
import { Keyring } from '@polkadot/keyring';
3+
import { cryptoWaitReady } from '@polkadot/util-crypto';
44

5-
const POLKADOT_TESTNET_RPC = "INSERT_RPC_URL";
6-
const SENDER_MNEMONIC = "INSERT_MNEMONIC";
7-
const DEST_ADDRESS = "INSERT_DEST_ADDRESS";
5+
const POLKADOT_TESTNET_RPC = 'INSERT_RPC_URL';
6+
const SENDER_MNEMONIC = 'INSERT_MNEMONIC';
7+
const DEST_ADDRESS = 'INSERT_DEST_ADDRESS';
88
const AMOUNT = 1_000_000_000n; // 1 PAS (adjust decimals as needed)
99

1010
async function main() {
1111
// Wait for crypto to be ready
1212
await cryptoWaitReady();
13-
13+
1414
// Create a WebSocket provider
1515
const wsProvider = new WsProvider(POLKADOT_TESTNET_RPC);
16-
16+
1717
// Initialize the API
1818
const api = await ApiPromise.create({ provider: wsProvider });
19-
console.log("Connected to Polkadot Testnet");
20-
19+
console.log('Connected to Polkadot Testnet');
20+
2121
// Set up keyring and get sender account
22-
const keyring = new Keyring({ type: "sr25519" });
22+
const keyring = new Keyring({ type: 'sr25519' });
2323
const sender = keyring.addFromMnemonic(SENDER_MNEMONIC);
2424
const senderAddress = sender.address;
25-
25+
2626
console.log(`Sender address: ${senderAddress}`);
2727
console.log(`Recipient address: ${DEST_ADDRESS}`);
2828
console.log(`Amount: ${AMOUNT} (${Number(AMOUNT) / 1_000_000_000} PAS)\n`);
29-
29+
3030
// Get sender's account info to check balance
3131
const accountInfo = await api.query.system.account(senderAddress);
32-
console.log(`Sender balance: ${accountInfo.data.free.toString()} (${Number(accountInfo.data.free.toBigInt()) / 1_000_000_000} PAS)`);
33-
32+
console.log(
33+
`Sender balance: ${accountInfo.data.free.toString()} (${
34+
Number(accountInfo.data.free.toBigInt()) / 1_000_000_000
35+
} PAS)`
36+
);
37+
3438
// Construct and sign the transfer transaction
35-
console.log("\nSigning and submitting transaction...");
36-
39+
console.log('\nSigning and submitting transaction...');
40+
3741
await new Promise((resolve, reject) => {
3842
api.tx.balances
3943
.transferKeepAlive(DEST_ADDRESS, AMOUNT)
4044
.signAndSend(sender, ({ status, txHash, dispatchError }) => {
4145
if (status.isInBlock) {
42-
console.log(`Transaction included in block: ${status.asInBlock.toHex()}`);
46+
console.log(
47+
`Transaction included in block: ${status.asInBlock.toHex()}`
48+
);
4349
} else if (status.isFinalized) {
44-
console.log(`Transaction finalized in block: ${status.asFinalized.toHex()}`);
50+
console.log(
51+
`Transaction finalized in block: ${status.asFinalized.toHex()}`
52+
);
4553
console.log(`Transaction hash: ${txHash.toHex()}`);
46-
54+
4755
if (dispatchError) {
4856
if (dispatchError.isModule) {
49-
const decoded = api.registry.findMetaError(dispatchError.asModule);
57+
const decoded = api.registry.findMetaError(
58+
dispatchError.asModule
59+
);
5060
const { docs, name, section } = decoded;
5161
reject(new Error(`${section}.${name}: ${docs.join(' ')}`));
5262
} else {
@@ -60,9 +70,9 @@ async function main() {
6070
})
6171
.catch(reject);
6272
});
63-
73+
6474
// Disconnect from the node
6575
await api.disconnect();
6676
}
6777

68-
main().catch(console.error);
78+
main().catch(console.error);

.snippets/code/chain-interactions/send-transactions/with-sdks/psi/send_transfer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ def main():
3838
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
3939

4040
# Submit and wait for inclusion
41-
receipt = substrate.submit_extrinsic(
42-
extrinsic, wait_for_inclusion=True
43-
)
41+
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
4442

4543
if receipt.is_success:
4644
print("\nTransaction successful!")
@@ -54,4 +52,4 @@ def main():
5452

5553

5654
if __name__ == "__main__":
57-
main()
55+
main()

0 commit comments

Comments
 (0)