Fully typed, autocompleted Ethereum Smart Contract in Swift
- Generates
Contract.generated.swift
file from ABI - All of your smart contract functions are fully typed and autocompleted
- Get
data
parameter string of transaction - Multiple contracts are available
How to get transaction data parameter:
Contract
.Abi1
.Function
.transfer(Address(string: "0x5c66b0d82df26e8FE165Be6628F5f5e1f1bccD5C"), BInt("100000000000000")!)
.txDataString()
// => 0xa9059cbb0000000000000000000000005c66b0d82df26e8FE165Be6628F5f5e1f1bccD5C00000000000000000000000000000000000000000000000000005af3107a4000
Currently supports:
bool
=>Bool
int8<16,32,64,128,256>
=>BInt
uint8<16,32,64,128,256>
=>BInt
address
=>Address
string
=>String
bytes
=>Data
bytes1<2,4,8,16,32>
=>Data
Currently supports CocoaPods
.
Basically, ContractSwift
needs ABI
json files in specific directory.
- $SRCROOT
- abi
- Contract1.json
- Contract2.json
- ...
Name of json file will be its contract name in swift.
struct Contract {
struct Contract1 {
...
}
}
// => Contract.Contract1.Function.transfer...
- Add
pod 'ContractSwift'
to your Podfile and runpod install
- Add a New Run Script Phase in Xcode.
- Paste the folowwing script(first argument is an input directory, second is output):
"$PODS_ROOT/ContractSwift/contractswift" generate "$SRCROOT/abi" "$SRCROOT"
- Build your project, then you'll see
Contract.generated.swift
file in the$SRCROOT
directory. - Add
Contract.generated.swift
into your project.
ContractSwift is available under the MIT license. See the LICENSE file for more info.