Error: Broadcasting transaction failed with code 8

I got this error when trying to send tokens (uscrt) using cosmJs sdk’s stargate client.
Error: Broadcasting transaction failed with code 8 (codespace: sdk). Log: pubKey does not match signer address secret13u3a5t44aqd3j3dn4hn3rt0kljr7c4t2eg55qe with signer index: 0: invalid pubkey

My code snippet:
const cosmos_client = await SigningStargateClient.connectWithSigner(
rpcEndpoint,
wallet,
);
const result = await cosmos_client.sendTokens(
‘secret13u3a5t44aqd3j3dn4hn3rt0kljr7c4t2eg55qe’,
recipient,
[{denom: ‘uscrt’, amount: ‘300000’}],
{
amount: [{denom: ‘uscrt’, amount: ‘2500’}],
gas: ‘200000’,
},
);

Where’s wallet coming from? The error essentially says that wallet doesn’t hold the private key of secret13u3a5t44aqd3j3dn4hn3rt0kljr7c4t2eg55qe

I created wallet in this way:
let mn =‘together carpet board direct social book photo veteran three tenant arrest mushroom’;
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mn, {
prefix: ‘secret’,
});

And are you sure that it corresponds to secret13u3a5t44aqd3j3dn4hn3rt0kljr7c4t2eg55qe?

I think so.

const [firstAccount] = await wallet.getAccounts();
console.log(‘Wallet:’, wallet);
console.log(‘Account:’, firstAccount);
console.log(‘Account Address:’, firstAccount.address);

Console LOG :
Wallet: {“accounts”: [{“hdPath”: [Array], “prefix”: “secret”}], “secret”: {“data”: “together carpet board direct social book photo veteran three tenant arrest mushroom”}, “seed”: [23, 156, 141, 170, 138, 252, 223, 66, 252, 69, 175, 90, 77, 242, 180, 166, 150, 138, 29, 13, 70, 76, 125, 210, 156, 184, 249, 105, 241, 173, 150, 188, 99, 249, 92, 140, 95, 185, 84, 254, 21, 109, 107, 253, 146, 32, 171, 236, 167, 132, 135, 86, 17, 159, 204, 37, 8, 132, 79, 54, 248, 111, 18, 178]}

Account: {“address”: “secret13u3a5t44aqd3j3dn4hn3rt0kljr7c4t2eg55qe”, “algo”: “secp256k1”, “pubkey”: [2, 121, 123, 246, 57, 54, 165, 230, 75, 84, 165, 11, 25, 161, 130, 71, 157, 213, 57, 206, 122, 38, 90, 231, 233, 91, 137, 57, 221, 39, 103, 100, 91]}

Account Address: secret13u3a5t44aqd3j3dn4hn3rt0kljr7c4t2eg55qe

Can you try this?:

const cosmos_client = await SigningStargateClient.connectWithSigner(
  rpcEndpoint,
  wallet,
  { prefix: 'secret' }
);

Yeah, I have checked it. But got same error.

One thing to inform you that I am using it in react native environment.
I can retrieve chainId, height and can check balance as well.
And my rpc endpoint is:
https://testnet-rpc.roninventures.io’;

First you can try another RPC endpoint, ronin was recently removed from the api-registry

And then weirdly, that mnemonic works with a Secret.JS wallet, but I failed to import it with cosmjs with this sandbox app, and then I tried Keplr and that failed with checksum error too.
Maybe we used different versions of cosmjs, and I don’t know how you got the mnemonic, but I get invalid checksum errors for it.

BTW, even if the code in the sandbox works, of course the addresses will differ until the hdpaths is correctly set. I just tried it for sanity and found it weird that secret.js Wallet imports it but not cosmjs, maybe related to your issue.