cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
636 stars 324 forks source link

Unable to sign and send a custom message #1596

Open ppoliani opened 2 weeks ago

ppoliani commented 2 weeks ago

I've been trying to sing and send a custom message using ledger. The error is the following

Error: Broadcasting transaction failed with code 4 (codespace: sdk). Log: signature verification failed; please verify account number (172), sequence (5) and chain-id (chain-1): unauthorized

Here's the code I use:

const registry = new Registry(defaultRegistryTypes)
registry.register("/chainx.vesting.MsgRelease", MsgRelease);

const aminoTypes = new AminoTypes({
  "/chainx.vesting.MsgRelease": {
    aminoType: "vesting/Release",
    toAmino: ({creator, posIndex}) => {
      return {
        creator,
        posIndex: posIndex.toString(), 
      }
    },
    fromAmino: ({creator, posIndex}) => {        
      return {
        creator,
        posIndex: BigInt(posIndex),
      }
    },
  }
});

const data = useStargateSigningClient({
  opts: {
    aminoTypes,
    registry,
  },
})
const stargate = data.data;

const message = {
  typeUrl: "/chainx.vesting.MsgRelease",
  value: MsgRelease.fromPartial({
    creator: account.data.bech32Address,
    posIndex
  }),
};
const fee = {
  amount: coins(2000, 'ustake'),
  gas: '222000',
}

const result = await stargate.signAndBroadcast(account.data.bech32Address, [message], fee);

Where

export interface MsgRelease {
  creator: string;
  posIndex: Long;
}

And here's the go struct on the chain itself

type MsgRelease struct {
    Creator  string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"`
    PosIndex uint64 `protobuf:"varint,2,opt,name=posIndex,proto3" json:"posIndex,omitempty"`
}

A few points regarding that: