0

I have been coding a bot that accept crypto payments to update balance for user. Checking balance is fine; works great.

When it runs the check command to check if positive balance it then needs to transfer that balance to another wallet.

I am using two addresses of which I control both private keys for testing. I have topped up $5 worth of ETH.

When it runs the send transaction command, I get these errors:

1/2 inner exception

HttpRequestException: No connection could be made because the target machine actively refused it.

2/2 inner exception

SocketException: No connection could be made because the target machine actively refused it.

Here is the method I am running:

private static async void check(String id)
    {
        string[] data = readdata(id);
        var publicKey = data[2];
        var privateKey = data[3];
        var web3 = new Nethereum.Web3.Web3("https://mainnet.infura.io/v3/APIKEY");
        var txCount = web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync(publicKey);
        var balance = web3.Eth.GetBalance.SendRequestAsync(publicKey);
        var etherAmount = Web3.Convert.FromWei(balance.Result);
        Console.WriteLine(etherAmount);
        var account = new Account(privateKey);
        var web33 = new Web3(account);
        var toAddress = "0xEee945DE85Af571940324De312D5077843767A1F";
        var transaction = await web33.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(toAddress, 1.11m);
        Console.WriteLine(transaction.Status);
    }
TylerH
  • 20,799
  • 66
  • 75
  • 101
lito
  • 11
  • 1
  • You probably did not close the first connection which is preventing a second connection with same destination. Put code into a using block so it gets dispose when you exit the using block. – jdweng Jun 15 '21 at 17:30
  • @jdweng around the web3 statement? it says it must be convertable to iDisposable for that and throws me a red line – lito Jun 15 '21 at 17:44
  • i just had a thought, i am not running an ETH node so must i point at infura for example? i belive currently it may be pointing at localhost:8545 – lito Jun 15 '21 at 17:49

1 Answers1

0

OP's solution migrated from the question to an answer:

I solved it by pointing the RPC at infura again like the top one, I wasn't aware it had to either run a local node or point to external API:

var web33 = new Web3(account, "https://mainnet.infura.io/v3/APIKEY
TylerH
  • 20,799
  • 66
  • 75
  • 101