@@ -39,31 +39,28 @@ public class ERC888: IERC888, ERC20BaseProperties {
39
39
}
40
40
41
41
public func getBalance( account: EthereumAddress ) async throws -> BigUInt {
42
- let contract = self . contract
43
- self . transaction. callOnBlock = . latest
44
- let result = try await contract. createReadOperation ( " balanceOf " , parameters: [ account] as [ AnyObject ] , extraData: Data ( ) ) !. callContractMethod ( )
42
+ transaction. callOnBlock = . latest
43
+ let result = try await contract. createReadOperation ( " balanceOf " , parameters: [ account] as [ AnyObject ] , extraData: Data ( ) ) !. callContractMethod ( )
45
44
guard let res = result [ " 0 " ] as? BigUInt else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
46
45
return res
47
46
}
48
47
49
48
public func transfer( from: EthereumAddress , to: EthereumAddress , amount: String ) async throws -> WriteOperation {
50
- let contract = self . contract
51
- self . transaction. from = from
52
- self . transaction. to = self . address
53
- self . transaction. callOnBlock = . latest
54
-
49
+ transaction. from = from
50
+ transaction. to = address
51
+ transaction. callOnBlock = . latest
52
+ contract. transaction = transaction
55
53
// get the decimals manually
56
54
let callResult = try await contract. createReadOperation ( " decimals " ) !. callContractMethod ( )
57
55
var decimals = BigUInt ( 0 )
58
56
guard let dec = callResult [ " 0 " ] , let decTyped = dec as? BigUInt else {
59
57
throw Web3Error . inputError ( desc: " Contract may be not ERC20 compatible, can not get decimals " ) }
60
58
decimals = decTyped
61
-
62
59
let intDecimals = Int ( decimals)
63
60
guard let value = Utilities . parseToBigUInt ( amount, decimals: intDecimals) else {
64
61
throw Web3Error . inputError ( desc: " Can not parse inputted amount " )
65
62
}
66
- let tx = contract. createWriteOperation ( " transfer " , parameters: [ to, value] as [ AnyObject ] ) !
63
+ let tx = contract. createWriteOperation ( " transfer " , parameters: [ to, value] as [ AnyObject ] ) !
67
64
return tx
68
65
}
69
66
0 commit comments