Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,34 @@ jobs:

- name: E2E tests.
run: yarn test:e2e

examples:
# The type of runner that the job will run on
runs-on: ubuntu-latest

steps:
- name: Checkout files
uses: actions/checkout@v4

- name: Install Node v18
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install JS dependencies
run: yarn install

- name: Run examples
run: bash examples/run_examples.sh
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ When the API is initalized using the `CDN`, `node:fetch` is being used and is st
2. Then, build and run the desired example:

```bash
yarn build:examples && node ./examples/build/examples/<file_to_run>.js
npx tsx ./examples/build/examples/<file_to_run>.ts

```

Expand Down Expand Up @@ -307,7 +307,7 @@ api.createTransferTransaction(
);
```

If you would like to run an example to understand the output, run: `yarn build:examples && node ./examples/build/examples/paraToSystemTransferMultiAsset.js`
If you would like to run an example to understand the output, run: `npx tsx ./examples/build/examples/paraToSystemTransferMultiAsset.js`

### Foreign Asset Transfers

Expand All @@ -328,7 +328,7 @@ api.createTransferTransaction(
);
```

If you would like to run an example to understand the output run: `yarn build:examples && node ./examples/build/examples/systemToParaTeleportForeignAssets.js`
If you would like to run an example to understand the output run: `npx tsx ./examples/build/examples/systemToParaTeleportForeignAssets.js`

### Liquid Pool Asset Transfers

Expand All @@ -344,7 +344,7 @@ api.createTransferTransaction('2023', '0xF977814e90dA44bFA03b6295A0616a897441ace
});
```

If you would like to run an example to understand the output run: `yarn build:examples && node ./examples/build/examples/systemToParaLpToken.js`
If you would like to run an example to understand the output run: `npx tsx node ./examples/build/examples/systemToParaLpToken.js`

### Local Transactions

Expand Down
24 changes: 17 additions & 7 deletions examples/WestendAssetHubToWestendCollectivesXcmV4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api'
*/
import { AssetTransferApi, constructApiPromise } from '../src';
import { TxResult } from '../src/types';
import { GREEN, PURPLE, RESET } from './colors';
import { AssetTransferApi } from '../src/AssetTransferApi.js';
import { constructApiPromise } from '../src/constructApiPromise.js';
import { TxResult } from '../src/types.js';
import { GREEN, PURPLE, RESET } from './colors.js';

/**
* In this example we are creating a `limitedTeleportAssets` call to send 1 WND from a Westend AssetHub (System Parachain) account
Expand All @@ -15,7 +16,9 @@ import { GREEN, PURPLE, RESET } from './colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
let callInfo: TxResult<'call'>;
try {
Expand All @@ -40,6 +43,13 @@ const main = async () => {
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`);
};

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
void (async () => {
try {
await main();
} catch (err) {
console.error(err);
process.exit(1);
} finally {
process.exit();
}
})();
24 changes: 17 additions & 7 deletions examples/WestendAssetHubToWestendXcmV4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api'
*/
import { AssetTransferApi, constructApiPromise } from '../src';
import { TxResult } from '../src/types';
import { GREEN, PURPLE, RESET } from './colors';
import { AssetTransferApi } from '../src/AssetTransferApi.js';
import { constructApiPromise } from '../src/constructApiPromise.js';
import { TxResult } from '../src/types.js';
import { GREEN, PURPLE, RESET } from './colors.js';

/**
* In this example we are creating a `limitedTeleportAssets` call to send 1 WND from a Westend AssetHub (System Parachain) account
Expand All @@ -15,7 +16,9 @@ import { GREEN, PURPLE, RESET } from './colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
let callInfo: TxResult<'call'>;
try {
Expand All @@ -40,6 +43,13 @@ const main = async () => {
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`);
};

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
void (async () => {
try {
await main();
} catch (err) {
console.error(err);
process.exit(1);
} finally {
process.exit();
}
})();
24 changes: 17 additions & 7 deletions examples/WestendToAssetHubXcmV4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api'
*/
import { AssetTransferApi, constructApiPromise } from '../src';
import { TxResult } from '../src/types';
import { GREEN, PURPLE, RESET } from './colors';
import { AssetTransferApi } from '../src/AssetTransferApi.js';
import { constructApiPromise } from '../src/constructApiPromise.js';
import { TxResult } from '../src/types.js';
import { GREEN, PURPLE, RESET } from './colors.js';

