-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement dryRunCall option (#433)
- Loading branch information
Showing
17 changed files
with
720 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* When importing from @substrate/asset-transfer-api it would look like the following | ||
* | ||
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api' | ||
*/ | ||
import { AssetTransferApi, constructApiPromise } from '../src'; | ||
import { TxResult } from '../src/types'; | ||
import { GREEN, PURPLE, RESET } from './colors'; | ||
|
||
/** | ||
* In this example we are creating a `polkadotXcm` pallet `transferAssets` call to send 1 WND (asset with location `{"parents":"1","interior":{"Here":""}}`) | ||
* from a Westend Asset Hub (System Parachain) account | ||
* to a Westend BridheHub account, where the `xcmVersion` is set to safeXcmVersion and no `weightLimit` option is provided declaring that | ||
* the tx will allow unlimited weight to be used for fees. The `dryRunCall` option is set to true, which allows for the transaction to be dry run after being constructed. | ||
* The `XcmFeeAsset` is set to `wnd` which will be the asset used to estimate fees during the dry run of the extrinsic. | ||
* The fee for each XCM and the overall execution result will be returned with the TxResult info. | ||
* | ||
* NOTE: When dry running a call, the `sendersAddr` and `xcmFeeAsset` fields must be provided. | ||
*/ | ||
const main = async () => { | ||
const { api, specName } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io'); | ||
const xcmVersion = 4; | ||
const assetApi = new AssetTransferApi(api, specName, xcmVersion); | ||
let callInfo: TxResult<'call'>; | ||
try { | ||
callInfo = await assetApi.createTransferTransaction( | ||
'1002', | ||
'5HBuLJz9LdkUNseUEL6DLeVkx2bqEi6pQr8Ea7fS4bzx7i7E', | ||
['wnd'], | ||
['10000000000'], | ||
{ | ||
format: 'call', | ||
dryRunCall: true, | ||
xcmFeeAsset: 'wnd', | ||
sendersAddr: '5EJWF8s4CEoRU8nDhHBYTT6QGFGqMXTmdQdaQJVEFNrG9sKy', | ||
xcmVersion: xcmVersion, | ||
}, | ||
); | ||
|
||
console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); | ||
} catch (e) { | ||
console.error(e); | ||
throw Error(e as string); | ||
} | ||
|
||
const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); | ||
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.