diff --git a/EthereumKit/Classes/Api/Core/RpcBlockchain.swift b/EthereumKit/Classes/Api/Core/RpcBlockchain.swift index a3c8385e..6db34458 100644 --- a/EthereumKit/Classes/Api/Core/RpcBlockchain.swift +++ b/EthereumKit/Classes/Api/Core/RpcBlockchain.swift @@ -162,7 +162,7 @@ extension RpcBlockchain: IBlockchain { syncer.single(rpc: CallJsonRpc(contractAddress: contractAddress, data: data, defaultBlockParameter: defaultBlockParameter)) } - func estimateGas(to: Address, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single { + func estimateGas(to: Address?, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single { syncer.single(rpc: EstimateGasJsonRpc(from: address, to: to, amount: amount, gasLimit: gasLimit, gasPrice: gasPrice, data: data)) } diff --git a/EthereumKit/Classes/Api/JsonRpc/EstimateGasJsonRpc.swift b/EthereumKit/Classes/Api/JsonRpc/EstimateGasJsonRpc.swift index aa6c6979..281b1780 100644 --- a/EthereumKit/Classes/Api/JsonRpc/EstimateGasJsonRpc.swift +++ b/EthereumKit/Classes/Api/JsonRpc/EstimateGasJsonRpc.swift @@ -2,12 +2,14 @@ import BigInt class EstimateGasJsonRpc: IntJsonRpc { - init(from: Address, to: Address, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) { + init(from: Address, to: Address?, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) { var params: [String: Any] = [ - "from": from.hex, - "to": to.hex + "from": from.hex ] + if let to = to { + params["to"] = to.hex + } if let amount = amount { params["value"] = "0x" + amount.serialize().hex.removeLeadingZeros() } diff --git a/EthereumKit/Classes/Core/Kit.swift b/EthereumKit/Classes/Core/Kit.swift index 7b071f5c..81ca3786 100644 --- a/EthereumKit/Classes/Core/Kit.swift +++ b/EthereumKit/Classes/Core/Kit.swift @@ -200,7 +200,7 @@ extension Kit { return blockchain.estimateGas(to: to, amount: resolvedAmount, gasLimit: maxGasLimit, gasPrice: gasPrice, data: nil) } - public func estimateGas(to: Address, amount: BigUInt?, gasPrice: Int?, data: Data?) -> Single { + public func estimateGas(to: Address?, amount: BigUInt?, gasPrice: Int?, data: Data?) -> Single { blockchain.estimateGas(to: to, amount: amount, gasLimit: maxGasLimit, gasPrice: gasPrice, data: data) } diff --git a/EthereumKit/Classes/Core/Protocols.swift b/EthereumKit/Classes/Core/Protocols.swift index 6eb0782d..b6cd4f20 100644 --- a/EthereumKit/Classes/Core/Protocols.swift +++ b/EthereumKit/Classes/Core/Protocols.swift @@ -21,7 +21,7 @@ protocol IBlockchain { func transactionSingle(transactionHash: Data) -> Single func getStorageAt(contractAddress: Address, positionData: Data, defaultBlockParameter: DefaultBlockParameter) -> Single func call(contractAddress: Address, data: Data, defaultBlockParameter: DefaultBlockParameter) -> Single - func estimateGas(to: Address, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single + func estimateGas(to: Address?, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single } protocol IBlockchainDelegate: class { diff --git a/EthereumKit/Classes/Spv/Core/SpvBlockchain.swift b/EthereumKit/Classes/Spv/Core/SpvBlockchain.swift index 84d8a030..53634803 100644 --- a/EthereumKit/Classes/Spv/Core/SpvBlockchain.swift +++ b/EthereumKit/Classes/Spv/Core/SpvBlockchain.swift @@ -110,7 +110,7 @@ extension SpvBlockchain: IBlockchain { // rpcApiProvider.call(contractAddress: contractAddress, data: data, defaultBlockParameter: defaultBlockParameter) } - func estimateGas(to: Address, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single { + func estimateGas(to: Address?, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single { fatalError("Not implemented yet") // rpcApiProvider.getEstimateGas(to: to, amount: amount, gasLimit: gasLimit, gasPrice: gasPrice, data: data) }