Skip to content

Commit 2d38fd0

Browse files
committed
Fix ERC8888
1 parent 7178a20 commit 2d38fd0

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,28 @@ public class ERC888: IERC888, ERC20BaseProperties {
3939
}
4040

4141
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()
4544
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
4645
return res
4746
}
4847

4948
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
5553
// get the decimals manually
5654
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
5755
var decimals = BigUInt(0)
5856
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
5957
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
6058
decimals = decTyped
61-
6259
let intDecimals = Int(decimals)
6360
guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else {
6461
throw Web3Error.inputError(desc: "Can not parse inputted amount")
6562
}
66-
let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )!
63+
let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])!
6764
return tx
6865
}
6966

0 commit comments

Comments
 (0)