Boilertalk / Web3.swift

A pure swift Ethereum Web3 library
MIT License
636 stars 187 forks source link

Decoding. WalletConnect Swap Request #168

Closed 2jumper3 closed 8 months ago

2jumper3 commented 8 months ago

Hello everyone! Thank you for your library - it works great, but I would like to ask one question: I am currently implementing WalletConnect into our application, and some resources to confirm the Swap send the eth transaction in the following format:

[{"data":"0x5ae401dc000000000000000000000000000000000000000000000000000000006579b3c300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000afc9796872cd604f0a4924fd958fb638217be28900000000000000000000000000000000000000000000000000089a5d3902434a0000000000000000000000000000000000000000000000000000000000505551000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"from":"0xafC9796872cd604F0A4924fd958Fb638217bE289",
"gas":"0x35171",
"to":"0x13f4EA83D0bd40E75C8222255bc855a974568Dd4",
"value":"0x89a5d3902434a"}]", 

As a result, I cannot create an EthTransaction and sign it because your signing process has a mandatory check for various fields, such as nonce, and this response does not include such a parameter. Is there a workaround or could you provide some guidance? Thank you very much.

What I'm tried and it doesn't work:

guard let ethData = try? EthereumData(txToCreate.data!), let gas = txToCreate.gas {

transaction = EthereumTransaction(nonce: txToCreate.nonce, 
gasPrice: gas, 
gasLimit: EthereumQuantity(quantity: 21000), 
from: txToCreate.from, 
to: txToCreate.to, 
value: txToCreate.value, 
data:ethData)
koraykoska commented 8 months ago

The mandatory fields in the library are mandatory by the Ethereum blockchain. There are no shortcuts. The reason WalletConnect doesn’t send the nonce is because you are supposed to fetch it yourself when creating the signature.

You can do this by calling web3.getTransactionCount(wallet) for the wallet that wants to send the tx. There is an example for that in the README.

On Wed, 13 Dec 2023 at 17:40, Sergey Udalov @.***> wrote:

Hello everyone! Thank you for your library - it works great, but I would like to ask one question: I am currently implementing WalletConnect into our application, and some resources to confirm the Swap send the eth transaction in the following format:

[{"data":"0x5ae401dc000000000000000000000000000000000000000000000000000000006579b3c300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000afc9796872cd604f0a4924fd958fb638217be28900000000000000000000000000000000000000000000000000089a5d3902434a0000000000000000000000000000000000000000000000000000000000505551000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "from":"0xafC9796872cd604F0A4924fd958Fb638217bE289", "gas":"0x35171", "to":"0x13f4EA83D0bd40E75C8222255bc855a974568Dd4", "value":"0x89a5d3902434a"}]",

As a result, I cannot create an EthTransaction and sign it because your signing process has a mandatory check for various fields, such as nonce, and this response does not include such a parameter. Is there a workaround or could you provide some guidance? Thank you very much.

— Reply to this email directly, view it on GitHub https://github.com/Boilertalk/Web3.swift/issues/168, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWUTTJ73ELNUWNZ3SRZDPTYJGV4DAVCNFSM6AAAAABATF4U2SVHI2DSMVQWIX3LMV43ASLTON2WKOZSGAZTSNZTG42TGNQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

2jumper3 commented 8 months ago

@koraykoska just thanks a lot, you save my day!