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

Terra MsgExecuteContract #902

Closed
AlexBHarley opened this issue Oct 12, 2021 · 4 comments
Closed

Terra MsgExecuteContract #902

AlexBHarley opened this issue Oct 12, 2021 · 4 comments

Comments

@AlexBHarley
Copy link
Contributor

I believe I should be able to use this library for constructing Terra compatible transactions instead of Terra.js or Anchor.js, is that correct?

If so, I need a little help creating a simple token transfer message, not too sure where things are going wrong when trying to transfer aUST tokens... Normal UST or LUNA transfers work great via the writer.sendTokens method, I guess I'm not fully understanding the WASM interaction.

import { coins } from '@cosmjs/amino';
import { cosmWasmTypes } from '@cosmjs/cosmwasm-stargate';
import { toUtf8 } from '@cosmjs/encoding';
import { AminoTypes, SigningStargateClient } from '@cosmjs/stargate';
import {
  MsgExecuteContract
} from 'cosmjs-types/cosmwasm/wasm/v1/tx';


async function main() {
  const writer = await SigningStargateClient.connectWithSigner(...);
  const from = '';
  const to = '';
  const contract = 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu';
  const amount = '100000';

  const msg: MsgExecuteContract = {
    sender: from,
    contract,
    msg: toUtf8(
      JSON.stringify({
        transfer: {
          recipient: to,
          amount,
        },
      })
    ),
    funds: coins(parseInt(amount), 'aUST'),
  };

  const a = new AminoTypes({
    additions: cosmWasmTypes,
  });

  const aminoMsg = a.toAmino({
    typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
    value: msg,
  });

  const encoded = a.fromAmino(aminoMsg);
  console.log(await writer.signAndBroadcast(from, [encoded], {
    amount: [],
    gas: '100000',
  }));
}

The error I get back is Unregistered type url: /cosmwasm.wasm.v1.MsgExecuteContract, I believe this is because after poking around Terra a little I find that in their Codec file they register was/MsgExecuteContract, am I on the right track?

@webmaster128
Copy link
Member

I believe I should be able to use this library for constructing Terra compatible transactions instead of Terra.js or Anchor.js, is that correct?

Unfortunately no. Terra decided to make all kinds of incompatible changes to CosmWasm (especially x/wasm) interfaces that are impossible to support for us. There might be cases where things work by accident, but it would be a frustrating experience overall. Also note Terra upgraded to Cosmos SDK 0.44 which CosmJS does not yet support but will probably do soonish.

@webmaster128
Copy link
Member

webmaster128 commented Oct 12, 2021

Well, okay, one thing that could potentially work is 1. CosmJS support for SDK 0.44 and then 2. a Terra specific fork of @cosmjs/cosmwasm-stargate with all proto types generated from the Terra type definitions instead of using cosmjs-types. It would require significat talent and time but it can probably be done.

@cryptoJ715
Copy link

