Open MkMarko opened 8 months ago
The transfer information is identical to that of keplr, but an error is reported
{
"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
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>```
I tried to transfer to Atom but was unsuccessful. After modifying it, I also failed to transfer to DVPN
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…]()