/**
* In this example we are creating a `limitedTeleportAssets` call to send 1 WND from a Westend (Relay Chain) account
Expand All @@ -15,7 +16,9 @@ import { GREEN, PURPLE, RESET } from './colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
let callInfo: TxResult<'call'>;
try {
Expand All @@ -40,6 +43,13 @@ const main = async () => {
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`);
};

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
void (async () => {
try {
await main();
} catch (err) {
console.error(err);
process.exit(1);
} finally {
process.exit();
}
})();
24 changes: 17 additions & 7 deletions examples/claimAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
*
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api'
*/
import { AssetTransferApi, constructApiPromise } from '../src';
import { TxResult } from '../src/types';
import { GREEN, PURPLE, RESET } from './colors';
import { AssetTransferApi } from '../src/AssetTransferApi.js';
import { constructApiPromise } from '../src/constructApiPromise.js';
import { TxResult } from '../src/types.js';
import { GREEN, PURPLE, RESET } from './colors.js';

/**
* In this example we are creating a `claimAssets` call to claim `WND` tokens trapped in the AssetTrap of Westend AssetHub where the `xcmVersion` is set to 3.
*
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
let callInfo: TxResult<'call'>;
try {
Expand All @@ -36,6 +39,13 @@ const main = async () => {
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`);
};

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
void (async () => {
try {
await main();
} catch (err) {
console.error(err);
process.exit(1);
} finally {
process.exit();
}
})();
20 changes: 14 additions & 6 deletions examples/dryRunCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api'
*/
import { AssetTransferApi, constructApiPromise } from '../src';
import { TxResult } from '../src/types';
import { GREEN, PURPLE, RESET } from './colors';
import { AssetTransferApi } from '../src/AssetTransferApi.js';
import { constructApiPromise } from '../src/constructApiPromise.js';
import { TxResult } from '../src/types.js';
import { GREEN, PURPLE, RESET } from './colors.js';

/**
* In this example we are creating a `polkadotXcm` pallet `transferAssets` call to send 1 WND (asset with location `{"parents":"1","interior":{"Here":""}}`)
Expand Down Expand Up @@ -47,6 +48,13 @@ const main = async () => {
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`);
};

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
void (async () => {
try {
await main();
} catch (err) {
console.error(err);
process.exit(1);
} finally {
process.exit();
}
})();
24 changes: 17 additions & 7 deletions examples/fetchFeeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api'
*/
import { AssetTransferApi, constructApiPromise } from '../src';
import { TxResult } from '../src/types';
import { GREEN, PURPLE, RESET } from './colors';
import { AssetTransferApi } from '../src/AssetTransferApi.js';
import { constructApiPromise } from '../src/constructApiPromise.js';
import { TxResult } from '../src/types.js';
import { GREEN, PURPLE, RESET } from './colors.js';

/**
* In this example we are creating a call to send WETH from a Bifrost Polkadot (Parachain) account
Expand All @@ -16,7 +17,9 @@ import { GREEN, PURPLE, RESET } from './colors';
*/
const main = async () => {
const safeXcmVersion = 3;
const { api, specName } = await constructApiPromise('wss://bifrost-polkadot-rpc.dwellir.com');
const { api, specName } = await constructApiPromise('wss://bifrost-polkadot-rpc.dwellir.com', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
let callInfo: TxResult<'call'>;
try {
Expand Down Expand Up @@ -45,6 +48,13 @@ const main = async () => {
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`);
};

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
void (async () => {
try {
await main();
} catch (err) {
console.error(err);
process.exit(1);
} finally {
process.exit();
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api'
*/
import { AssetTransferApi, constructApiPromise } from '../../../../src';
import { TxResult } from '../../../../src/types';
import { GREEN, PURPLE, RESET } from '../../../colors';
import { AssetTransferApi } from '../../../../src/AssetTransferApi.js';
import { constructApiPromise } from '../../../../src/constructApiPromise.js';
import { TxResult } from '../../../../src/types.js';
import { GREEN, PURPLE, RESET } from '../../../colors.js';

/**
* In this example we are creating a `polkadotXcm` pallet `transferAssets` call to send 1 DOT (foreign asset with location `{"parents":"2","interior":{"X1":{"GlobalConsensus":"Polkadot"}}}`)
Expand All @@ -16,7 +17,9 @@ import { GREEN, PURPLE, RESET } from '../../../colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo: TxResult<'call'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { GREEN, PURPLE, RESET } from '../../../colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo: TxResult<'call'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { GREEN, PURPLE, RESET } from '../../../../colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo: TxResult<'call'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { GREEN, PURPLE, RESET } from '../../../../colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo: TxResult<'call'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { GREEN, PURPLE, RESET } from '../../../../colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo: TxResult<'call'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { GREEN, PURPLE, RESET } from '../../../../colors';
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`.
*/
const main = async () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io');
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io', {
throwOnConnect: true,
});
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo: TxResult<'call'>;
Expand Down
Loading
Loading