Skip to content

Commit

Permalink
update docs to xcm v4
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaben committed Apr 26, 2024
1 parent ba4c186 commit e657161
Show file tree
Hide file tree
Showing 50 changed files with 679 additions and 806 deletions.
@@ -1,4 +1,4 @@
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 9.13.6
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 10.13.1

// 1. Input data
const providerWsURL = 'wss://wss.api.moonbase.moonbeam.network';
Expand All @@ -11,7 +11,7 @@ const xcmTransaction = {
},
};

const getEncodedCallData = async () => {
const getEncodedCalldata = async () => {
// 2. Create Substrate API Provider
const substrateProvider = new WsProvider(providerWsURL);
const api = await ApiPromise.create({ provider: substrateProvider });
Expand All @@ -27,4 +27,4 @@ const getEncodedCallData = async () => {
api.disconnect();
};

getEncodedCallData();
getEncodedCalldata();
@@ -1,4 +1,4 @@
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 9.13.6
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 10.13.1

// 1. Input data
const providerWsURL = 'wss://wss.api.moonbase.moonbeam.network';
Expand All @@ -11,7 +11,7 @@ const xcmTransaction = {
},
};

const getEncodedCallData = async () => {
const getEncodedCalldata = async () => {
// 2. Create Substrate API Provider
const substrateProvider = new WsProvider(providerWsURL);
const api = await ApiPromise.create({ provider: substrateProvider });
Expand All @@ -26,4 +26,4 @@ const getEncodedCallData = async () => {
api.disconnect();
};

getEncodedCallData();
getEncodedCalldata();
@@ -1,23 +1,23 @@
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; // Version 9.13.6
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; // Version 10.13.1
import { cryptoWaitReady } from '@polkadot/util-crypto';

// 1. Input data
const providerWsURL =
'wss://fro-moon-rpc-1-moonbase-relay-rpc-1.moonbase.ol-infra.network';
const privateKey = 'INSERT_PRIVATE_KEY';
const dest = { V3: { parents: 0, interior: { X1: { Parachain: 1000 } } } };
const dest = { V4: { parents: 0, interior: { X1: [{ Parachain: 1000 }] } } };
const instr1 = {
WithdrawAsset: [
{
id: { Concrete: { parents: 0, interior: { X1: { PalletInstance: 3 } } } },
id: { parents: 0, interior: { X1: [{ PalletInstance: 3 }] } },
fun: { Fungible: 10000000000000000n }, // 0.01 DEV
},
],
};
const instr2 = {
BuyExecution: [
{
id: { Concrete: { parents: 0, interior: { X1: { PalletInstance: 3 } } } },
id: { parents: 0, interior: { X1: [{ PalletInstance: 3 }] } },
fun: { Fungible: 10000000000000000n }, // 0.01 DEV
},
{ Unlimited: null },
Expand All @@ -26,15 +26,14 @@ const instr2 = {
const instr3 = {
Transact: {
originKind: 'SovereignAccount',
requireWeightAtMost: { refTime: 3900000000n, proofSize: 38750n },
requireWeightAtMost: { refTime: 3900000000n, proofSize: 9687n },
call: {
encoded:
'0x260001785d02000000000000000000000000000000000000000000000000000000000000a72f549a1a12b9b49f30a7f3aeb1f4e96389c5d8000000000000000000000000000000000000000000000000000000000000000010d09de08a00',
},
},
};
const message = { V3: [instr1, instr2, instr3] };

const message = { V4: [instr1, instr2, instr3] };

const sendXcmMessage = async () => {
// 2. Create Keyring instance
Expand Down
@@ -1,4 +1,4 @@
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 9.13.6
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 10.13.1

const providerWsURL = 'wss://wss.api.moonbase.moonbeam.network';

Expand All @@ -19,6 +19,8 @@ const main = async () => {
const unitsPerSecond = data.toString();
console.log(unitsPerSecond);
}

api.disconnect();
};

main();
@@ -1,7 +1,7 @@
import { ApiPromise, WsProvider } from '@polkadot/api';

const assetLocation = {
V3: {
V4: {
parents: INSERT_PARENTS,
interior: INSERT_INTERIOR,
},
Expand Down
@@ -1,7 +1,7 @@
import { ApiPromise, WsProvider } from '@polkadot/api';

const assetLocation = {
V3: {
V4: {
parents: INSERT_PARENTS,
interior: INSERT_INTERIOR,
},
Expand Down
@@ -1,7 +1,7 @@
import { ApiPromise, WsProvider } from '@polkadot/api';

const assetLocation = {
V3: {
V4: {
parents: INSERT_PARENTS,
interior: INSERT_INTERIOR,
},
Expand Down
@@ -1,7 +1,7 @@
import { ApiPromise, WsProvider } from '@polkadot/api';

const dest = {
V3: {
V4: {
parents: INSERT_PARENTS,
interior: INSERT_INTERIOR,
},
Expand Down
@@ -1,7 +1,7 @@
import { ApiPromise, WsProvider } from '@polkadot/api';

const dest = {
V3: {
V4: {
parents: INSERT_PARENTS,
interior: INSERT_INTERIOR,
},
Expand Down
@@ -1,21 +1,24 @@
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 9.13.6
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 10.13.1

const providerWsURL = 'wss://wss.api.moonbase.moonbeam.network';

const location = { parents: 1, interior: { X1: { Parachain: 888 } } };
const location = { parents: 1, interior: { X1: [{ Parachain: 888 }] } };

const main = async () => {
const substrateProvider = new WsProvider(providerWsURL);
const api = await ApiPromise.create({ provider: substrateProvider });

const transactInfoWithWeightLimit = await api.query.xcmTransactor.transactInfoWithWeightLimit(location);
const transactInfoWithWeightLimit =
await api.query.xcmTransactor.transactInfoWithWeightLimit(location);

if (transactInfoWithWeightLimit.isSome) {
const data = transactInfoWithWeightLimit.unwrap();
const transactExtraWeightSigned =
data.toJSON().transactExtraWeightSigned.refTime;
console.log(transactExtraWeightSigned);
}

api.disconnect();
};

main();
@@ -1,12 +1,13 @@
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; // Version 9.13.6
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; // Version 10.13.1
import { cryptoWaitReady } from '@polkadot/util-crypto';

// 1. Provide input data
const providerWsURL = 'wss://wss.api.moonbase.moonbeam.network';
const privateKey = 'INSERT_PRIVATE_KEY';
const dest = {
V3: {
V4: {
parents: 1,
interior: { X1: { Parachain: 888 } },
interior: { X1: [{ Parachain: 888 }] },
},
};
const fee = {
Expand All @@ -22,11 +23,12 @@ const weightInfo = {
};
const refund = true;

// 2. Create Keyring instance
const keyring = new Keyring({ type: 'ethereum' });
const alice = keyring.addFromUri(privateKey);

const transactThroughSigned = async () => {
// 2. Create Keyring instance
await cryptoWaitReady();
const keyring = new Keyring({ type: 'ethereum' });
const alice = keyring.addFromUri(privateKey);

// 3. Create Substrate API provider
const substrateProvider = new WsProvider(providerWsURL);
const api = await ApiPromise.create({ provider: substrateProvider });
Expand Down
Expand Up @@ -8,8 +8,8 @@ const provider = new ethers.JsonRpcProvider(
'https://rpc.api.moonbase.moonbeam.network'
);
const signer = new ethers.Wallet(privateKey, provider);
const xcmTransactorV2 = new ethers.Contract(
'0x000000000000000000000000000000000000080d',
const xcmTransactorV3 = new ethers.Contract(
'0x0000000000000000000000000000000000000817',
abi,
signer
);
Expand All @@ -24,7 +24,7 @@ const multilocation = [
];

const main = async () => {
const feePerSecond = await xcmTransactorV2.feePerSecond(
const feePerSecond = await xcmTransactorV3.feePerSecond(
multilocation
);

Expand Down
Expand Up @@ -8,8 +8,8 @@ const provider = new ethers.JsonRpcProvider(
'https://rpc.api.moonbase.moonbeam.network'
);
const signer = new ethers.Wallet(privateKey, provider);
const xcmTransactorV2 = new ethers.Contract(
'0x000000000000000000000000000000000000080d',
const xcmTransactorV3 = new ethers.Contract(
'0x0000000000000000000000000000000000000817',
abi,
signer
);
Expand All @@ -23,7 +23,7 @@ const multilocation = [
];

const main = async () => {
const transactInfoWithSigned = await xcmTransactorV2.transactInfoWithSigned(
const transactInfoWithSigned = await xcmTransactorV3.transactInfoWithSigned(
multilocation
);
console.log(transactInfoWithSigned);
Expand Down
@@ -1,5 +1,5 @@
import ABI from './xcmUtilsABI.js'; // Import the XCM Utilities Precompile ABI
import { ethers } from 'ethers'; // Import Ethers library
import abi from './xcmUtilsABI.js'; // Import the XCM Utilities Precompile ABI

const privateKey = 'INSERT_YOUR_PRIVATE_KEY';
const xcmUtilsAddress = '0x000000000000000000000000000000000000080C';
Expand All @@ -13,7 +13,7 @@ const signer = new ethers.Wallet(privateKey, provider);
/* Create contract instance of the XCM Utilities Precompile */
const xcmUtils = new ethers.Contract(
xcmUtilsAddress,
ABI,
abi,
signer
);

Expand Down
@@ -1,40 +1,44 @@
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; // Version 9.13.6
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; // Version 10.13.1
import { cryptoWaitReady } from '@polkadot/util-crypto';

// 1. Provide input data
const providerWsURL = 'wss://wss.api.moonbase.moonbeam.network';
const privateKey = 'INSERT_PRIVATE_KEY';
const moonbeamAccount = 'INSERT_ADDRESS';
const instr1 = {
WithdrawAsset: [
{
id: { Concrete: { parents: 0, interior: { X1: { PalletInstance: 3 } } } },
fun: { Fungible: 100000000000000000n },
id: { parents: 0, interior: { X1: [{ PalletInstance: 3 }] } },
fun: { Fungible: 100000000000000000n }, // 0.1 DEV
},
],
};
const instr2 = {
DepositAsset: {
assets: { Wild: { AllCounted: 1 } },
assets: { Wild: 'All' },
beneficiary: {
parents: 0,
interior: {
X1: {
AccountKey20: {
key: moonbeamAccount,
X1: [
{
AccountKey20: {
key: '0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0',
},
},
},
],
},
},
},
};
const message = { V3: [instr1, instr2] };
const maxWeight = { refTime: 400000000n, proofSize: 14484n };
const message = { V4: [instr1, instr2] };
const maxWeight = { refTime: 400000000n, proofSize: 14484n };

// 2. Create Keyring instance
const keyring = new Keyring({ type: 'ethereum' });
const alice = keyring.addFromUri(privateKey);

const executeXcmMessage = async () => {
// 2. Create Keyring instance
await cryptoWaitReady();
const keyring = new Keyring({ type: 'ethereum' });
const alice = keyring.addFromUri(privateKey);

// 3. Create Substrate API provider
const substrateProvider = new WsProvider(providerWsURL);
const api = await ApiPromise.create({ provider: substrateProvider });
Expand Down
@@ -1,12 +1,12 @@
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 9.13.6
import { ApiPromise, WsProvider } from '@polkadot/api'; // Version 10.13.1

// 1. Provide input data
const moonbeamAccount = 'INSERT_ADDRESS'
const moonbeamAccount = 'INSERT_ADDRESS';
const providerWsURL = 'wss://wss.api.moonbase.moonbeam.network';
const instr1 = {
WithdrawAsset: [
{
id: { Concrete: { parents: 0, interior: { X1: { PalletInstance: 3 } } } },
id: { parents: 0, interior: { X1: [{ PalletInstance: 3 }] } },
fun: { Fungible: 100000000000000000n },
},
],
Expand All @@ -17,17 +17,19 @@ const instr2 = {
beneficiary: {
parents: 0,
interior: {
X1: {
AccountKey20: {
key: moonbeamAccount,
X1: [
{
AccountKey20: {
key: moonbeamAccount,
},
},
},
],
},
},
},
};
const message = { V3: [instr1, instr2] };
const maxWeight = { refTime: 400000000n, proofSize: 14484n };
const message = { V4: [instr1, instr2] };
const maxWeight = { refTime: 400000000n, proofSize: 14484n };

const getEncodedXcmMessage = async () => {
// 2. Create Substrate API provider
Expand All @@ -40,10 +42,10 @@ const getEncodedXcmMessage = async () => {
// 4. Get the encoded XCM message
// By using index 0, you'll get just the encoded XCM message.
// If you wanted to get the maxWeight, you could use index 1
const encodedXcmMessage = tx.args[0].toHex()
const encodedXcmMessage = tx.args[0].toHex();
console.log(`Encoded Calldata for XCM Message: ${encodedXcmMessage}`);

api.disconnect();
}
};

getEncodedXcmMessage();
getEncodedXcmMessage();
@@ -1,5 +1,5 @@
import ABI from './xcmUtilsABI.js'; // Import the XCM Utilities Precompile ABI
import { Web3 } from 'web3'; // Import Web3 library
import abi from './xcmUtilsABI.js'; // Import the XCM Utilities Precompile ABI

const privateKey = 'INSERT_PRIVATE_KEY';
const accountFrom = web3.eth.accounts.privateKeyToAccount(privateKey).address;
Expand All @@ -10,7 +10,7 @@ const web3 = new Web3('https://rpc.api.moonbase.moonbeam.network'); // Change to

/* Create contract instance of the XCM Utilities Precompile */
const xcmUtils = new web3.eth.Contract(
ABI,
abi,
xcmUtilsAddress,
{ from: accountFrom } // 'from' is necessary for gas estimation
);
Expand Down

0 comments on commit e657161

Please sign in to comment.