This is my transaction data via keplr
{
"txBody": {
"messages": [
{
"sender": "terra1ptywzlfy47c338j62ax7acs8rjvqems0ptv0gv",
"contract": "terra1v93ll6kqp33unukuwls3pslquehnazudu653au",
"msg": "eyJzd2FwIjp7Im1heF9zcHJlYWQiOiIwLjA1Iiwib2ZmZXJfYXNzZXQiOnsiaW5mbyI6eyJuYXRpdmVfdG9rZW4iOnsiZGVub20iOiJ1bHVuYSJ9fSwiYW1vdW50IjoiMTAwMDAifSwiYmVsaWVmX3ByaWNlIjoiMS4wMDIwMDQwMDgwMTYwMzIifX0="
},
{
"sender": "terra1ptywzlfy47c338j62ax7acs8rjvqems0ptv0gv",
"contract": "terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp",
"msg": "eyJzZW5kIjp7Im1zZyI6ImV5SmtaWEJ2YzJsMFgyTnZiR3hoZEdWeVlXd2lPbnQ5ZlE9PSIsImFtb3VudCI6Ijk0ODEiLCJjb250cmFjdCI6InRlcnJhMXB0anAydmZqcndoMGowZmFqOXI2a2F0bTY0MGtnanhud3dxOWtuIn19"
},
{
"sender": "terra1ptywzlfy47c338j62ax7acs8rjvqems0ptv0gv",
"contract": "terra1tmnqgvg567ypvsvk6rwsga3srp7e3lg6u0elp8",
"msg": "eyJsb2NrX2NvbGxhdGVyYWwiOnsiY29sbGF0ZXJhbHMiOltbInRlcnJhMWtjODdtdTQ2MGZ3a3F0ZTI5cnF1aDRoYzIwbTU0Znh3dHN4N2dwIiwiOTQ4MSJdXX19"
},
{
"sender": "terra1ptywzlfy47c338j62ax7acs8rjvqems0ptv0gv",
"contract": "terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s",
"msg": "eyJib3Jyb3dfc3RhYmxlIjp7ImJvcnJvd19hbW91bnQiOiI2NTMwMDAifX0="
},
{
"sender": "terra1ptywzlfy47c338j62ax7acs8rjvqems0ptv0gv",
"contract": "terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s",
"msg": "eyJib3Jyb3dfc3RhYmxlIjp7ImJvcnJvd19hbW91bnQiOiIxMDAwIiwidG8iOiJ0ZXJyYTFsa2tyNmQzcGRlNmQ3MDBhcHFzbGFta2twdmZ0cGxnNm1qcnp4OSJ9fQ=="
},
{
"sender": "terra1ptywzlfy47c338j62ax7acs8rjvqems0ptv0gv",
"contract": "terra1sgu6yca6yjk0a34l86u6ju4apjcd6refwuhgzv",
"msg": "eyJzd2FwIjp7Im1heF9zcHJlYWQiOiIwLjA1Iiwib2ZmZXJfYXNzZXQiOnsiaW5mbyI6eyJuYXRpdmVfdG9rZW4iOnsiZGVub20iOiJ1dXNkIn19LCJhbW91bnQiOiI2NTMwMDAifSwiYmVsaWVmX3ByaWNlIjoiMTA5LjY1NTc1MTQ2OTM1MzQ5In19"
},
{
"sender": "terra1ptywzlfy47c338j62ax7acs8rjvqems0ptv0gv",
"contract": "terra1tus5ec9qsdht8dapq9ldfnsf8eehnfmwvsut83",
"msg": "eyJzd2FwIjp7Im1heF9zcHJlYWQiOiIwLjA1Iiwib2ZmZXJfYXNzZXQiOnsiaW5mbyI6eyJuYXRpdmVfdG9rZW4iOnsiZGVub20iOiJ1bHVuYSJ9fSwiYW1vdW50IjoiNTgwNiJ9LCJiZWxpZWZfcHJpY2UiOiIwLjAwMTA1NTM0OTUwMDQ1Mzk2NyJ9fQ=="
}
],
"memo": "Borrow"
},
"authInfo": {
"signerInfos": [
{
"publicKey": {
"type_url": "/cosmos.crypto.secp256k1.PubKey",
"value": "CiECs8rBpq/BtzCLHi6H/Su4fCPb0HKNSRmRD7LiNLwDGiU="
},
"modeInfo": {
"single": {
"mode": "SIGN_MODE_DIRECT"
}
}
}
],
"fee": {
"amount": [
{
"denom": "uluna",
"amount": "3000"
}
],
"gasLimit": "200000"
}
},
"chainId": "columbus-5",
"accountNumber": "3773033"
}

but I get this error : Log: unable to resolve type URL /cosmwasm.wasm.v1.MsgExecuteContract: tx parse error

How can I fix this error?

@AlexBHarley
Copy link
Contributor Author

Closing this, for Terra we just use Terra.js

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

3 participants