Skip to content

Commit 72b40c0

Browse files
authored
Merge pull request #72 from BANKEX/develop
convenience methods in web3.eth to send ETH using either raw BigUInt value in Wei, or parsing a decimal string of arbitrary units
2 parents b5e25f5 + a0e0f86 commit 72b40c0

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

web3swift/Web3/Classes/Web3+Eth.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ extension web3.Eth {
293293
}
294294

295295
public func estimateGas(_ transaction: EthereumTransaction, options: Web3Options?, onBlock: String = "latest") -> Result<BigUInt, Web3Error> {
296-
let mergedOptions = Web3Options.merge(Web3Options.defaultOptions(), with: options)
296+
let mergedOptions = Web3Options.merge(self.options, with: options)
297297
guard let request = EthereumTransaction.createRequest(method: JSONRPCmethod.estimateGas, transaction: transaction, onBlock: onBlock, options: mergedOptions) else {
298298
return Result.failure(Web3Error.inputError("Transaction serialization failed"))
299299
}
@@ -430,5 +430,21 @@ extension web3.Eth {
430430
return Result(block)
431431
}
432432
}
433+
public func sendETH(to: EthereumAddress, amount: BigUInt, extraData: Data = Data(), options: Web3Options? = nil) -> TransactionIntermediate? {
434+
let contract = self.web3.contract(Web3.Utils.coldWalletABI, at: to, abiVersion: 2)
435+
guard var mergedOptions = Web3Options.merge(self.options, with: options) else {return nil}
436+
mergedOptions.value = amount
437+
let intermediate = contract?.method("fallback", extraData: extraData, options: mergedOptions)
438+
return intermediate
439+
}
440+
441+
public func sendETH(to: EthereumAddress, amount: String, units: Web3.Utils.Units = .eth, extraData: Data = Data(), options: Web3Options? = nil) -> TransactionIntermediate? {
442+
let contract = self.web3.contract(Web3.Utils.coldWalletABI, at: to, abiVersion: 2)
443+
guard var mergedOptions = Web3Options.merge(self.options, with: options) else {return nil}
444+
guard let value = Web3.Utils.parseToBigUInt(amount, units: .eth) else {return nil}
445+
mergedOptions.value = value
446+
let intermediate = contract?.method("fallback", extraData: extraData, options: mergedOptions)
447+
return intermediate
448+
}
433449

434450
}

0 commit comments

Comments
 (0)