Skip to content

Instantly share code, notes, and snippets.

@josepot
Last active July 25, 2025 07:25
Show Gist options
  • Save josepot/99a8237339a46198f626a1556d71d258 to your computer and use it in GitHub Desktop.
Save josepot/99a8237339a46198f626a1556d71d258 to your computer and use it in GitHub Desktop.
// First install PAPI and add the passet chain, like this:
// bun i polkadot-api
// bun papi add -w wss://testnet-passet-hub.polkadot.io passet
// Then put the content below in a file like `index.ts` and simply run:
// bun index.ts
import {
passet,
XcmVersionedXcm,
XcmV5Instruction,
XcmV5AssetFilter,
XcmV5Junction,
XcmV5Junctions,
XcmV3MultiassetFungibility,
XcmV3WeightLimit,
XcmV5WildAsset,
XcmV2MultiassetWildFungibility,
} from "@polkadot-api/descriptors"
import { Binary, getTypedCodecs, AccountId } from "polkadot-api"
import { toHex } from "polkadot-api/utils"
const recipientAddress = "5DJEnMcMvsvD3EsbVjnUAETUsitvBoieqMxTWp8y6EUkGMgN" // Replace with actual address
const recipientPublicKey = AccountId().enc(recipientAddress)
// Prepare the XCM message with V5 instructions
const xcmMessage = XcmVersionedXcm.V5([
// WithdrawAsset instruction
XcmV5Instruction.WithdrawAsset([
{
id: {
parents: 1,
interior: XcmV5Junctions.Here(),
},
fun: XcmV3MultiassetFungibility.Fungible(1200000000n),
},
]),
// BuyExecution instruction
XcmV5Instruction.BuyExecution({
fees: {
id: {
parents: 1,
interior: XcmV5Junctions.Here(),
},
fun: XcmV3MultiassetFungibility.Fungible(1200000000n),
},
weight_limit: XcmV3WeightLimit.Unlimited(),
}),
// DepositAsset instruction
XcmV5Instruction.DepositAsset({
assets: XcmV5AssetFilter.Wild(
XcmV5WildAsset.AllOf({
id: {
parents: 1,
interior: XcmV5Junctions.Here(),
},
fun: XcmV2MultiassetWildFungibility.Fungible(),
})
),
beneficiary: {
parents: 0,
interior: XcmV5Junctions.X1(
XcmV5Junction.AccountId32({
network: undefined,
id: Binary.fromBytes(recipientPublicKey),
})
),
},
}),
])
const typedCodecs = await getTypedCodecs(passet)
const xcmExecuteTxCodec = typedCodecs.tx.PolkadotXcm.execute
const xcmMsgCodec = xcmExecuteTxCodec.inner.message
console.log(toHex(xcmMsgCodec.enc(xcmMessage)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment