web3swift 是一个用于与以太坊网络交互的 iOS 工具包。
加入我们的 discord 或 Telegram,如果您需要支持或想为 web3swift 开发做贡献!
Swift Package Manager 是一个用于自动化 Swift 代码分发的工具,它与 Swift 构建系统良好集成。
一旦您设置了 Swift 包,添加 web3swift
作为依赖项就像将其添加到您的 Package.swift
的 dependencies
值一样简单。
dependencies: [
.package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0"))
]
或者,如果您的项目不是包,请按照这些指南了解 如何将 Swift Package 添加到您的 Xcode 项目中。
在导入部分
import web3swift
import Web3Core
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ sudo gem install cocoapods
要使用 CocoaPods 将 web3swift 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '13.0'
target '<Your Target Name>' do
use_frameworks!
pod 'web3swift'
end
然后,运行以下命令
$ pod install
警告:CocoaPods 是一个用于管理 iOS 开发中依赖项的强大工具,但它也有一些限制,妨碍我们在此处提供一流的支持。我们强烈建议首先使用 SPM,因为使用 CocoaPods 会延迟向您交付新的更新和错误修复。
let transaction: CodableTransaction = .emptyTransaction
transaction.from = from ?? transaction.sender // `sender` one is if you have private key of your wallet address, so public key e.g. your wallet address could be interpreted
transaction.value = value
transaction.gasLimitPolicy = .manual(78423)
transaction.gasPricePolicy = .manual(20000000000)
web3.eth.send(transaction)
let contract = web3.contract(Web3.Utils.erc20ABI, at: receipt.contractAddress!)!
let readOp = contract.createReadOperation("name")!
readOp.transaction.from = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")
let response = try await readTX.callContractMethod()
let abiString = "[]" // some ABI string
let bytecode = Data.fromHex("") // some ABI bite sequence
let contract = web3.contract(abiString, at: nil, abiVersion: 2)!
let parameters: [Any] = [...]
let deployOp = contract.prepareDeploy(bytecode: bytecode, constructor: contract.contract.constructor, parameters: parameters)!
deployOp.transaction.from = "" // your address
deployOp.transaction.gasLimitPolicy = .manual(3000000)
let result = try await deployTx.writeToChain(password: "web3swift")
func feeHistory(blockCount: UInt, block: BlockNumber, percentiles:[Double]) async throws -> Web3.Oracle.FeeHistory {
let requestCall: APIRequest = .feeHistory(blockCount, block, percentiles)
let response: APIResponse<Web3.Oracle.FeeHistory> = try await APIRequest.sendRequest(with: web3.provider, for: requestCall) /// explicitly declaring `Result` type is **required**.
return response.result
}
git clone https://github.com/web3swift-team/web3swift.git
cd web3swift
swift build
文档正在建设中👷🏻👷🏼♀️。我们正在尽力详细注释所有公共 API,但最终目标仍然遥远。但在最近的次要更新之一中,我们将为已完成的文档量带来 DocC 支持。并且非常欢迎您在这方面的 PR。
请查看我们的客户 wiki 页面。
如果您需要支持或想为 web3swift 开发做贡献,请加入我们的 discord 和 Telegram!
为了进行本地开发并运行本地测试,我们建议使用 ganache,这也是 CI 在运行 github actions 时使用的工具。
// To install
$ npm install ganache --global
// To run
$ ganache
这将创建一个本地区块链以及一些在我们的测试中使用的测试帐户。请确保 ganache
在其默认端口 8546
上运行。要在测试用例中更改端口,请找到 LocalTestCase.swift
并修改静态 url
变量。
我们正在使用 pre-commit 在创建提交之前在本地运行验证。请安装 pre-commit 并从项目根目录运行 pre-commit install
。之后,每次提交之前,git hook 将运行并执行 codespell
、swiftlint
和其他检查。
想要改进吗?太棒了:那么这对您来说是个好消息:我们准备通过 @gitcoin bot 为您的贡献付费!
@skywinder 负责开源,并且不要求使用 web3swift 库的用户付费。我们希望继续尽一切努力推动发展。
0x6A3738c6299f45c31697aceA647D49EdCC9C28A4
如果您认为自己发现了 web3swift 的安全漏洞,应尽快通过电子邮件 web3swift@oxor.io 报告。请不要将其发布到公共 issue 跟踪器。
web3swift 在 Apache License 2.0 许可证下可用。有关详细信息,请参阅 LICENSE。