diff --git a/packages/page-js/src/snippets/extrinsics-examples.ts b/packages/page-js/src/snippets/extrinsics-examples.ts index 7ace604fb0e7..c225bafa3840 100644 --- a/packages/page-js/src/snippets/extrinsics-examples.ts +++ b/packages/page-js/src/snippets/extrinsics-examples.ts @@ -34,3 +34,22 @@ await transfer.signAndSend(ALICE, ({ events = [], status }) => { }); });` }; + +export const daSubmitDataCall: Snippet = { + value: 'daSubmitDataCall', + text: 'Call Submit Data and listen to events', + label: { color: 'grey', children: 'Extrinsics', size: 'tiny' }, + code: `// You need to be connected to a development chain for this example to work. +const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; + +const data = "Hello World"; +const submitData = api.tx.dataAvailability.submitData(data); + +// Sign and Send the transaction +await submitData.signAndSend(ALICE, ({ events = [], status }) => { + console.log(status); + events.forEach(({ phase, event: { data, method, section } }) => { + console.log(phase.toString() + ' : ' + section + '.' + method + ' ' + data.toString()); + }); +});` +}; diff --git a/packages/page-js/src/snippets/index.ts b/packages/page-js/src/snippets/index.ts index 033f8f278852..6e059f846098 100644 --- a/packages/page-js/src/snippets/index.ts +++ b/packages/page-js/src/snippets/index.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { constsStakingParameters } from './consts-examples.js'; -import { extrinsicMakeTransfer } from './extrinsics-examples.js'; +import { daSubmitDataCall, extrinsicMakeTransfer } from './extrinsics-examples.js'; import { rpcNetworkAuthoring, rpcNewHead, rpcQueryState, rpcSysthemInfo } from './rpc-examples.js'; import { storageGetInfo, storageKeys, storageListenToBalanceChange, storageListenToMultipleBalancesChange, storageRetrieveInfoOnQueryKeys, storageSystemEvents } from './storage-examples.js'; @@ -20,5 +20,6 @@ export const allSnippets = [ storageRetrieveInfoOnQueryKeys, storageKeys, constsStakingParameters, - extrinsicMakeTransfer + extrinsicMakeTransfer, + daSubmitDataCall ] as const;