/// <summary> /// Creates a 'ClaimTransaction', signs it and send a 'sendrawtransaction' RPC call to the connected node. /// This method does not put gas into claimable state. Can only claim 'unclaimable' amount. /// </summary> /// <returns></returns> public override async Task <ClaimTransaction> ClaimGas(UInt160 changeAddress = null) { var(claimable, amount) = await TransactionBuilderHelper.GetClaimable(AddressScriptHash.ToAddress(), _restService); if (amount <= 0) { throw new WalletException("No GAS available to claim at this address"); } var tx = new ClaimTransaction(); var references = new List <CoinReference>(); foreach (var entry in claimable) { references.Add(new CoinReference { PrevHash = UInt256.Parse(entry.Txid), PrevIndex = (ushort)entry.N, }); } if (changeAddress == null) { changeAddress = AddressScriptHash; } var outputs = new List <TransactionOutput> { new TransactionOutput { ScriptHash = changeAddress, AssetId = Utils.GasToken, Value = Fixed8.FromDecimal(amount), } }; tx.Version = 0; tx.Claims = references.ToArray(); tx.Inputs = new CoinReference[0]; tx.Outputs = outputs.ToArray(); tx.Attributes = new TransactionAttribute[0]; var result = await SignAndSendTransaction(tx); return(result ? tx : null); }