Trying to form a batchAll command that carries out 2 activities:
- Deposit 1 GLMR from wallet1 to wallet2
- Cancel tokens' delegation revoke
When I try to sign the batch with wallet1 (batchAllExtrinsic.sign) I get:
TypeError: Cannot read properties of undefined (reading 'specVersion')
My async main function looks as follows:
const wsProvider = new WsProvider("wss://wss.api.moonbeam.network");
const api = await ApiPromise.create({
provider: wsProvider,
types: {
// Add any custom types here
AccountId: "EthereumAccountId",
Address: "AccountId",
Balance: "u128",
RefCount: "u8",
LookupSource: "AccountId"
}
});
// Wait for the api to be ready
await api.isReady;
const keyringECDSA = new Keyring({ type: "ethereum" });
const feesWallet = keyringECDSA.addFromUri(PRIVATE_KEY_FEE_WALLET);
const stakedWallet = keyringECDSA.addFromUri(PRIVATE_KEY_STAKED_WALLET);
const amount = 1_000_000_000_000_000;
// Create the batchAll extrinsic with the staking actions
const batchAllExtrinsic = api.tx.utility.batchAll([
api.tx.balances.transfer(feesWalletH160, amount),
api.tx.parachainStaking.cancelDelegationRequest(addressCollator3)
]);
// Get the latest block hash
const latestBlockHash = await api.rpc.chain.getFinalizedHead();
// Get the block hash and nonce for signing
const blockHash = await api.rpc.chain.getBlock(latestBlockHash);
const { nonce } = await api.query.system.account(feesWallet.address);
const genesisHash = api.genesisHash;
const specVersion = api.runtimeVersion.specVersion;
const transactionVersion = api.runtimeVersion.transactionVersion;
// Sign the batch call using both wallets
batchAllExtrinsic.sign(feesWallet, { blockHash, nonce, genesisHash, specVersion,transactionVersion});
batchAllExtrinsic.addSignature(stakedWallet.address, stakedWallet.sign(batchAllExtrinsic));
// Send the batch call
batchAllExtrinsic.send(({ status }) => {
if (status.isInBlock) {
console.log(`Transaction included in block ${status.asInBlock}`);
} else if (status.isFinalized) {
console.log(`Transaction finalized in block ${status.asFinalized}`);
process.exit(0);
}
});
Tried various workarounds (setting api setRuntimeVersion, changing batchAll to batch, replacing the txs with different methods) but nothing seems to solve this error. Your help will be strongly appreciated