Holds open an api connection to a specified chain within the ApiPromise in order to help construct transactions for assets and estimating fees.

import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api'

const main = () => {
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://some_ws_url');
const assetsApi = new AssetTransferApi(api, specName, safeXcmVersion);
}

Methods

  • Create a local claimAssets XCM transaction to retrieve trapped assets. This can be either locally on a systems parachain, on the relay chain or any chain that supports the pallet-xcm claimAssets runtime call.

    import { TxResult } from '@substrate/asset-transfer-api'

    let callInfo: TxResult<'call'>;
    try {
    callInfo = await assetsApi.claimAssets(
    [`{"parents":"0","interior":{"X2":[{"PalletInstance":"50"},{"GeneralIndex":"1984"}]}}`],
    ['1000000000000'],
    '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
    {
    format: 'call',
    xcmVersion: 2,
    }
    )
    } catch (e) {
    console.error(e);
    throw Error(e);
    }

    Type Parameters

    Parameters

    • assetIds: string[]

      Array of assetId's to be claimed from the AssetTrap

    • amounts: string[]

      Array of the amounts of each trapped asset to be claimed

    • beneficiary: string

      Address of the account to receive the trapped assets

    • opts: TransferArgsOpts<T>

      Options

    Returns Promise<TxResult<T>>

  • Create an asset transfer transaction. This can be either locally on a systems parachain or relay chain, or between chains using xcm.

    import { TxResult } from '@substrate/asset-transfer-api'

    let callInfo: TxResult<'call'>;
    try {
    callInfo = await assetsApi.createTransferTransaction(
    '1000',
    '5EWNeodpcQ6iYibJ3jmWVe85nsok1EDG8Kk3aFg8ZzpfY1qX',
    ['WND'],
    ['1000000000000'],
    {
    format: 'call',
    xcmVersion: 2,
    }
    )
    } catch (e) {
    console.error(e);
    throw Error(e);
    }

    Type Parameters

    Parameters

    • destChainId: string

      ID of the destination (para) chain (‘0’ for Relaychain)

    • destAddr: string

      Address of destination account

    • assetIds: string[]

      Array of assetId's to be transferred

    • amounts: string[]

      Array of the amounts of each token to transfer

    • opts: TransferArgsOpts<T> = {}

      Options

    Returns Promise<TxResult<T>>

  • Decodes the hex of an extrinsic into a string readable format.

    const decodedExt = assetsApi.decodeExtrinsic(tx, 'call');
    console.log(JSON.parse(decodedExt));

    Type Parameters

    Parameters

    • encodedTransaction: string

      the hex of an extrinsic tx

    • format: T

      The format the tx is in

    Returns string

  • Dry Run a call to determine its execution result

    const executionResult = await assetApi.dryRunCall(sendersAddr, tx, 'call');
    console.log(executionResult.toJSON());

    Type Parameters

    Parameters

    • sendersAddr: string

      address of the account sending the transaction

    • tx: ConstructedFormat<T>

      a payload, call or submittable

    • format: T

      The format the tx is in

    Returns Promise<null | Result<CallDryRunEffects, XcmDryRunApiError>>

  • Fetch estimated fee information for an extrinsic

    const feeInfo = assetApi.fetchFeeInfo(tx, 'call');
    console.log(feeInfo.toJSON());

    Type Parameters

    Parameters

    • tx: ConstructedFormat<T>

      a payload, call or submittable

    • format: T

      The format the tx is in

    Returns Promise<null | RuntimeDispatchInfo | RuntimeDispatchInfoV1>

  • Initialize the registry. This will only activate the registry for the CDN. If the registryType is NPM the initalization will exit since the AssetTransferApi initializes with the reigstry from the NPM package.

    Returns Promise<void>