6

Integrating web3.js into a native iOS & Android Apps has issues.

I am having difficulty integrating web3.js into a native mobile App (iOS & Android), would it be reasonable to use a cloud server & npm install web3 and let the mobile App connect to that Cloud server instance to make all calls to a deployed Smart Contract?

The only issue I see with this, is that it defies the peer-to-peer architecture of the blockchain by having a cloud server in the middle.

1
  • 1
    Yes, you are you can use a third party service like infura o etherscan that allow interacting the blockchain through their servers, and you can also setup your own geth node to use as fallback. Depending on the use case you may want to allow your users to setup their own geth node.
    – Ismael
    Commented Aug 4, 2017 at 3:30

2 Answers 2

3

You can use the Infura APIS from mobile to interact with the blockchain locally https://blog.infura.io/getting-started-with-infura-28e41844cc89 that way you don't have to setup your own proxy server

3

For iOS: skywinder/web3swift

Here is elegant web3js functionality in Swift. Native ABI parsing and smart contract interactions

Here is an example, to send transaction:

TransactionsService().prepareTransactionForSendingEther(destinationAddressString: destinationAddress, amountString: amount, gasLimit: 21000) { (result) in
            switch result {
            case .Success(let transaction):
                guard let gasPrice = self.gasPriceTextField.text else { return }
                guard let gasLimit = self.gasLimitTextField.text else { return }
                guard let name = self.walletName else { return }
                let dict:[String:Any] = [
                    "gasPrice":gasPrice,
                    "gasLimit":gasLimit,
                    "transaction":transaction,
                    "amount":amount,
                    "name": name,
                    "fromAddress": self.walletAddress!,
                    "toAddress": destinationAddress]
                
                self.sendFunds(dict: dict, enteredPassword: withPassword)
                
            case .Error(let error):
                var textToSend = ""
                if let error = error as? SendErrors {
                    switch error {
                    case .invalidDestinationAddress:
                        textToSend = "invalidAddress"
                    default:
                        break
                    }
                }
                
                showErrorAlert(for: self, error: error)
            }
        }

For Android you can use web3j/web3j

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.