Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Add examples for custom evmos Msgs #43

Closed
ducphamle2 opened this issue Jun 2, 2022 · 7 comments
Closed

Add examples for custom evmos Msgs #43

ducphamle2 opened this issue Jun 2, 2022 · 7 comments

Comments

@ducphamle2
Copy link

I cannot create a transaction for custom evmos Msgs (namely MsgConvertCoin) using Metamask & EIP712.

is it possible that MsgConvertCoin is not a legacy amino cosmos msg, and therefore when it is broadcast to the evmos network, the network cannot read its type?

Below is the log I printed for txData for the MsgConvertCoin msg in Etheremint repo:

{
  "account_number": "0",
  "chain_id": "evmos_6666-1",
  "fee": {
    "amount": [
      {
        "amount": "0",
        "denom": "oraie"
      }
    ],
    "gas": "2000000"
  },
  "memo": "foobar",
  "msgs": [
    {
      "coin": {
        "amount": "1",
        "denom": "ibc/E8734BEF4ECF225B71825BC74DE30DCFF3644EAC9778FFD4EF9F94369B6C8377"
      },
      "receiver": "0x3C5C6b570C1DA469E8B24A2E8Ed33c278bDA3222",
      "sender": "evmos1sa2qx2k8je4fp83ww5es3h6khvyd40tf752s8j"
    }
  ],
  "sequence": "1"
}

As you can see, there's no type in the msgs array. Meanwhile, if I use a legacy msg like MsgSend, it appears:

{
  "account_number": "0",
  "chain_id": "evmos_6666-1",
  "fee": {
    "amount": [
      {
        "amount": "0",
        "denom": "oraie"
      }
    ],
    "gas": "2000000"
  },
  "memo": "foobar",
  "msgs": [
    {
      "type": "cosmos-sdk/MsgSend",
      "value": {
        "amount": [
          {
            "amount": "1",
            "denom": "ibc/E8734BEF4ECF225B71825BC74DE30DCFF3644EAC9778FFD4EF9F94369B6C8377"
          }
        ],
        "from_address": "evmos1sa2qx2k8je4fp83ww5es3h6khvyd40tf752s8j",
        "to_address": "evmos1sa2qx2k8je4fp83ww5es3h6khvyd40tf752s8j"
      }
    }
  ],
  "sequence": "1"
}

Also, is there an example for creating & broadcasting a custom msg using Keplr?

It would be great if we have more examples for custom evmos Msgs & a js function or library for signing evmos transactions. Thanks!

@ducphamle2
Copy link
Author

Here's the MsgConvertCoin source code I am adding. Not sure if I did something wrong:

https://github.com/oraichain/kwtjs/blob/main/packages/transactions/src/messages/msgConvertCoin.ts

@hanchon
Copy link
Contributor

hanchon commented Jun 2, 2022

Hi, I'm finishing a PR to add the Edit validator message.

As soon as I got that ready, I'll check what is the problem with the ConvertCoin message. I usually run a test with the message that I want to include to the lib using Ethermint, something like this: https://github.com/tharsis/ethermint/blob/046cd001749c04183d6987c7baedf2788f9e039a/app/ante/utils_test.go#L258
And debug the EIP712 code to make sure that the types and encodings are correctly set.

Sorry that I don't have some easier way to add the message! I wanted to spend a week or so writing documentation to make it easier to use/collab with this lib, but I didn't have time.
If everything goes well, I'll try to at least add more examples early next week!

@ducphamle2
Copy link
Author

Hi. Thank you for your quick response.
I was able to broadcast the MsgConvertCoin & MsgConvertERC20 using Keplr.

Please take a look: a0f3560, 7dd9db8

Also, when using Keplr, we had to use signDirect & set the coinType to 60 to make it work. Hence, I think the docs should have at least an example for signing a custom message like MsgConvertCoin. I have not generalized the steps when using Keplr yet, but you can take a look at this example file: https://github.com/oraichain/cw-ide-webview/blob/test/evmos/src/components/CustomNetwork/CustomNetwork.jsx

However, I have not been able to use Metamask, so I believe I will still need your help on that. Your examples that use Metamask work fine, but not for custom messages.

@hanchon
Copy link
Contributor

hanchon commented Jun 3, 2022

Yes, you are right, the coinType 60 must be set for keplr, that will force keplr to sign using the keccak256.

I think that using Evmos(Beta) as network doesn't require it, because the coinType is already set for that network on the keplr default config, I'll add the coinType comment so it can be used on any other chain, thanks!

I remember that there was a parameter isEthereum that can be sent in the signDirect function to use the eth signing, but I don't know if that parameter is still in the keplr code.

I'll push the MsgEditValidator PR today, and use your commits to try the convertCoin message using metamask.

@ducphamle2
Copy link
Author

Sounds cool. Thanks for your help!. To anyone who's facing this similar issue while @hanchon is updating the docs, feel free to re-open this issue so we can discuss further.

@hanchon
Copy link
Contributor

hanchon commented Jun 13, 2022

@ducphamle2 This PR will enable the erc20 messages. #45 , it requires one evmos' pr to be merged in order to work correctly with eip712 evmos/evmos#677 . Next release should have everything working.
I started to add examples on the ./examples folder

@ducphamle2
Copy link
Author

@hanchon thank you for your help! This confirms my speculation that we needed to add something in the evmos repo for the messages to pass through. Again, awesome work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants