How should custom AminoTypes be written?
See original GitHub issueI’m using @cosmjs/ Stargate to plug into Osmosis dex
const aminoTypes = new AminoTypes({
"What do I write here????": {
aminoType: "osmosis/gamm/swap-exact-amount-in",
toAmino: (data) => {
debugger
return data
},
fromAmino: (data) => {
debugger
return data
},
},
});
The complete code:
async swap () {
const aminoTypes = new AminoTypes({
"/osmosis.gamm.swap-exact-amount-in": {
aminoType: "osmosis/gamm/swap-exact-amount-in",
toAmino: (data) => {
debugger
return data
},
fromAmino: (data) => {
debugger
return data
},
},
});
const offlineSigner = window.keplr.getOfflineSignerOnlyAmino(this.chainId);
let sddf = this.accounts = await offlineSigner.getAccounts();
const client = this.client = await SigningStargateClient.connectWithSigner(
network,
offlineSigner,
{
aminoTypes
}
);
const address = this.accounts[0].address
const msgAny = {
"typeUrl": "/osmosis.gamm.swap-exact-amount-in",
"value": {
"sender": address,
"routes": [
{
"poolId": "7",
"tokenOutDenom": "uosmo"
}
],
"tokenIn": {
"denom": "ibc/7C4D60AA95E5A7558B0A364860979CA34B7FF8AAF255B87AF9E879374470CEC0",
"amount": "21429239"
},
"tokenOutMinAmount": "201687"
}
}
const fee = {
amount: [],
gas: "100000", // 180k
};
const memo = "备忘录211";
try {
const result = await this.client.signAndBroadcast(
address,
[msgAny],
fee,
memo
);
assertIsDeliverTxSuccess(result);
if (result.code !== undefined &&
result.code !== 0) {
alert("Failed to send tx: " + result.log || result.rawLog);
} else {
alert("Succeed to send tx:" + result.transactionHash);
}
} catch (error) {
let sd = error
debugger
alert("Failed to send tx:" + error.message);
}
}
Error
Error: Unregistered type url: /osmosis.gamm.swap-exact-amount-in\n at Registry.lookupTypeWithError (webpack-internal:///./node_modules/@cosmjs/proto-signing/build/registry.js:74:19)\n at Registry.encode (webpack-internal:///./node_modules/@cosmjs/proto-signing/build/registry.js:90:27)\n at Registry.encodeAsAny (webpack-internal:///./node_modules/@cosmjs/proto-signing/build/registry.js:99:34)\n at eval (webpack-internal:///./node_modules/@cosmjs/proto-signing/build/registry.js:106:77)\n at Array.map (<anonymous>)\n at Registry.encodeTxBody (webpack-internal:///./node_modules/@cosmjs/proto-signing/build/registry.js:106:55)\n at Registry.encode (webpack-internal:///./node_modules/@cosmjs/proto-signing/build/registry.js:88:25)\n at SigningStargateClient.signAmino (webpack-internal:///./node_modules/@cosmjs/stargate/build/signingstargateclient.js:218:49)\n at async SigningStargateClient.signAndBroadcast (webpack-internal:///./node_modules/@cosmjs/stargate/build/signingstargateclient.js:167:23)"
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
https://www.npmjs.com/package/osmojs
Closing as there’s 3 solutions provided. Please open again if you’re still running into issues. Thanks!