Latest 0.1
Homepage https://github.com/AckeeCZ/Ethereum-iOS-Dev-Kit
License MIT
Platforms ios 10.0
Dependencies EtherKit, ReactiveSwift
Authors

ackee|Ethereum-iOS-Dev-Kit

Ethereum iOS Dev Kit

Installation

There are multiple possibilities to install ContractCodegen on your machine or in your project, depending on your preferences and needs. Note that if you do not install ContractCodegen using Cocoapods, you will have have to import EtherKit and ReactiveSwift by yourself.

Download the ZIP for the latest release

* [Go to the GitHub page for the latest release](https://github.com/AckeeCZ/Ethereum-iOS-Dev-Kit/releases/latest)
* Download the `contractcodegen-x.y.z.zip` file associated with that release
* Extract the content of the zip archive in your project directory

We recommend that you **unarchive the ZIP inside your project directory** and **commit its content** to git. This way, **all coworkers will use the same version of ContractCodegen for this project**.

If you unarchived the ZIP file in a folder e.g. called `contractcodegen`, you can then invoke it like this:

“`sh
contractcodegen/bin/contractcodegen …
“`


Via CocoaPods

If you’re using CocoaPods, you can simply add `pod ‘ContractCodegen’` to your `Podfile`.

This will download the `ContractCodegen` binaries and dependencies in `Pods/` during your next `pod install` execution.

Given that you can specify an exact version for “ContractCodegen“ in your `Podfile`, this allows you to ensure **all coworkers will use the same version of ContractCodegen for this project**.

You can then invoke ContractCodegen from your terminal:
“`sh
Pods/ContractCodegen/ContractCodegen/bin/contractcodegen …
“`

_Note: ContractCodegen isn’t really a pod, as it’s not a library your code will depend on at runtime; so the installation via CocoaPods is just a trick that installs the ContractCodegen binaries in the Pods/ folder, but you won’t see any swift files in the Pods/ContractCodegen group in your Xcode’s Pods.xcodeproj. That’s normal: the ContractCodegen binary is still present in that folder in the Finder._


System-wide installation

* [Go to the GitHub page for the latest release](https://github.com/AckeeCZ/Ethereum-iOS-Dev-Kit/releases/latest)
* Download the `contractcodegen-x.y.z.zip` file associated with that release
* Extract the content of the zip archive

1. `cd` into the unarchived directory
2. `make install`
3. You then invoke contractgen simply with `contractgen …`

iOS MVVM Project Template

We have also created iOS MVVM Project Template, so setting your project has never been easier.
Easily follow the installation instructions.
After you are done, add name_of_your_abi.json file to Resources. Then add ContractCodegen to your Podfile, do pod install and run this command in your project root directory:

Pods/ContractCodegen/ContractCodegen/bin/contractgen HelloContract NameOfYourProject/Resources/abi.json -x NameOfYourProject.xcodeproj -o NameOfYourProject/Model/Generated/GeneraredContracts

Usage

Codegen

The standard usage looks like this contractgen HelloContract path_to_abi/abi.json -x path_to_xcodeproj/project.xcodeproj -o relative_output_path

Please note that the output path option (--output) should be relative to your project – if your generated files are in YourProjectName/MainFolder/GeneratedContracts folder, then you should write --output MainFolder/GeneratedContracts
For your projects to be bound you also must set the --xcode option as well. Otherwise you will have to drag the files to your projects manually.

Usage of Generated Codes

The standard call using code created by codegen looks like this:

import ReactiveSwift
import EtherKit 
let helloWorldContractAddress = try! Address(describing: "0x7cA5E6a3200A758B146C17D4E3a4E47937e79Af5")
let query = EtherQuery(URL(string: "infrastructure-url")!, connectionMode: .http)
query.helloContract(at: helloWorldContractAddress).greet(greetString: "Greetings!").send(using: key, amount: Wei(1)).start()

key should be of protocol PrivateKeyType (more at EtherKit documentation)
Also note that right now the created code works with ReactiveSwift only.

If the contract function is non-payable, the syntax is almost the same (amount is omitted):

query.helloContract(at: helloWorldContractAddress).greet(greetString: "Greetings!").send(using: key).start()

Result of the call is either a Hash of the transaction or an EtherKitError.

Latest podspec

{
    "name": "ContractCodegen",
    "version": "0.1",
    "summary": "Generate code from abi.json",
    "description": "Generate code from abi.json using Swift tool.",
    "homepage": "https://github.com/AckeeCZ/Ethereum-iOS-Dev-Kit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ackee": "[email protected]"
    },
    "source": {
        "git": "https://github.com/AckeeCZ/Ethereum-iOS-Dev-Kit.git",
        "tag": "0.1"
    },
    "preserve_paths": [
        "ContractCodegen/bin/contractgen",
        "ContractCodegen/Rakefile",
        "ContractCodegen/templates/**",
        "ContractCodegen/LICENSE"
    ],
    "platforms": {
        "ios": "10.0"
    },
    "swift_version": "4.2",
    "dependencies": {
        "EtherKit": [
            "~> 0.2.0"
        ],
        "ReactiveSwift": [
            "~> 4.0"
        ]
    }
}

Pin It on Pinterest

Share This