Skip to content

imanrep/swiftabigen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swiftabigen

Convert EVM Contract ABI from json to swift file

How to install

  1. Install NodeJS on your system
  2. Install NPM package npm i swiftabigen --location=global
  3. After installation you can use command npx swiftabigen filename filename is name of json ABI file without extension
  4. File will be generated under folder (see picture below)

image

  1. Open your XCode Project and create Group with name CustomAbi
  2. Click Add files to "project" and import the folder

Screenshot 2023-01-25 at 17 27 07

Make sure you choose create groups!

Screenshot 2023-01-25 at 17 28 09

Tara! your ABI was successfully imported.

Screenshot 2023-01-25 at 17 29 04

How to use

You no need to declare contract to every functions. you only need declare for the Contract and use the functions!

IERC20 example

Transfer

func test_contract() async {
        do {
            let x = IERC20Contract(contract: "0x7ef95a0FEE0Dd31b22626fA2e10Ee6A223F8a684", client: client)
            let name = try await x.name()
            print(name)
        }catch {
            
        }
}

Screenshot 2023-01-25 at 17 33 42

Token Transfer (nonPayable)

func test_contract() async {
        do {
            let x = IERC20Contract(contract: "0x7ef95a0FEE0Dd31b22626fA2e10Ee6A223F8a684", client: client)
            let txHash = try await x.transfer(recepient: EthereumAddress("0x7ef95a0FEE0Dd31b22626fA2e10Ee6A223F8a684"), amount BigUInt(100000000000), account : account)
            print(txHash)
        }catch {
            
        }
}

Screenshot 2023-01-25 at 17 39 22

Dependencies

web3.swift

ReadMe

About

Convert EVM Contract ABI from json to swift file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published