Skip to content

Commit 9d782c9

Browse files
committed
Add erc base properties provider
1 parent f9dcd83 commit 9d782c9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// ERCBasePropertiesProvider.swift
3+
//
4+
//
5+
// Created by Jann Driessen on 21.11.22.
6+
//
7+
8+
import BigInt
9+
import Foundation
10+
11+
public final class ERCBasePropertiesProvider {
12+
var name: String?
13+
var symbol: String?
14+
var decimals: UInt8?
15+
16+
private let contract: Web3.Contract
17+
private (set) var hasReadProperties: Bool = false
18+
init(contract: Web3.Contract) {
19+
self.contract = contract
20+
}
21+
22+
public func readProperties() async throws {
23+
guard !hasReadProperties else { return }
24+
guard contract.contract.address != nil else {return}
25+
name = try await contract
26+
.createReadOperation("name")?
27+
.callContractMethod()["0"] as? String
28+
29+
symbol = try await contract
30+
.createReadOperation("symbol")?
31+
.callContractMethod()["0"] as? String
32+
33+
let decimals = try await contract
34+
.createReadOperation("decimals")?
35+
.callContractMethod()["0"] as? BigUInt
36+
self.decimals = decimals != nil ? UInt8(decimals!) : nil
37+
hasReadProperties = true
38+
}
39+
}

0 commit comments

Comments
 (0)