Skip to content

Commit 62f3e97

Browse files
This one fixing the ERC20 implementation bug, where ERC20.transaction never assigns to Contract.transaction for any given method that writes on chain.
Obviously it's a bug spreading all over the `Token` implementation. So this fix should be applied to all `ERC*.swift` methods that returns `WriteOperation`. This is the special case of #712. Closes #711
1 parent 736dff6 commit 62f3e97

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public class ERC20: IERC20, ERC20BaseProperties {
6262
}
6363

6464
public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation {
65-
let contract = self.contract
6665
self.transaction.from = from
6766
self.transaction.to = self.address
6867
self.transaction.callOnBlock = .latest
@@ -80,12 +79,12 @@ public class ERC20: IERC20, ERC20BaseProperties {
8079
guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else {
8180
throw Web3Error.inputError(desc: "Can not parse inputted amount")
8281
}
82+
contract.transaction = transaction
8383
let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )!
8484
return tx
8585
}
8686

8787
public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation {
88-
let contract = self.contract
8988
self.transaction.from = from
9089
self.transaction.to = self.address
9190
self.transaction.callOnBlock = .latest
@@ -103,7 +102,7 @@ public class ERC20: IERC20, ERC20BaseProperties {
103102
guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else {
104103
throw Web3Error.inputError(desc: "Can not parse inputted amount")
105104
}
106-
105+
contract.transaction = transaction
107106
let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )!
108107
return tx
109108
}
@@ -133,7 +132,6 @@ public class ERC20: IERC20, ERC20BaseProperties {
133132
}
134133

135134
public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation {
136-
let contract = self.contract
137135
self.transaction.from = from
138136
self.transaction.to = self.address
139137
self.transaction.callOnBlock = .latest
@@ -151,7 +149,7 @@ public class ERC20: IERC20, ERC20BaseProperties {
151149
guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else {
152150
throw Web3Error.inputError(desc: "Can not parse inputted amount")
153151
}
154-
152+
contract.transaction = transaction
155153
let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )!
156154
return tx
157155
}

0 commit comments

Comments
 (0)