{"id":19149582,"url":"https://github.com/zeriontech/0x.swift","last_synced_at":"2025-05-07T04:44:18.383Z","repository":{"id":108614082,"uuid":"176339302","full_name":"zeriontech/0x.swift","owner":"zeriontech","description":"Swift Library for 0x protocol","archived":false,"fork":false,"pushed_at":"2019-08-19T22:31:26.000Z","size":117,"stargazers_count":4,"open_issues_count":6,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-07T04:44:12.180Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeriontech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-03-18T17:44:42.000Z","updated_at":"2022-03-10T17:22:41.000Z","dependencies_parsed_at":"2023-04-26T10:11:39.096Z","dependency_job_id":null,"html_url":"https://github.com/zeriontech/0x.swift","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeriontech%2F0x.swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeriontech%2F0x.swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeriontech%2F0x.swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeriontech%2F0x.swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeriontech","download_url":"https://codeload.github.com/zeriontech/0x.swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252816519,"owners_count":21808702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T08:08:51.647Z","updated_at":"2025-05-07T04:44:18.374Z","avatar_url":"https://github.com/zeriontech.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 0x.swift\n\n[![Version](https://img.shields.io/cocoapods/v/0x.swift.svg?style=flat)](https://cocoapods.org/pods/0x.swift)\n[![License](https://img.shields.io/cocoapods/l/0x.swift.svg?style=flat)](https://cocoapods.org/pods/0x.swift)\n[![Platform](https://img.shields.io/cocoapods/p/0x.swift.svg?style=flat)](https://cocoapods.org/pods/0x.swift)\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n## Installation\n\n0x.swift is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod '0x.swift'\n```\n\n## Interacting with ERC20 token\n\n### Create token instance\n```swift\nlet network = AlchemyNetwork( \n            chain: \"mainnet\",\n            apiKey: \"ETi2ntZoWxd6nTI1qE13Q4I1eLB8AMDl\"\n        )\n\nlet zrxToken = ERC20Token(\n        //ZRX Token\n        contract: EthAddress(\n            hex: \"0xe41d2489571d322189246dafa5ebde1f4699f498\" \n        ),\n        //JSON RPC network (Alchemy, Infura, Local or Private)\n        network: network\n    )\n```\n### Check decimal\n```swift\nlet decimals = try zrxToken.decimals().value().toDecimal()\n```\n### Check owner balance\n```swift\nlet balance : Decimal = try zrxToken.balanceOf(\n        owner: EthAddress(\n            hex: \"0x606af0bd4501855914b50e2672c5926b896737ef\"\n        )\n    ).value().toNormalizedDecimal(\n        power: 18\n    )\n```\n\n### Sending tokens \n```swift\nlet sendingTxHash = try zrxToken.transfer(\n    to: EthAddress(\n        hex: \"0x42b9dF65B219B3dD36FF330A4dD8f327A6Ada990\"\n    ), \n    value: EthNumber(\n        decimals: \"1\"\n    ), \n    sender: EthPrivateKey(\n        hex: \"SENDER_PRIVATE_KEY\"\n    )\n)\n\nlet receipts = try sendingTxHash.receipt(\n        network: network\n    )\n```\n\n### Parsing single event from receipt\n```swift\nlet transfer = try ERC20Events.Transfer(\n        log: receipt.logs()[0]\n    )\nprint(transfer.from.toPrefixedHexString())\nprint(transfer.to.toPrefixedHexString())\nprint(transfer.value.toDecimalString())\n```\n\n### Parsing multiple events from receipt\n```swift\nlet events = ABIEvent.parse(types: [\n        ERC20Events.Transfer.self,\n        ERC20Events.Approval.self\n    ], logs: receipt.logs())\n```\n\n### Filtering events\n```swift\nlet transfers = events.filter { $0.signature() == ERC20Events.Transfer.signature() }\n\nlet contract = EthAddress(hex: \"0x606af0bd4501855914b50e2672c5926b896737ef\")\nlet zrxTransfers = transfers.filter { $0.contract == contract }\n```\n\n## Working with typed data\n\n### Hashing typed data from JSON\n```swift\nlet data = try EIP712TypedData(jsonString: typedDataJson)\nlet hash = EIP712Hash(domain: data.domain, typedData: data)\n```\n\n### Constructing typed data from Swift objects\n```swift\nstruct Order {\n    \n    let makerAddress: String\n    let takerAddress: String\n    let feeRecipientAddress: String\n    let senderAddress: String\n    let makerAssetAmount: Int\n    let takerAssetAmount: Int\n    let makerFee: Int\n    let takerFee: Int\n    let expirationTimeSeconds: Int\n    let salt: Int\n    let makerAssetData: Data\n    let takerAssetData: Data\n}\n\nextension Order: EIP712Representable {\n    \n    var values: [EIP712Value] {\n        return [\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"makerAddress\", type: .address),\n                value: makerAddress\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"takerAddress\", type: .address),\n                value: takerAddress\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"feeRecipientAddress\", type: .address),\n                value: feeRecipientAddress\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"senderAddress\", type: .address),\n                value: senderAddress\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"makerAssetAmount\", type: .uint(len: 256)),\n                value: makerAssetAmount\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"takerAssetAmount\", type: .uint(len: 256)),\n                value: takerAssetAmount\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"makerFee\", type: .uint(len: 256)),\n                value: makerFee\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"takerFee\", type: .uint(len: 256)),\n                value: takerFee\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"expirationTimeSeconds\", type: .uint(len: 256)),\n                value: expirationTimeSeconds\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"salt\", type: .uint(len: 256)),\n                value: salt\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"makerAssetData\", type: .bytes),\n                value: makerAssetData\n            ),\n            EIP712SimpleValue(\n                parameter: EIP712Parameter(name: \"takerAssetData\", type: .bytes),\n                value: takerAssetData\n            ),\n        ]\n    }\n}\n\nlet order = Order(\n    makerAddress: \"0xc0ffee254729296a45a3885639ac7e10f9d54979\",\n    takerAddress: \"0x999999cf1046e68e36e1aa2e0e07105eddd1f08e\",\n    feeRecipientAddress: \"0x0000000000000000000000000000000000000000\",\n    senderAddress: \"0x0000000000000000000000000000000000000000\",\n    makerAssetAmount: 1,\n    takerAssetAmount: 1,\n    makerFee: 0,\n    takerFee: 0,\n    expirationTimeSeconds: 3600,\n    salt: 0,\n    makerAssetData: // ABIv2 encoded data,\n    takerAssetData: // ABIv2 encoded data\n)\n\nlet domain = EIP712Domain(\n    name: \"0x protocol\",\n    version: \"2\",\n    chainID: 1,\n    verifyingContract: \"0x4f833a24e1f95d70f028921e27040ca56e09ab0b\",\n    salt: nil\n)\n\nlet hash = EIP712Hash(domain: domain, typedData: order)\n```\n\n### Signing typed data\n```swift\nlet privateKey = EthPrivateKey(hex: \"SIGNER_PRIVATE_KEY\")\nlet signer = EIP712Signer(privateKey: privateKey)\nlet signature = try signer.signatureData(hash: hash)\n```\n\n### Verifying typed data signature\n```swift\nlet address = EthAddress(hex: \"SIGNER_ADDRESS\")\nlet verifier = EIP712SignatureVerifier()\nreturn try verifier.verify(data: hash, signature: signature, address: address)\n```\n\n## Author\n\n- Igor Shmakov [@shmakovigor](https://github.com/shmakovigor), shmakoff.work@gmail.com\n- Vadim Koleoshkin [@rockfridrich](https://github.com/rockfridrich), vadim@koleoshkin.com\n\n## License\n\n0x.swift is available under the the Apache License 2.0. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeriontech%2F0x.swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeriontech%2F0x.swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeriontech%2F0x.swift/lists"}