I did The ETH transaction with help of web3swift and Infura endpoint. I can't able to get the status of that transaction. I have generated a transaction hash by using the following code.
guard
let fromAddress = walletAddress,
let walletAddress = EthereumAddress(fromAddress),
let toaddress = EthereumAddress(toAddress),
let amountDouble = Web3.Utils.parseToBigUInt(eth, units: .eth),
let gasPrice = Web3.Utils.parseToBigUInt(String(format: "%.10f", gasPrice), units: .eth)
else { throw LocalError.walletError }
var options = TransactionOptions.defaultOptions
options.gasLimit = .manual(BigUInt(gasLimit))
options.from = walletAddress
options.value = amountDouble
options.gasPrice = .manual(gasPrice)
options.to = toaddress
let param: [ AnyObject ] = [toaddress, amountDouble] as [ AnyObject ]
guard
let intermediateSend = self.web3Instance?.contract(Web3.Utils.coldWalletABI, at: toaddress, abiVersion: 2),
let transaction = intermediateSend.write(parameters: param, extraData: Data(), transactionOptions: options),
let walletPassword = mainAccount.walletPassword
else { throw LocalError.walletError }
DispatchQueue.main.async {
NotificationCenter.default.post(name: Notification.transactionInitiated, object: nil)
}
let sendResult = try transaction.send(password: walletPassword)
Log.s(sendResult)
And this is my code for getting a transaction receipt
let receipt = try self.web3Instance.eth.getTransactionReceipt(sendResult.hash)
The receipt was generated after a few seconds. how to get real-time transaction status using web3swift and infura API? Thank you!
You can fetch the receipt of transaction performed at blockchain by calling the
getTransactionReceiptfunction. First of all, you need to convert your hash string to data bytes and then call the function.getTransactionReceiptfunction returns result of typeTransactionReceiptand from receipt you can fetch status, block number, contract address etc...