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

eth_sendTransaction method not working: iOS #82

Open
Prakash7247 opened this issue Jan 22, 2025 · 1 comment
Open

eth_sendTransaction method not working: iOS #82

Prakash7247 opened this issue Jan 22, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Prakash7247
Copy link

**Bug description **

I am facing an issue with the eth_sendTransaction method. When I run the demo project (migrate WalletConnectV2 to reown 1.2.1) on my device, the WalletConnect functionality works correctly, and the connection with different wallets, such as MetaMask, Trust Wallet, Rainbow Wallet, etc., is successfully established. However, when I try to send a transaction request using the eth_sendTransaction method, the functionality does not work as expected.

Specifically, the wallet app is opened via the AppKit.instance.launchCurrentWallet() method, but the transaction confirmation popup does not appear. I have tested this functionality with several wallets, including MetaMask, Trust Wallet, Rainbow Wallet, and others, but the issue persists across all of them.

Can you please guide me on what I might be doing wrong or provide suggestions on resolving this issue?

SDK Version

  • Client: Swift
  • Version Reown 1.2.1

Device (please complete the following information):

  • Device: iPhone Xr
  • OS: iOS 18.0
  • Browser: native app
  • Version: 1

** Here is my code **

let projectId = InputConfig.projectId

    // Initialize metadata
    let metadata = AppMetadata(
        name: "Web3Modal Swift Dapp",
        description: "Web3Modal DApp sample",
        url: "www.web3modal.com",
        icons: ["https://avatars.githubusercontent.com/u/37784886"],
        redirect: try! .init(native: "w3mdapp://", universal: "https://lab.web3modal.com/web3modal_example", linkMode: true)
    )

    Networking.configure(
        groupIdentifier: "app_group_identifier",
        projectId: projectId,
        socketFactory: DefaultSocketFactory()
    )

    AppKit.configure(
        projectId: projectId,
        metadata: metadata,
        crypto: DefaultCryptoProvider(),
        authRequestParams: nil, // use .stub() for testing SIWE
        customWallets: [
            .init(
                id: "swift-sample",
                name: "Swift Sample Wallet",
                homepage: "https://walletconnect.com/",
                imageUrl: "https://avatars.githubusercontent.com/u/37784886?s=200&v=4",
                order: 1,
                mobileLink: "walletapp://",
                linkMode: "https://lab.web3modal.com/wallet"
            )
        ]
    ) { error in
        print(error)
    }
    setup()
}

private func setup() {
    AppKit.instance.socketConnectionStatusPublisher
        .receive(on: DispatchQueue.main)
        .sink { [weak self] status in
            print("Socket connection status: \(status)")
            self?.socketConnectionManager.socketConnected = (status == .connected)
        }
        .store(in: &disposeBag)

    AppKit.instance.logger.setLogging(level: .debug)
    Sign.instance.setLogging(level: .debug)
    Networking.instance.setLogging(level: .debug)
    Relay.instance.setLogging(level: .debug)
    
    AppKit.instance.authResponsePublisher
        .sink { [weak self] (id: RPCID, result: Result<(Session?, [Cacao]), AuthError>) in
            switch result {
            case .success((_, _)):
                AlertPresenter.present(message: "User authenticated", type: .success)
            case .failure(let error):
                AlertPresenter.present(message: "User authentication error: \(error)", type: .error)
            }
        }
        .store(in: &disposeBag)

    AppKit.instance.SIWEAuthenticationPublisher
        .sink { [weak self] result in
            switch result {
            case .success((let message, let signature)):
                AlertPresenter.present(message: "User authenticated", type: .success)
            case .failure(let error):
                AlertPresenter.present(message: "User authentication error: \(error)", type: .error)
            }
        }
        .store(in: &disposeBag)
}

// ETH_SEND_TRANSACTION

Button("Send transaction") {
Task {
do {
try await calledRequest()
AppKit.instance.launchCurrentWallet()
} catch {
print("Error occurred: (error)")
}
}
}

private func calledRequest() async {
guard let session = AppKit.instance.getSessions().first else {
print("No active session")
return
}
let payLoad: [String: Any] = [
"from":AppKit.instance.getAddress() ?? "",
"to":"0xc771784564fa1de46a903887e78f5e8555cf6a7d",
"value":"0",
"data":"0x",
"nonce":"0x07",
"gasPrice":"0x0649534e00",
"gasLimit":"0x5208",
]

    do {
        try await AppKit.instance.request(
            params: .init(
                topic: session.topic,
                method: "eth_sendTransaction",
                params: AnyCodable(any: payLoad),
                chainId: Blockchain("eip155:1")!
            )
        )
        
    } catch {
        print("Error occurred during request: \(error)")
        print("Detailed error: \(String(describing: error))")
    }

/// Also try with this method as well
//let payLoad: [String: Any] = [
// "from":AppKit.instance.getAddress() ?? "",
// "to":"0xc771784564fa1de46a903887e78f5e8555cf6a7d",
// "value":"0x",
// "data":"",
// "nonce":"0x07",
// "gasPrice":"0x0649534e00",
// "gasLimit":"0x5208",
// ]
//
// do {
// // Ensure chainId is properly formatted
// let formattedChainId = socketConnectionManager.chainId.contains("eip155:")
// ? socketConnectionManager.chainId
// : "eip155:(socketConnectionManager.chainId)"
// try await AppKit.instance.request(
// params: .init(
// topic: session.topic,
// method: "eth_sendTransaction",
// params: AnyCodable(any: payLoad),
// chainId: Blockchain(formattedChainId)!
// )
// )
//
// } catch {
// print("Error occurred during request: (error)")
// print("Detailed error: (String(describing: error))")
// }
}

@Prakash7247 Prakash7247 added the bug Something isn't working label Jan 22, 2025
Copy link

linear bot commented Jan 22, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant