Esempio n. 1
0
        public async Task <RopstenRequest> GetRopstenERC20Transactions()
        {
            var url     = NethereumConfig.ROPSTEN_ERC20_TRANSACTIONS(NethereumConfig.WALLET_B);
            var request = await url.GetAsyncRopstenRequest();

            return(request);
        }
Esempio n. 2
0
        public async Task <String> SendOfflineERC20Token(string fromWallet, string toWallet, int tokenAmount, int maxNonce = 500)
        {
            var hexAmount        = tokenAmount.DecimalToHexadecimal();
            var functionInput    = new object[] { toWallet, hexAmount };
            var transferFunction = _contract.GetFunction("transfer");
            var data             = transferFunction.GetData(functionInput);
            var txCount          = await _web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(NethereumConfig.CONTRACT_ADDRESS);

            var trxId   = "";
            var message = "";
            var nonce   = txCount.Value;

            while (nonce < maxNonce)
            {
                try
                {
                    var encoded = Web3.OfflineTransactionSigner
                                  .SignTransaction(
                        NethereumConfig.GetPrivateKey(fromWallet), // SIGN WITH PRIVATE KEY
                        NethereumConfig.CONTRACT_ADDRESS,          // SEND TRX TO CONTRACT
                        0,                                         // VALUE OF ETH - In this case, we aren't transferring ETH
                        nonce,                                     // NONCE
                        new HexBigInteger("400000"),               // GAS PRICE
                        new HexBigInteger("400000"),               // GAS LIMIT
                        data                                       // CONTRACT DATA
                        );

                    // SIGN TRANSACTION
                    var verifyAddress = Web3.OfflineTransactionSigner.GetSenderAddress(encoded);
                    trxId = await _web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + encoded);

                    break;
                }
                catch (Exception ex)
                {
                    message = ex.Message;

                    while (ex.InnerException != null)
                    {
                        ex       = ex.InnerException;
                        message += "\n" + ex.Message;
                    }

                    if (!message.Contains("nonce") && !message.Contains("underpriced"))
                    {
                        throw new Exception(message);
                    }

                    nonce++;
                }
            }

            return(trxId);
        }