your name here
your name here

Reputation: 1

How to use Ethereum RPC API to swap tokens?

I am trying to code a client for swapping tokens through BSC chain (I really don't want to use web3 libraries) using Ethereum API. So learned some stuff from Ethereum RPC API documentation, but i can't really understand what are the steps for sending Raw Signed transaction. So here is my example payload:

data = {"jsonrpc": "2.0",
            "method": "eth_sendTransaction",
            "params": [
                {
                    'from': address,
                    'to': self.router_address,
                    'gas': hex(gas),
                    'gasPrice':  hex(gasPrice),
                    'value': hex(ETH_amount),
                    'data': query,
                    "nonce": await self.getTransactionCount(address)
                }],
            "id": _id}

And of course necessary header {"Content-Type": "application/json"}

The data field (query variable) basically was taken from this transaction. If you scroll down, you can see the original payload, which of course was successfully processed, because the operation was created with PancakeSwap. But when i send the same (even with modified deadline parameter) i get the this:

{'jsonrpc': '2.0', 'id': 1, 'error': {'code': -32000, 'message': 'unknown account'}}

Obvioulsy somewhere should be done signing function, but i just don't know how to make it. Can somebody help me? How do I process the data and make requests so that the swap succeeds? (From BNB to BUSD, for example - without approving step).

Upvotes: 0

Views: 319

Answers (1)

TUFAN POYRAZ
TUFAN POYRAZ

Reputation: 59

Try to use web3.toChecksumAddress("address") for both your address and router address

Upvotes: 0

Related Questions