I get "execution reverted" error when calling the KlaySwap Protocol smart contract

Hello everyone!

I am trying to run a smart contract via the Klaytn’s JSON-RPC APIs (klay_call method) and I get this error message:

{'code': -32000, 'message': 'evm: execution reverted'}

I cannot find any information about this error in Klaytn documentation or anywhere on the internet so this is why I’m asking here.

I have asked the same question in the Klaytn Developers Group on Facebook too, I’m not spamming, I just wasn’t aware of the existence of this forum

This is the code that’s giving me this error:

pastebin Klaytn use smart contract

I can use other smart contracts to get information the same way I show above and there are no problems. The problem is with this particular contract.

So my question is:

What does this error mean and what can I do to fix it?

Thank you in advance :slight_smile:

I’m using Python, the web3.py library and a library I made that basically maps the Klaytn’s JSON-RPC API endpoints to python functions.

Hello @Greg_Chatzinikolaou,
Thank you for your interest in Klaytn.

execution reverted occurs when there something wrong when running a contract.
If an error occurs with a require statement, you can use revertTracer to checkout the log.

An example for a require statement in a solidity code:

require(msg.value % 2 == 0, "Even value required.");

An example for revertTracer:

debug.traceTransaction("0xbae8bd56daa6a3f1bba16854d14e37f265e76976c960ac57c4c7b56a78729e53", {tracer:'revertTracer'})
"Even value required"

Checkout VM Tracing - Klaytn Docs for revertTracer.
You need debug options to run debug.traceTransaction. It means you might need to run your own EN.

If the revert occured on somewhere else, it is kind of hard to find out where and why.
Therefore, we recommend to use truffle to test your code beforehand.

We can check your contract if something is not working that you think it should.
To do so, please add more information on how you called the contract.

Moreover, the KlaySwap contract is implemented by Ozys team.
If you have question while using the KlaySwap, please ask the Ozys team.

[email address]


Hello @Winnie ,
Thank you very match for your reply.

Edit: I think the problem was that I was using the klay_call endpoint. I should have used klay_sendTransaction instead.
Now the problem is that I get this error:

{'code': -32000, 'message': 'unknown account'}

But the account exists so now I have more questions about this endpoint but because it out of topic for this thread I’m going to start a new topic on this if I don’t find any information.

Hi @Greg_Chatzinikolaou,
Sorry for the late reply. I didn’t notice you have more question.

You can either

For a node to sign a transaction, you need to import your key to the node.
You need personal option to do import a key. This also means you need to run your own EN.

We offer caver-js, caver-java which can sign data and make transactions. It is quiet convenient.

We also have KAS (Klaytn API Service) which takes care of your accounts and make transactions without running your own node. It is charged by the number of API calls. But, it is free for 10,000 Requests / Day.

If you have more questions about using caver and KAS, please make a new thread in the corresponding sections.

1 Like

Hi @Winnie ,
You didn’t notice my reply because it got blocked by the forum for some reason.
We were chasing our tails trying to sign the contracts in python. We could only send legacy transactions. And the klaytn documentation didn’t help much.

In the end, we ended up using caver js and connect it to our main app as a microservice.

I wish we knew about KAS from the begining. That would be the best and fastest solution.

1 Like

I am so sorry for the inconvenience.

I will check the forum frequently to reply as fast as I can next time.

1 Like