Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polkadot API Transfer event Nonce issue when using api.query.system.account #476

Open
Dante9988 opened this issue Jun 25, 2024 · 0 comments

Comments

@Dante9988
Copy link

Description: When getting a nonce by following doc https://polkadot.js.org/docs/api/examples/promise/transfer-events
current nonce is incorrect and replies with error message: VEC: Unable to decode on index 0 createType(Lookup0):: Unknown type passed to AccountId constructor, found typeof object RPC-CORE: queryStorageAt(keys: Vec<StorageKey>, at?: BlockHash): Vec<StorageChangeSet>:: createType(Vec<StorageKey>):: createType(Lookup0):: Unknown type passed to AccountId constructor, found typeof object

Better way to get nonce is this: let currentNonce = (await api.rpc.system.accountNextIndex(baseAccount.address)).toBigInt();

When sending txn to substrate network, following structure fits the best:

let currentNonce = (await api.rpc.system.accountNextIndex(baseAccount.address)).toBigInt();

        const transferExtrinsic = api.tx.balances.transfer(transfers.recipient, transfers.amount);

        const hash = await new Promise<string>((resolve, reject) => {
            transferExtrinsic
                .signAndSend(baseAccount, { nonce: currentNonce }, ({ status, dispatchError }) => {
                    if (status.isInBlock || status.isFinalized) {
                        const hash = status.isInBlock ? status.asInBlock.toString() : status.asFinalized.toString();
                        console.log(`Transaction included in block: ${hash}`);
                        if (!dispatchError) {
                            resolve(hash);
                        } else {
                            console.error('Transaction failed with dispatch error:', dispatchError.toString());
                            reject(new Error('Transaction failed with dispatch error'));
                        }
                    }
                }).catch(reject);
        });

Polkadot API doc should be updated appropriately as per ^10.11.2 version

@Dante9988 Dante9988 changed the title Polkadot API Transfer event Nonce issue Polkadot API Transfer event Nonce issue when using api.query.system Jun 25, 2024
@Dante9988 Dante9988 changed the title Polkadot API Transfer event Nonce issue when using api.query.system Polkadot API Transfer event Nonce issue when using api.query.system.account Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant