Convert EVM Contract ABI from json to swift file
- Install NodeJS on your system
- Install NPM package
npm i swiftabigen --location=global
- After installation you can use command
npx swiftabigen filename
filename is name of json ABI file without extension - File will be generated under folder (see picture below)
- Open your XCode Project and create Group with name CustomAbi
- Click Add files to "project" and import the folder
Make sure you choose create groups!
Tara! your ABI was successfully imported.
You no need to declare contract to every functions. you only need declare for the Contract and use the functions!
func test_contract() async {
do {
let x = IERC20Contract(contract: "0x7ef95a0FEE0Dd31b22626fA2e10Ee6A223F8a684", client: client)
let name = try await x.name()
print(name)
}catch {
}
}
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 {
}
}