-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for Fee Preferences and proxy extrinsic which is a fpass …
…proxy call (#20) * Add example for Fee Preferences and proxy extrinsic which is a fpass proxy call Co-authored-by: Ken Vu <[email protected]>
- Loading branch information
1 parent
fff0534
commit 95f709b
Showing
2 changed files
with
71 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
examples/substrate/use-feeProxy/src/feeProxyWithProxyExtrinsic.ts
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 @@ | ||
import { collectArgs } from "@trne/utils/collectArgs"; | ||
import { createKeyring } from "@trne/utils/createKeyring"; | ||
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents"; | ||
import { getChainApi } from "@trne/utils/getChainApi"; | ||
import { sendExtrinsic } from "@trne/utils/sendExtrinsic"; | ||
import assert from "assert"; | ||
import { cleanEnv, str } from "envalid"; | ||
|
||
const argv = collectArgs(); | ||
|
||
const env = cleanEnv(process.env, { | ||
CALLER_PRIVATE_KEY: str(), // private key of extrinsic caller | ||
}); | ||
|
||
// This example assumes, there is liquidity pool for paymentAsset AND XrpAsset (100,000,000,000 & 100,000,000,000) | ||
// Also assumes, that the futurepassAddress has payment asset. | ||
export async function main() { | ||
assert("paymentAsset" in argv, "Payment asset ID is required"); | ||
|
||
const api = await getChainApi("porcini"); | ||
const caller = createKeyring(env.CALLER_PRIVATE_KEY); | ||
const fpassAddress = (await api.query.futurepass.holders(caller.address)).toString(); | ||
const { paymentAsset } = argv as unknown as { paymentAsset: number }; | ||
|
||
// can be any extrinsic, using `system.remarkWithEvent` for simplicity | ||
const innerCall = api.tx.system.remarkWithEvent("Hello World"); | ||
|
||
const proxyExtrinsic = api.tx.futurepass.proxyExtrinsic(fpassAddress, innerCall); | ||
const maxPayment = 1000000; | ||
const feeProxiedCall = api.tx.feeProxy.callWithFeePreferences( | ||
paymentAsset, | ||
maxPayment, | ||
proxyExtrinsic | ||
); | ||
const { result } = await sendExtrinsic(feeProxiedCall, caller, { | ||
log: console, | ||
}); | ||
|
||
const [proxyEvent, remarkEvent] = filterExtrinsicEvents(result.events, [ | ||
"FeeProxy.CallWithFeePreferences", | ||
// depending on what extrinsic call you have, filter out the right event here | ||
"System.Remarked", | ||
]); | ||
console.log("Extrinsic Result", { | ||
proxy: proxyEvent.toJSON(), | ||
remark: remarkEvent.toJSON(), | ||
}); | ||
|
||
await api.disconnect(); | ||
} | ||
|
||
main(); |