diff --git a/Sources/Web3Core/EthereumNetwork/Request/APIRequest+ComputedProperties.swift b/Sources/Web3Core/EthereumNetwork/Request/APIRequest+ComputedProperties.swift index fc711ce4b..892f7fa69 100644 --- a/Sources/Web3Core/EthereumNetwork/Request/APIRequest+ComputedProperties.swift +++ b/Sources/Web3Core/EthereumNetwork/Request/APIRequest+ComputedProperties.swift @@ -22,7 +22,7 @@ extension APIRequest { return [RequestParameter]() case .estimateGas(let transactionParameters, let blockNumber): - return [.transaction(transactionParameters), .string(blockNumber.description)] + return [.transaction(transactionParameters), blockNumber.map { .string($0.description) }].compactMap { $0 } case let .sendRawTransaction(hash): return [.string(hash)] diff --git a/Sources/Web3Core/EthereumNetwork/Request/APIRequest.swift b/Sources/Web3Core/EthereumNetwork/Request/APIRequest.swift index cb057da7e..900985171 100644 --- a/Sources/Web3Core/EthereumNetwork/Request/APIRequest.swift +++ b/Sources/Web3Core/EthereumNetwork/Request/APIRequest.swift @@ -96,7 +96,7 @@ public enum APIRequest { /// - Parameters: /// - TransactionParameters: parameters of planned transaction /// - BlockNumber: block where it should be evaluated - case estimateGas(CodableTransaction, BlockNumber) + case estimateGas(CodableTransaction, BlockNumber?) /// Send raw transaction /// - Parameters: diff --git a/Sources/Web3Core/Transaction/CodableTransaction.swift b/Sources/Web3Core/Transaction/CodableTransaction.swift index 1246e2714..ebf706940 100644 --- a/Sources/Web3Core/Transaction/CodableTransaction.swift +++ b/Sources/Web3Core/Transaction/CodableTransaction.swift @@ -240,7 +240,7 @@ extension CodableTransaction: Codable { try containier.encode(gasLimit.hexString, forKey: .gasLimit) } - if let gasPrice = gasPrice, !gasPrice.isZero { + if let gasPrice = gasPrice/*, !gasPrice.isZero*/ { try containier.encode(gasPrice.hexString, forKey: .gasPrice) } @@ -292,10 +292,10 @@ extension CodableTransaction { /// - s: signature s parameter (default 0) - will get set properly once signed /// - parameters: EthereumParameters object containing additional parameters for the transaction like gas public init(type: TransactionType? = nil, to: EthereumAddress, nonce: BigUInt = 0, - chainID: BigUInt = 0, value: BigUInt = 0, data: Data = Data(), + chainID: BigUInt = 0, value: BigUInt = 0, data: Data = Data(), callOnBlock: BlockNumber? = .latest, gasLimit: BigUInt = 0, maxFeePerGas: BigUInt? = nil, maxPriorityFeePerGas: BigUInt? = nil, gasPrice: BigUInt? = nil, accessList: [AccessListEntry]? = nil, v: BigUInt = 1, r: BigUInt = 0, s: BigUInt = 0) { - callOnBlock = .latest + self.callOnBlock = callOnBlock envelope = EnvelopeFactory.createEnvelope(type: type, to: to, nonce: nonce, chainID: chainID, value: value, data: data, gasLimit: gasLimit, maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: maxPriorityFeePerGas, gasPrice: gasPrice, accessList: accessList, v: v, r: r, s: s) } diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/IEth+Defaults.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/IEth+Defaults.swift index 8d695cba2..e70e14f69 100644 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/IEth+Defaults.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/IEth+Defaults.swift @@ -20,7 +20,7 @@ public extension IEth { try await estimateGas(for: transaction, onBlock: .latest) } - func estimateGas(for transaction: CodableTransaction, onBlock: BlockNumber) async throws -> BigUInt { + func estimateGas(for transaction: CodableTransaction, onBlock: BlockNumber?) async throws -> BigUInt { let request = APIRequest.estimateGas(transaction, onBlock) return try await APIRequest.sendRequest(with: provider, for: request).result } diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/IEth.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/IEth.swift index 0ce33372f..fb4468eae 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/IEth.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/IEth.swift @@ -13,7 +13,7 @@ public protocol IEth { func send(_ transaction: CodableTransaction) async throws -> TransactionSendingResult func send(raw data: Data) async throws -> TransactionSendingResult - func estimateGas(for transaction: CodableTransaction, onBlock: BlockNumber) async throws -> BigUInt + func estimateGas(for transaction: CodableTransaction, onBlock: BlockNumber?) async throws -> BigUInt func feeHistory(blockCount: BigUInt, block: BlockNumber, percentiles: [Double]) async throws -> Oracle.FeeHistory func ownedAccounts() async throws -> [EthereumAddress] func getBalance(for address: EthereumAddress, onBlock: BlockNumber) async throws -> BigUInt diff --git a/Sources/web3swift/Web3/Web3+Resolver.swift b/Sources/web3swift/Web3/Web3+Resolver.swift index 1fa3d6299..2f2fafbdd 100644 --- a/Sources/web3swift/Web3/Web3+Resolver.swift +++ b/Sources/web3swift/Web3/Web3+Resolver.swift @@ -88,7 +88,7 @@ public class PolicyResolver { extension PolicyResolver { private func estimateGas(for transaction: CodableTransaction) async throws -> BigUInt { - let request: APIRequest = .estimateGas(transaction, transaction.callOnBlock ?? .latest) + let request: APIRequest = .estimateGas(transaction, transaction.callOnBlock) let response: APIResponse = try await APIRequest.sendRequest(with: provider, for: request) return response.result }