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

[HELP] Wasm Precompile Execute Issue #2103

Closed
hsnice16 opened this issue Mar 16, 2025 · 4 comments
Closed

[HELP] Wasm Precompile Execute Issue #2103

hsnice16 opened this issue Mar 16, 2025 · 4 comments

Comments

@hsnice16
Copy link

I have created a CosmWasm contract for the flip coin game, and have deployed it on the atlantic-2 chain. Now, I was using the Wasm precompile to use the deployed contract. But I am running into the following issue

Uncaught (in promise) Error: missing revert data (action="estimateGas", data=null, reason=null, transaction={ "data": "0x44d227ae000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000003e73656931346c727a6e71636564796666667375657273367137393474747635347a61396e657939356a6477647371776674776676636b6c7179786b6b757a0000000000000000000000000000000000000000000000000000000000000000001a7b22666c6970223a7b2269735f68656164223a66616c73657d7d00000000000000000000000000000000000000000000000000000000000000000000000000235b7b22616d6f756e74223a313030303030302c2264656e6f6d223a2275736569227d5d0000000000000000000000000000000000000000000000000000000000", "from": "0x52A2D9beAcd14eF7281c1c4413ad76d331e901aC", "to": "0x0000000000000000000000000000000000001002" }, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.13.5)

I am not sure if this is a known issue, or not, so it would have been nice if someone could help.
Also, not sure if this is the right repository to raise this issue, so sorry if that's not.

--

This is the function I am using

export async function flip(
  contract: Contract | undefined,
  isHead: boolean,
  wager: number
) {
  if (!contract) {
    return;
  }

  const executeMsg = { flip: { is_head: isHead } };
  const executeResponse = await contract.execute(
    CW_FLIP_COIN_CONTRACT,
    toUtf8Bytes(JSON.stringify(executeMsg)),
    toUtf8Bytes(
      JSON.stringify([{ amount: wager * 10 ** CW_DECIMALS, denom: "usei" }])
    )
  );

  console.log("executeResponse-before", executeResponse);
  await executeResponse.wait();
  console.log("executeResponse-after", executeResponse);
}

And, these are the constants

export const CW_DECIMALS = 6;

export const CW_FLIP_COIN_CONTRACT =
  "sei14lrznqcedyfffsuers6q794ttv54za9ney95jdwdsqwftwfvcklqyxkkuz";

export const WASM_PRECOMPILE_ADDRESS: `0x${string}` =
  "0x0000000000000000000000000000000000001002";

This is the ethers version

    "ethers": "^6.13.5",

--

This is the project if anyone needs more info - https://github.com/hsnice16/cw-flip-coin-ui/blob/main/src/component/Input.tsx#L65

--

Let me know if needs any other info

@codebycarson
Copy link
Contributor

Hey, could it be that you haven't given this execute enough gas to execute? If it gives you a transaction hash, try using "cast" from the Foundry CLI on the 0x hash to see more info about the tx and its run.

I see that you're using CW for the VM, but EVM for the RPC interface. Is it possible to either a.) use EVM for the contract or B.) use the cosmos RPC interface to call the wasm contract through a standard cosmos tx msg.

@hsnice16
Copy link
Author

@codebycarson

Thanks for replying!

could it be that you haven't given this execute enough gas to execute?

I tried this. Earlier when I was trying to pass gasLimit in an object as the fourth argument in the execute method, it was not working, but this time it worked.

I see that you're using CW for the VM, but EVM for the RPC interface. Is it possible to either a.) use EVM for the contract or B.) use the cosmos RPC interface to call the wasm contract through a standard cosmos tx msg.

I have written a CosmWasm contract for a coin flip game, and on Discord, I found out that the Pointer Contract only exists for tokens, so the only option to access the contract on EVM was the Wasm Precompile.

@hsnice16
Copy link
Author

hsnice16 commented Mar 18, 2025

One thing I noticed and having issues with, is that we can't use events with Wasm Precompile.
I was doing contract.on(..., () => {...})

Like, this is a transaction that I did - https://seitrace.com/tx/0x016c3491e500c7740c1543666afbbdc3bf7e7b4680a0c54e3def64da2d405d7b?chain=atlantic-2

You can see there is a flip_completed event in the associated Cosmos transaction hash, but nothing is mentioned in the EVM transaction details. I also can't see anything about the events in the codebase, precompiles/wasmd/wasmd.go.

This is how I am doing the transaction - https://github.com/hsnice16/cw-flip-coin-ui/blob/main/src/util/contract.ts#L105

--

Am I thinking in the right direction about missing events?
Any idea how can I do this? I might be wrong, but don't think there is a way to listen for events on the CosmWasm side.

--

I had also taken a screenshot if this helps.

Image

--

p.s. I was checking if I can listen for events on the CosmWasm side, It seems like if we have a web socket for the RPC, we can do that, but I didn't find it anywhere in the doc.

@hsnice16
Copy link
Author

Thanks for the help!

I figured out how we can get events on the CosmWasm and have completed this project.
If anyone checking this later, and wants to know what I did, can check this - https://github.com/hsnice16/cw-flip-coin-ui/blob/main/src/context/SocketContext.tsx#L101

And, if anyone wants to play 😅 - https://flipsei.vercel.app/

I am closing this issue.

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

2 participants