Skip to content

Commit 8949721

Browse files
committed
fix: llms
1 parent ecd221b commit 8949721

File tree

2 files changed

+318
-0
lines changed

2 files changed

+318
-0
lines changed

llms-full.txt

Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Doc-Page: https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/re
180180
Doc-Page: https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/dapps/remark-tutorial.md
181181
Doc-Page: https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/index.md
182182
Doc-Page: https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/index.md
183+
Doc-Page: https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/pay-tx-with-different-fees.md
183184
Doc-Page: https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/replay-and-dry-run-xcms.md
184185
Doc-Page: https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-channels/index.md
185186
Doc-Page: https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-channels/para-to-para.md
@@ -29990,6 +29991,322 @@ Learn to establish and use cross-chain communication channels:
2999029991
</div>
2999129992
--- END CONTENT ---
2999229993

29994+
Doc-Content: https://docs.polkadot.com/tutorials/interoperability/pay-tx-with-different-fees/
29995+
--- BEGIN CONTENT ---
29996+
---
29997+
title: Send Transaction Paying Fees with Different Tokens
29998+
description: This tutorial demonstrates how to send a DOT transfer transaction while paying the fees using a different token on the Asset Hub.
29999+
---
30000+
30001+
# Send Transaction Paying Fees with Different Tokens
30002+
30003+
## Introduction
30004+
30005+
The Asset Hub provides a powerful feature that allows users to pay transaction fees using alternative tokens instead of the native token of the chain.
30006+
30007+
This tutorial demonstrates how to send a DOT transfer transaction while paying the fees using a different token (USDT in this example) on the Asset Hub.
30008+
30009+
## Environment Setup
30010+
30011+
Let's set up the development environment for this tutorial:
30012+
30013+
1. Create a new directory and initialize the project:
30014+
30015+
```bash
30016+
mkdir fee-payment-tutorial && \
30017+
cd fee-payment-tutorial
30018+
```
30019+
30020+
2. Initialize the project:
30021+
30022+
```bash
30023+
npm init -y
30024+
```
30025+
30026+
3. Install dev dependencies:
30027+
30028+
```bash
30029+
npm install --save-dev @types/node@^22.12.0 ts-node@^10.9.2 typescript@^5.7.3
30030+
```
30031+
30032+
4. Install dependencies:
30033+
30034+
```bash
30035+
npm install --save @polkadot-labs/hdkd@^0.0.13 @polkadot-labs/hdkd-helpers@^0.0.13 [email protected]
30036+
```
30037+
30038+
5. Create TypeScript configuration:
30039+
30040+
```bash
30041+
npx tsc --init
30042+
```
30043+
30044+
6. Generate the types for the Polkadot API for Asset Hub:
30045+
30046+
```bash
30047+
npx papi add assetHub -n polkadot_asset_hub
30048+
```
30049+
30050+
7. Create a new file called `fee-payment-transaction.ts`:
30051+
30052+
```bash
30053+
touch fee-payment-transaction.ts
30054+
```
30055+
30056+
## Local Asset Hub Setup
30057+
30058+
Before running the script, you'll need to fork the Asset Hub locally using Chopsticks:
30059+
30060+
```bash
30061+
chopsticks -c polkadot-asset-hub
30062+
```
30063+
30064+
This command will fork the Asset Hub chain and make it available at `ws://localhost:8000`.
30065+
30066+
## Implementation
30067+
30068+
Now let's implement the fee payment transaction step by step.
30069+
30070+
### Import Dependencies
30071+
30072+
Add the following imports to your `fee-payment-transaction.ts` file:
30073+
30074+
```typescript title="fee-payment-transaction.ts"
30075+
import { sr25519CreateDerive } from "@polkadot-labs/hdkd";
30076+
import {
30077+
DEV_PHRASE,
30078+
entropyToMiniSecret,
30079+
mnemonicToEntropy,
30080+
} from "@polkadot-labs/hdkd-helpers";
30081+
import { getPolkadotSigner } from "polkadot-api/signer";
30082+
import { createClient } from "polkadot-api";
30083+
import { assetHub } from "@polkadot-api/descriptors";
30084+
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
30085+
import { getWsProvider } from "polkadot-api/ws-provider/node";
30086+
import { MultiAddress } from "@polkadot-api/descriptors";
30087+
```
30088+
30089+
### Define Constants
30090+
30091+
Define the constants for your transaction:
30092+
30093+
```typescript title="fee-payment-transaction.ts"
30094+
const TARGET_ADDRESS = "14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3"; // Bob's address
30095+
const TRANSFER_AMOUNT = 3_000_000_000n; // 3 DOT
30096+
const USD_ASSET_ID = 1337;
30097+
```
30098+
30099+
### Create Signer
30100+
30101+
Create a signer using Alice's development account:
30102+
30103+
```typescript title="fee-payment-transaction.ts"
30104+
const createSigner = async () => {
30105+
const entropy = mnemonicToEntropy(DEV_PHRASE);
30106+
const miniSecret = entropyToMiniSecret(entropy);
30107+
const derive = sr25519CreateDerive(miniSecret);
30108+
const hdkdKeyPair = derive("//Alice");
30109+
const polkadotSigner = getPolkadotSigner(
30110+
hdkdKeyPair.publicKey,
30111+
"Sr25519",
30112+
hdkdKeyPair.sign
30113+
);
30114+
return polkadotSigner;
30115+
};
30116+
```
30117+
30118+
This function will return a signer that can be used to sign the transaction.
30119+
30120+
### Setup Client and API
30121+
30122+
Create the client connection to the local Asset Hub:
30123+
30124+
```typescript title="fee-payment-transaction.ts"
30125+
const client = createClient(
30126+
withPolkadotSdkCompat(
30127+
getWsProvider("ws://localhost:8000") // Chopsticks Asset Hub
30128+
)
30129+
);
30130+
30131+
const api = client.getTypedApi(assetHub);
30132+
```
30133+
30134+
### Create the Transaction
30135+
30136+
Create a standard DOT transfer transaction:
30137+
30138+
```typescript title="fee-payment-transaction.ts"
30139+
const tx = api.tx.Balances.transfer_keep_alive({
30140+
dest: MultiAddress.Id(TARGET_ADDRESS),
30141+
value: BigInt(TRANSFER_AMOUNT),
30142+
});
30143+
```
30144+
30145+
This creates a transaction that transfers 3 DOT to Bob's address while keeping Alice's account alive.
30146+
30147+
### Sign and Submit with Alternative Fee Payment
30148+
30149+
The key part of this tutorial is specifying an alternative asset for fee payment. This is done through the `asset` parameter in the `signAndSubmit` options:
30150+
30151+
```typescript title="fee-payment-transaction.ts"
30152+
const signer = await createSigner();
30153+
30154+
const result = await tx.signAndSubmit(signer, {
30155+
asset: {
30156+
parents: 0,
30157+
interior: {
30158+
type: "X2",
30159+
value: [
30160+
{ type: "PalletInstance", value: 50 },
30161+
{ type: "GeneralIndex", value: BigInt(USD_ASSET_ID) },
30162+
],
30163+
},
30164+
},
30165+
});
30166+
30167+
const { txHash, ok, block, events } = result;
30168+
console.log(`Tx finalized: ${txHash} (ok=${ok})`);
30169+
console.log(`Block: #${block.number} ${block.hash} [tx index ${block.index}]`);
30170+
30171+
console.log("Events:");
30172+
for (const ev of events) {
30173+
const type = (ev as any).type ?? "unknown";
30174+
console.log(`- ${type}`);
30175+
}
30176+
30177+
process.exit(0);
30178+
```
30179+
30180+
This specifies that the fees should be paid using the USDT asset.
30181+
30182+
## Full Code
30183+
30184+
The full code for the complete implementation is the following:
30185+
30186+
??? code "Complete Code"
30187+
30188+
```typescript title="fee-payment-transaction.ts"
30189+
import { sr25519CreateDerive } from "@polkadot-labs/hdkd";
30190+
import {
30191+
DEV_PHRASE,
30192+
entropyToMiniSecret,
30193+
mnemonicToEntropy,
30194+
} from "@polkadot-labs/hdkd-helpers";
30195+
import { getPolkadotSigner } from "polkadot-api/signer";
30196+
import { createClient } from "polkadot-api";
30197+
import { assetHub } from "@polkadot-api/descriptors";
30198+
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
30199+
import { getWsProvider } from "polkadot-api/ws-provider/node";
30200+
import { MultiAddress } from "@polkadot-api/descriptors";
30201+
30202+
const TARGET_ADDRESS = "14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3"; // Bob's address
30203+
const TRANSFER_AMOUNT = 3_000_000_000n; // 3 DOT
30204+
const USD_ASSET_ID = 1337;
30205+
30206+
const createSigner = async () => {
30207+
const entropy = mnemonicToEntropy(DEV_PHRASE);
30208+
const miniSecret = entropyToMiniSecret(entropy);
30209+
const derive = sr25519CreateDerive(miniSecret);
30210+
const hdkdKeyPair = derive("//Alice");
30211+
const polkadotSigner = getPolkadotSigner(
30212+
hdkdKeyPair.publicKey,
30213+
"Sr25519",
30214+
hdkdKeyPair.sign
30215+
);
30216+
return polkadotSigner;
30217+
};
30218+
30219+
const client = createClient(
30220+
withPolkadotSdkCompat(
30221+
getWsProvider("ws://localhost:8000") // Chopsticks Asset Hub
30222+
)
30223+
);
30224+
30225+
const api = client.getTypedApi(assetHub);
30226+
30227+
const tx = api.tx.Balances.transfer_keep_alive({
30228+
dest: MultiAddress.Id(TARGET_ADDRESS),
30229+
value: BigInt(TRANSFER_AMOUNT),
30230+
});
30231+
30232+
const signer = await createSigner();
30233+
30234+
const result = await tx.signAndSubmit(signer, {
30235+
asset: {
30236+
parents: 0,
30237+
interior: {
30238+
type: "X2",
30239+
value: [
30240+
{ type: "PalletInstance", value: 50 },
30241+
{ type: "GeneralIndex", value: BigInt(USD_ASSET_ID) },
30242+
],
30243+
},
30244+
},
30245+
});
30246+
30247+
const { txHash, ok, block, events } = result;
30248+
console.log(`Tx finalized: ${txHash} (ok=${ok})`);
30249+
console.log(`Block: #${block.number} ${block.hash} [tx index ${block.index}]`);
30250+
30251+
console.log("Events:");
30252+
for (const ev of events) {
30253+
const type = (ev as any).type ?? "unknown";
30254+
console.log(`- ${type}`);
30255+
}
30256+
30257+
process.exit(0);
30258+
```
30259+
30260+
## Running the Script
30261+
30262+
1. Make sure Chopsticks is running with the Asset Hub fork:
30263+
30264+
```bash
30265+
chopsticks -c polkadot-asset-hub
30266+
```
30267+
30268+
2. Run the script:
30269+
30270+
```bash
30271+
npx ts-node fee-payment-transaction.ts
30272+
```
30273+
30274+
## Expected Output
30275+
30276+
When you run the script successfully, you should see output similar to:
30277+
30278+
<div id="termynal" data-termynal>
30279+
<span data-ty="input"><span class="file-path"></span>npx ts-node fee-payment-transaction.ts</span>
30280+
<pre>
30281+
Tx finalized: 0x771956fdf40b3741bdc3c1e981a6daacbe5521877ad1915542e7413bb4a820bc (ok=true)
30282+
Block: #9645060 0x57710514f168b5c444c8e47b1e1a31dd9e7bc7e9a51d8d25ccdbc6053e159f6b [tx index 2]
30283+
Events:
30284+
- Assets
30285+
- Balances
30286+
- Assets
30287+
- AssetConversion
30288+
- Balances
30289+
- Balances
30290+
- AssetTxPayment
30291+
- System
30292+
</pre>
30293+
</div>
30294+
30295+
The key events to look for are:
30296+
30297+
- **Assets**: The asset was transferred
30298+
- **Balances**: The fees were paid using the alternative asset
30299+
- **AssetConversion**: The fees were converted to the alternative asset
30300+
- **AssetTxPayment**: The fees were paid using the alternative asset
30301+
- **System**: The transaction was successful
30302+
30303+
## Conclusion
30304+
30305+
Paying transaction fees with alternative tokens on Asset Hub provides significant flexibility for users and applications.
30306+
30307+
The key takeaway is understanding how to specify alternative assets using the XCM location format, which opens up possibilities for building applications that can operate entirely using specific token ecosystems while still leveraging the full power of the network.
30308+
--- END CONTENT ---
30309+
2999330310
Doc-Content: https://docs.polkadot.com/tutorials/interoperability/replay-and-dry-run-xcms/
2999430311
--- BEGIN CONTENT ---
2999530312
---

llms.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
- [PAPI Account Watcher Tutorial](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/dapps/remark-tutorial.md): Build a CLI app that listens to on-chain events using the Polkadot API and responds to specific messages for a given account.
179179
- [Tutorials](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/index.md): Explore step-by-step tutorials for building in Polkadot, from parachain deployment and testing to cross-chain asset creation and XCM channel management.
180180
- [Interoperability Tutorials](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/index.md): Explore tutorials on interoperability for Polkadot SDK-based blockchains, covering cross-chain communication and integration techniques.
181+
- [Send Transaction Paying Fees with Different Tokens](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/pay-tx-with-different-fees.md): This tutorial demonstrates how to send a DOT transfer transaction while paying the fees using a different token on the Asset Hub.
181182
- [Replay and Dry Run XCMs](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/replay-and-dry-run-xcms.md): Replay and dry-run XCMs using Chopsticks with full logging enabled. Diagnose issues, trace message flow, and debug complex cross-chain interactions.
182183
- [Tutorials for Managing XCM Channels](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-channels/index.md): Learn step-by-step how to establish unidirectional and bidirectional HRMP channels between parachains and system parachains using XCM.
183184
- [Opening HRMP Channels Between Parachains](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-channels/para-to-para.md): Learn how to open HRMP channels between parachains on Polkadot. Discover the step-by-step process for establishing uni- and bidirectional communication.

0 commit comments

Comments
 (0)