1

I want to create a nomination pool on a substrate based chain, I am using polkadot api, this is what I have managed to write till now

const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');

async function createNominationPool() {
  // Define the WebSocket provider (use a Polkadot node endpoint)
  const wsProvider = new WsProvider('wss://goldberg.avail.tools/ws');

  // Create the API instance
  const api = await ApiPromise.create({ provider: wsProvider });

  // Create a keyring instance
  const keyring = new Keyring({ type: 'sr25519' });

  // Add your account to the keyring (replace 'YOUR_SEED_PHRASE' with your seed phrase)
  const account = keyring.addFromUri('I cannot tell you this I said NO why you still reading');

  // Define the parameters for the nomination pool (adjust as needed)
  const initialBalance = 100000000000; // Set the initial balance (in smallest unit, e.g., Plancks for Polkadot)
  const rootAccount = account.address;  // Set the root account of the pool
  const nominatorAccount = account.address; // Set the nominator account of the pool

  // Create the nomination pool
  const tx = api.tx.nominationPools.create(initialBalance, rootAccount, nominatorAccount, account.address);

  // Sign and send the transaction
  const hash = await tx.signAndSend(account);

  // Log the transaction hash
  console.log(`Created nomination pool with transaction hash: ${hash.toString()}`);
}

createNominationPool().catch(console.error);

I tried running it, it gives a runtime WASM error, but doesnt tell me what is really wrong

instruction executed
WASM backtrace:
error while executing at wasm backtrace:
    0: 0x2c59af - <unknown>!rust_begin_unwind
    1: 0x7775 - <unknown>!core::panicking::panic_fmt::h7a368385936888dc
    2: 0x2812fd - <unknown>!TaggedTransactionQueue_validate_transaction: RuntimeApi, Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed\nWASM backtrace:\nerror while executing at wasm backtrace:\n    0: 0x2c59af - <unknown>!rust_begin_unwind\n    1: 0x7775 - <unknown>!core::pa…
RpcError: 1002: Verification Error: Runtime error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
WASM backtrace:
error while executing at wasm backtrace:
    0: 0x2c59af - <unknown>!rust_begin_unwind
    1: 0x7775 - <unknown>!core::panicking::panic_fmt::h7a368385936888dc
    2: 0x2812fd - <unknown>!TaggedTransactionQueue_validate_transaction: RuntimeApi, Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed\nWASM backtrace:\nerror while executing at wasm backtrace:\n    0: 0x2c59af - <unknown>!rust_begin_unwind\n    1: 0x7775 - <unknown>!core::pa…

Any help to resolve this error or suggesting a new method to do this would be appreciated, thanks !

1 Answer 1

0

You need to retrieve and capture the error the extrinsic is getting. Check this example in the PolkadotJS documentation: How do I get the decoded enum for an ExtrinsicFailed event?

const hash = await tx.signAndSend(account, ({dispatchError }) => {
 if (dispatchError) {
      if (dispatchError.isModule) {
        // for module errors, we have the section indexed, lookup
        const decoded = api.registry.findMetaError(dispatchError.asModule);
        const { docs, name, section } = decoded;

        console.log(`${section}.${name}: ${docs.join(' ')}`);
      } else {
        // Other, CannotLookup, BadOrigin, no extra info
        console.log(dispatchError.toString());
      }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.