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

Uncaught (in promise) Error: Broadcasting transaction failed with code 18 (codespace: sdk). Log: must contain at least one message: invalid request #1572

Open
MkMarko opened this issue Mar 17, 2024 · 4 comments

Comments

@MkMarko
Copy link

MkMarko commented Mar 17, 2024

Can someone help me or provide me with a sample document? I am testing a simple transfer function, but it keeps showing an error message and pops up KEPLR authorization transfer, but it has not been successful
Uploading 222w.png…

@MkMarko
Copy link
Author

MkMarko commented Mar 17, 2024

The transfer information is identical to that of keplr, but an error is reported

@MkMarko
Copy link
Author

MkMarko commented Mar 17, 2024

{
  "account_number": "193209",
  "chain_id": "sentinelhub-2",
  "fee": {
    "gas": "86560",
    "amount": [
      {
        "amount": "21640",
        "denom": "udvpn"
      }
    ]
  },
  "memo": "测试",
  "msgs": [
    {
      "type": "cosmos-sdk/MsgSend",
      "value": {
        "amount": [
          {
            "amount": "1000000",
            "denom": "udvpn"
          }
        ],
        "from_address": "sent1rtpugzgumc0gjvc7wn60cd869wuh00jvs7ea6a",
        "to_address": "sent1z8vnu648wh2lyuyzm2zwk6jqz9s6g26h42v2gp"
      }
    }
  ],
  "sequence": "335"
}

This is the data before signing

@MkMarko
Copy link
Author

MkMarko commented Mar 17, 2024

This is my JavaScript code

import { SigningStargateClient } from "@cosmjs/stargate";
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';

export default {
  data() {
    return {
      title: "Keplr授权",
      someObject: {}
    }
  },
  methods: {
    async run() {
            if (!window.keplr) {
            	console.warn('你没有安装keplr');
            } else {
                const chainId = "sentinelhub-2";
   
                await window.keplr.enable(chainId);
            
                const offlineSigner = window.keplr.getOfflineSigner(chainId);
         
                const accounts = await offlineSigner.getAccounts();
                
                const tendermintClient = await Tendermint34Client.connect('https://sentinel-rpc.publicnode.com:443');

    //             // Initialize the gaia api with the offline signer that is injected by Keplr extension.
                const cosmJS = new SigningStargateClient(
                        tendermintClient,
                        accounts[0].address,
                        offlineSigner);
                
                console.log(cosmJS.getAllBalances(accounts[0].address))
                
                const sendMsg = {
                  type: "cosmos-sdk/MsgSend",
                  value: {
                    from_address: accounts[0].address,
                    to_address: "sent1z8vnu648wh2lyuyzm2zwk6jqz9s6g26h42v2gp", // 收款人的地址
                    amount: [
                      {
                        denom: "udvpn", // 货币单位
                        amount: "1000000", // 转账数量,注意这是以最小单位计数的,所以这是0.001 ATOM
                      },
                    ],
                  },
                };
                
                const fee = {
                  amount: [
                    {
                      denom: "udvpn",
                      amount: "86560", // 手续费,也是以最小单位计数的,所以这是0.002 ATOM
                    },
                  ],
                  gas: "86560", // Gas,这是执行交易所需的计算资源的估计
                };
                
                const memo = "测试"; // 你可以在这里添加一些备注信息
                
                let { accountNumber, sequence } = await cosmJS.getSequence(accounts[0].address);
                
                sequence = sequence.toString();
                 accountNumber = accountNumber.toString();
                
                const signDoc = {
                  chain_id: chainId,
                  account_number: accountNumber,
                  sequence,
                  fee,
                  msgs: [sendMsg],
                  memo,
                };
                
                const { signed, signature } = await offlineSigner.sign(accounts[0].address, signDoc);
                
                           
                const signedTx = {
                  msg: [sendMsg],
                  fee,
                  memo,
                  signatures: [signature],
                };
                
                const result = await cosmJS.broadcastTx(signedTx);
                console.log(result);
        }
    }
  },
  mounted() {
    this.run();
  }
}
</script>```

@MkMarko
Copy link
Author

MkMarko commented Mar 17, 2024

I tried to transfer to Atom but was unsuccessful. After modifying it, I also failed to transfer to DVPN

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