2

I'm working on a project using an EVM-compatible Substrate blockchain. I am encountering problems when trying to call functions on this Substrate instance.

Here's the function used to sign and send transactions to Substrate pallets:

async _signAndSendTransaction(account, tx) {
    try {
        const { cryptoWaitReady, mnemonicGenerate } = require('@polkadot/util-crypto');
        const { Keyring } = require('@polkadot/keyring');

        await cryptoWaitReady();

        const keyring = new Keyring({ type: 'sr25519' });
        const senderAccount = keyring.addFromUri(account.mnemonic); 
        console.log(senderAccount.address)
        // const nonce = await this.api.rpc.system.accountNextIndex(account.address);
        const signedTx = await tx.signAsync(senderAccount);
        const hash = await signedTx.send();

        return hash.toHex();
    } catch (error) {
        console.log(error.message)
    }
}

For wallet connection, I'm utilizing Metamask, and the EVM-based address that I use to call the functions is 0x6C45Ada1e3bE236D2667b4f2828888991263A4dD.

However, when I log the following lines:

const senderAccount = keyring.addFromUri(account.mnemonic);
console.log(senderAccount.address)

I get a different address: 5E4bnwDsLFpe28WtyYVva5joGxhDUQ7M1Gzd4ndWCY52R21e.

Finally, I encounter this error message:

2023-07-02 00:15:42 RPC-CORE: submitExtrinsic(extrinsic: Extrinsic): Hash:: 1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low 1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low

I'd appreciate any guidance on how I might solve this issue. Thanks in advance for your help.

1 Answer 1

0

The account you have in Metamask is different as the one you are getting with your mnemonic phrase in your code snippet. And you have no funds to pay fees in the account that is sending the extrinsic.

You can check this using the subkey tool:

subkey inspect "your-mnemonic"

Then calculate the Eth Address of this account with this guide: How to convert a Substrate address to an Etherum address?.

If you are building on a Moonbeam chain, this guide: How to use Polkadot.js Apps to Interact with Moonbeam.

Edited

When you use your mnemonic to recover the keys in Metamask or in an EVM chain it results in a public_key different to the one you get on Substrate, due the fact that Substrate uses different crypto system than Ethereum's More information, check this previous issue on StackExchange when is better explained in the answers: Private key for EVM Frontier.

Parachains has different approaches to this problem, for example in Acala to get the same account on Metamask in order to see for example the balance you have to bind your MetaMask account to your Substrate account.

Check this guide from the Acala Documentation.

Moonbeam has a unified accounts system, which replaces the default Substrate-style accounts and keys with Ethereum-style accounts and keys. As a result, you can interact with your Moonbeam account using MetaMask and Ethereum tools you may already be familiar with, such as Remix and Hardhat.

7
  • 1
    Thanks , now i want know , what should i do for balance?
    – Mr Coder
    Jul 3, 2023 at 9:24
  • check the query balances using RPC guide for EVM accounts: docs.substrate.io/tutorials/integrate-with-tools/…
    – Alex Bean
    Jul 3, 2023 at 9:44
  • If you have any other specific doubt about the balances, is better to mark this as accepted and open another Question with the specific doubt. This might help the community when looking for similar problems
    – Alex Bean
    Jul 3, 2023 at 9:46
  • I have ran thos command subkey inspect "your-mnemonic" but the account Id is not same with the metamask address .
    – Mr Coder
    Jul 3, 2023 at 10:27
  • Updated answer, hopefully a bit more clear now with examples
    – Alex Bean
    Jul 3, 2023 at 18:52

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.