polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 354 forks source link

1010:Invalid Transaction:Transaction has a bad signature #5907

Closed Wangmmx closed 4 months ago

Wangmmx commented 5 months ago

I got this error when transfer KSM with the @polkadot/api v11.2.1 lib, and sign with @polkadot/types v11.2.1

    let transfer = api.tx.balances.transferAllowDeath(BOB, 1);
    let signedHex = transfer.sign(pair, {era:0, runtimeVersion: { specVersion:runtime.specVersion, transactionVersion:runtime.transactionVersion}}).toHex()
//broadcast the signedHex

And pair can be any random one, I had never got this error before, could you please help me with this? Thanks a lot

csquan commented 5 months ago

same too,any solutions?

TarikGul commented 5 months ago

On Kusama the CheckMetadataHash signed extension was added which acted as a breaking change. Support for it has been added to the api in 11.1.1 - That being said, I have been able to successfully send transactions in Kusama, but I can double check using .sign

TarikGul commented 5 months ago

Try adding mode: 0 to the signerOptions.

csquan commented 5 months ago

how to adding mode: 0 to the signerOptions?

csquan commented 5 months ago

seems add field metadataHash and mode in payload,but I do not test it .

TarikGul commented 5 months ago

Yea you just need to add mode: 0 to the signerOptions which is just a options object at the end of sign

malingzhao commented 5 months ago
const provider = new WsProvider('wss://kusama-rpc.polkadot.io');
const api = await ApiPromise.create({ provider });
console.log("the address is =========")
console.log(sender.address)
// Estimate the fees as RuntimeDispatchInfo using the signer
const info = await api.tx.balances.transferAllowDeath("F7B8Hd9LrEyeLFdcXnf81NcNH75W4UobQ81viZBVTVFsRhK", 1).signAndSend(sender, {mode:0})

v11.3.1 how does the err resolve

Wangmmx commented 5 months ago

I have no idea why got this error after adding the mode:0 to sign function, at last I solved it without using this sdk, create it offline and sign it in local environment, and also the signerPayload need add {mode:0, metadataHash:''}, and send it online

Or I use the other function can success too, after build the transfer, then

  await transfer.signAndSend(pair, {mode: 0}).then(function (ret) {
      console.log(ret)
   })
malingzhao commented 5 months ago

ok

polkadot-js-bot commented 4 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.