Skip to content

Commit 50e177a

Browse files
committed
refactored according to feedback
1 parent 5320898 commit 50e177a

File tree

14 files changed

+494
-511
lines changed

14 files changed

+494
-511
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { ApiPromise, WsProvider } = require('@polkadot/api');
2+
const provider = new WsProvider('wss://rpc.polkadot.io');
3+
const api = await ApiPromise.create({ provider });
4+
5+
async function checkAccountExistence(api, address) {
6+
const accountInfo = await api.query.system.account(address);
7+
const balance = accountInfo.data.free.toBigInt();
8+
const existentialDeposit = api.consts.balances.existentialDeposit.toBigInt();
9+
10+
return {
11+
exists: !accountInfo.isEmpty,
12+
balance,
13+
hasExistentialDeposit: balance >= existentialDeposit,
14+
};
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { dot } from '@polkadot-api/descriptors';
2+
import { createClient } from 'polkadot-api';
3+
import { getWsProvider } from 'polkadot-api/ws-provider/web';
4+
5+
async function queryAccountBalance(address: string) {
6+
const client = createClient(getWsProvider('wss://rpc.polkadot.io'));
7+
const api = client.getTypedApi(dot);
8+
9+
const accountInfo = await api.query.System.Account.getValue(address);
10+
const existentialDeposit = await api.constants.Balances.ExistentialDeposit();
11+
12+
return {
13+
balance: accountInfo?.data.free ?? 0n,
14+
hasED: (accountInfo?.data.free ?? 0n) >= existentialDeposit,
15+
};
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ah } from '@polkadot-api/descriptors';
2+
import { createClient } from 'polkadot-api';
3+
import { getWsProvider } from 'polkadot-api/ws-provider/web';
4+
5+
const client = createClient(
6+
getWsProvider('wss://asset-hub-paseo.dotters.network')
7+
);
8+
const api = client.getTypedApi(ah);
9+
10+
const feeInAsset =
11+
await api.apis.AssetConversionApi.quote_price_exact_tokens_for_tokens(
12+
assetIn,
13+
assetOut,
14+
amountIn
15+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { dot } from '@polkadot-api/descriptors';
2+
import { createClient } from 'polkadot-api';
3+
import { getWsProvider } from 'polkadot-api/ws-provider/web';
4+
5+
const client = createClient(getWsProvider('wss://rpc.polkadot.io'));
6+
const api = client.getTypedApi(dot);
7+
8+
const feeDetails = await api.apis.TransactionPaymentApi.query_fee_details(
9+
call.toHex(),
10+
call.encodedLength
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { dot } from '@polkadot-api/descriptors';
2+
import { createClient } from 'polkadot-api';
3+
import { getWsProvider } from 'polkadot-api/ws-provider/web';
4+
5+
const client = createClient(getWsProvider('wss://rpc.polkadot.io'));
6+
const api = client.getTypedApi(dot);
7+
8+
const deliveryFees = await api.apis.XcmPaymentApi.query_delivery_fees(
9+
destination,
10+
message
11+
);

.snippets/code/tutorials/polkadot-sdk/system-chains/asset-hub/batch-teleport-with-dry-run.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@ import { Builder, Version, BatchMode, hasDryRunSupport } from '@paraspell/sdk';
22

33
// Paseo has 10 decimals, use this to simplify.
44
const PAS_UNITS = 10_000_000_000;
5-
// The RPC endpoints to connect to Paseo Asset Hub.
6-
// Not needed if using Polkadot.
7-
const PASEO_AH_RPC = 'wss://asset-hub-paseo.dotters.network';
85

96
async function batchTeleport() {
107
const senderAddress = '15whavTNSyceP8SL3Z1JukFcUPzmeR26RxKXkfQiPhsykg7s';
118
const recipientAddress = '14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3';
129

1310
// Check if dry run is supported on Polkadot Asset Hub.
14-
const supportsDryRun = hasDryRunSupport('AssetHubPolkadot');
15-
console.log(`AssetHubPolkadot supports dry run: ${supportsDryRun}`);
11+
const supportsDryRun = hasDryRunSupport('AssetHubPaseo');
12+
console.log(`AssetHubPaseo supports dry run: ${supportsDryRun}`);
1613

1714
if (supportsDryRun) {
1815
console.log('Running dry run for first transaction...');
1916

2017
// Dry run the first transaction.
2118
try {
22-
const dryRunResult1 = await Builder([PASEO_AH_RPC])
23-
.from('AssetHubPolkadot')
24-
.to('Polkadot')
25-
.currency({ symbol: 'DOT', amount: 1 * PAS_UNITS })
19+
const dryRunResult1 = await Builder()
20+
.from('AssetHubPaseo')
21+
.to('Paseo')
22+
.currency({ symbol: 'PAS', amount: 1 * PAS_UNITS })
2623
.address(recipientAddress)
2724
.senderAddress(senderAddress)
2825
.xcmVersion(Version.V5)
@@ -32,10 +29,10 @@ async function batchTeleport() {
3229

3330
// Dry run the second transaction.
3431
console.log('Running dry run for second transaction...');
35-
const dryRunResult2 = await Builder([PASEO_AH_RPC])
36-
.from('AssetHubPolkadot')
37-
.to('Polkadot')
38-
.currency({ symbol: 'DOT', amount: 1 * PAS_UNITS })
32+
const dryRunResult2 = await Builder()
33+
.from('AssetHubPaseo')
34+
.to('Paseo')
35+
.currency({ symbol: 'PAS', amount: 1 * PAS_UNITS })
3936
.address(recipientAddress)
4037
.senderAddress(senderAddress)
4138
.xcmVersion(Version.V5)
@@ -49,35 +46,35 @@ async function batchTeleport() {
4946
console.dir(dryRunResult1, { depth: null });
5047
console.log('Transaction 2:');
5148
console.dir(dryRunResult2, { depth: null });
52-
53-
5449
} catch (error) {
5550
console.error('Dry run failed:', error);
5651
return; // Exit early if dry run throws an error.
5752
}
5853
} else {
59-
console.log('Dry run not supported, proceeding directly to batch transaction...');
54+
console.log(
55+
'Dry run not supported, proceeding directly to batch transaction...'
56+
);
6057
}
6158

6259
// Original batch transaction code.
63-
const builder = Builder([PASEO_AH_RPC])
64-
.from('AssetHubPolkadot')
65-
.to('Polkadot')
66-
.currency({ symbol: 'DOT', amount: 1 * PAS_UNITS })
60+
const builder = Builder()
61+
.from('AssetHubPaseo')
62+
.to('Paseo')
63+
.currency({ symbol: 'PAS', amount: 1 * PAS_UNITS })
6764
.address(recipientAddress)
6865
.xcmVersion(Version.V5)
6966
.addToBatch()
7067

71-
.from('AssetHubPolkadot')
72-
.to('Polkadot')
73-
.currency({ symbol: 'DOT', amount: 1 * PAS_UNITS })
68+
.from('AssetHubPaseo')
69+
.to('Paseo')
70+
.currency({ symbol: 'PAS', amount: 1 * PAS_UNITS })
7471
.address(recipientAddress)
7572
.xcmVersion(Version.V5)
7673
.addToBatch();
7774

7875
const tx = await builder.buildBatch({
7976
// This settings object is optional and batch all is the default option.
80-
mode: BatchMode.BATCH_ALL //or BatchMode.BATCH
77+
mode: BatchMode.BATCH_ALL, //or BatchMode.BATCH
8178
});
8279

8380
const callData = await tx.getEncodedData();
@@ -89,4 +86,4 @@ async function batchTeleport() {
8986
`);
9087
}
9188

92-
batchTeleport();
89+
batchTeleport();

.snippets/code/tutorials/polkadot-sdk/system-chains/asset-hub/index.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@ import { Builder, Version, BatchMode } from '@paraspell/sdk';
22

33
// Paseo has 10 decimals, use this to simplify.
44
const PAS_UNITS = 10_000_000_000;
5-
// The RPC endpoints to connect to Paseo.
6-
// Not needed if using Polkadot.
7-
const PASEO_AH_RPC = 'wss://asset-hub-paseo.dotters.network';
85

96
async function batchTeleport() {
10-
const builder = Builder([PASEO_AH_RPC])
11-
.from('AssetHubPolkadot')
12-
.to('Polkadot')
13-
.currency({ symbol: 'DOT', amount: 1 * PAS_UNITS })
7+
const builder = Builder()
8+
.from('AssetHubPaseo')
9+
.to('Paseo')
10+
.currency({ symbol: 'PAS', amount: 1 * PAS_UNITS })
1411
.address('15whavTNSyceP8SL3Z1JukFcUPzmeR26RxKXkfQiPhsykg7s')
1512
.xcmVersion(Version.V5)
1613
.addToBatch()
17-
18-
.from('AssetHubPolkadot')
19-
.to('Polkadot')
20-
.currency({ symbol: 'DOT', amount: 1 * PAS_UNITS })
14+
15+
.from('AssetHubPaseo')
16+
.to('Paseo')
17+
.currency({ symbol: 'PAS', amount: 1 * PAS_UNITS })
2118
.address('14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3')
2219
.xcmVersion(Version.V5)
2320
.addToBatch();
24-
const tx = await builder.buildBatch({
21+
22+
const tx = await builder.buildBatch({
2523
// This settings object is optional and batch all is the default option
26-
mode: BatchMode.BATCH_ALL //or BatchMode.BATCH
27-
})
24+
mode: BatchMode.BATCH_ALL, //or BatchMode.BATCH
25+
});
26+
2827
const callData = await tx.getEncodedData();
2928

3029
// This generates a link the polkadot developer console.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "batch-teleport-tutorial",
3+
"version": "1.0.0",
4+
"description": "Tutorial for creating batch teleport transactions with ParaSpell SDK using Bun",
5+
"main": "index.ts",
6+
"type": "module",
7+
"scripts": {
8+
"start": "bun run index.ts",
9+
"dev": "bun run --watch index.ts" // --watch automatically restarts the script when files change
10+
},
11+
},
12+
"dependencies": {
13+
"@paraspell/sdk": "^{{dependencies.javascript_packages.paraspell_sdk.version}}"
14+
}
15+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<div id="termynal" data-termynal>
2+
<span data-ty="input"><span class="file-path"></span>bun run dev</span>
3+
<br />
24
<span data-ty> Send via PAPI console:</span>
35
<span data-ty> https://dev.papi.how/extrinsics#networkId=paseo_asset_hub&endpoint=light-client&data=0x1c041c...</span>
46
</div>

0 commit comments

Comments
 (0)