可以将 IOS 应用程序与 ERC20 令牌集成

Possible to Integrate IOS app with ERC20 token

此时可以将 IOS 应用程序与以太坊网络上的 ERC20 令牌集成。

似乎有一个名为 web3.swift 的库允许与以太坊集成。也许这是要走的路,但不知道它是否已准备好用于生产应用程序。

此外,似乎有一些关于 Swift 和区块链的在线课程,例如使用 Tierion 区块链作为服务的 this one from Lynda and this one from Udemy and some tutorials on blockchain integration such as this from AppCoda and this one。事实上,AWS、Azure 等似乎都提供区块链即服务。亚马逊通过以太坊提供托管区块链。

但是,我还没有看到任何具体说明如何将 IOS 应用程序与以太坊集成的内容。如果它由 AWS 在后端完成,这是否违背了使用区块链避免在服务器上集中化的目的?

我正在研究的用例是查看您拥有的代币数量并允许用户在服务上花费代币。然而,代币将驻留在区块链上。

感谢您就现阶段是否可行以及如果可行,如何开发它提供任何建议。

新交易

Infura 服务可能会在这里提供帮助。创建帐户并设置项目后,您将获得可以在特定以太坊网络上执行写入操作的节点(用于主网和一些测试网)。

这是用 Swift 和 Web3.swift 编写的代码,可能会有帮助:

func send(sender: String,
          receiver: String,
          senderSecret: String,
          tokenContractAddress: String,
          amount: Int,
          completion: @escaping Result<Transaction, Error>) {

    let web3 = Web3(rpcURL: "YOUR_INFURA_NODE_ID_GOES_HERE")

    do {
        let privateKey = try EthereumPrivateKey(hexPrivateKey: senderSecret)

        let senderWallet = try EthereumAddress(hex: sender, eip55: true)

        let receiverWallet = try EthereumAddress(hex: receiver, eip55: true)

        let contract = web3.eth.Contract(
            type: GenericERC20Contract.self,
            address: try EthereumAddress(hex: tokenContractAddress, eip55: true)
        )

        firstly {
            return web3.eth.getTransactionCount(address: privateKey.address, block: .latest)
        }.compactMap { nonce in
            guard let tx = contract
                .transfer(to: receiverWallet, value: BigUInt(amount))
                .createTransaction(
                    nonce: nonce,
                    from: senderWallet,
                    value: 0,
                    gas: 100000,
                    gasPrice: EthereumQuantity(quantity: 21.gwei)
                ) else { return nil }

            return try tx.sign(with: privateKey, chainId: 3)
        }.then { tx in
            return web3.eth.sendRawTransaction(transaction: tx!)
        }.done { hash in
            let tx = Transaction(hash: hash)
            completion.set(.success(tx))
        }.catch { error in
            completion.set(.failure(error))
        }
    } catch {
        completion.set(.failure(error))
    }
}

公开信息

如果不需要发起交易,您只想使用 public 信息,例如 token supply/holder balances/etc. -你可以尝试一些像 blockscout 这样的开放 API 来获取你需要的数据。