Nethereum C# how can I get balance in address? - c#

I try to get balance in address.
It is my code:
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nethereum.Web3;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Bananas().Wait();
}
static private async Task Bananas()
{
var publicKey = "0xC0b4ec83028307053Fbe8d00ba4372384fe4b52B";
var web3 = new Nethereum.Web3.Web3("https://ropsten.infura.io/myInfura");
//var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(publicKey);
var balance = await web3.Eth.GetBalance.SendRequestAsync(publicKey);
var etherAmount = Web3.Convert.FromWei(balance.Value);
Console.WriteLine(web3);
Console.WriteLine("Get txCount ", etherAmount);
Console.ReadLine();
}
}
}`
I installed Nethereum via PM console: Nethereum.
I use a normal link of infura.
Why don`t I get a next result without the balance in address?

I have just made a console application with your code and all the data is coming back fine from Nethereum.
Your issue is with your Console.WriteLine(... You are passing the etherAmount as a arg0 property into the Console.WriteLine which will not output correctly on the console when you run it.
Try this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nethereum.Web3;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Bananas().Wait();
}
static private async Task Bananas()
{
var publicKey = "0xC0b4ec83028307053Fbe8d00ba4372384fe4b52B";
var web3 = new Nethereum.Web3.Web3("https://ropsten.infura.io/myInfura");
//var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(publicKey);
var balance = await web3.Eth.GetBalance.SendRequestAsync(publicKey);
var etherAmount = Web3.Convert.FromWei(balance.Value);
Console.WriteLine(web3);
Console.WriteLine("Get txCount " + etherAmount);
Console.ReadLine();
}
}
}
ps nice 1110.337873197299357846 ETH ;) (i know it is only test ETH but we can dream)

Related

Get List of all files from all folder from Azure DataLake using C#

Can we have some example to get list of all files from all folder from Azure Data Lake using .NET(C#).
we are doing in Data factory lookup activity but performance is not good.
we need to check a alternate way to get list of file and write in log folder
Blockquote
Here is how it worked for me
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static async Task Main(string[] args)
{
var account = new CloudStorageAccount(new StorageCredentials("<YOUR ACCOUNT NAME>", "<YOUR CONNECTION STRING>"), true);
var containerName = "<YOUR CONTAINER NAME>";
var blobClient = account.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
BlobContinuationToken token = null;
do
{
var blobPrefix = "";
var useFlatBlobListing = true;
var blobsListingResult = container.ListBlobsSegmentedAsync(blobPrefix, useFlatBlobListing, BlobListingDetails.None, 500, token, null, null);
var blobsList = blobsListingResult.Result;
foreach (var item in blobsList.Results)
{
var blobName = (item as CloudBlob).Name;
Console.WriteLine(blobName);
}
}
while (token != null);
}
}
}
OUTPUT :
REFERENCES
How to list all virtual directories and subdirectories

Console not writing

using System;
using System.Net;
static class Program {
public static void Main()
{
WebClient wc = new WebClient();
var proxies = wc.DownloadString(#"http://proxy-ip-list.com/download/free-proxy-list.txt");
Console.WriteLine("http://" + proxies.Split(';')[5]);
Console.ReadLine();
}
}
I'm very much baffled...
I tried printer Char-by-Char.
I tried assigning the string to a variable before writing.
I've tried everything, what's going on?
Console.WriteLine("http://" + "182.255.46.123:8080"); works...
It's because the string being returned contains a carriage-return character at the beginning:
proxies.Split(';')[5] = " \r182.255.46.123:8080"
You can remove it like this:
Console.WriteLine("http://" + proxies.Split(';')[5].Replace("\r", "").Trim());
Try this:
using System;
using System.Text.RegularExpressions;
using System.Net;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
WebClient wc = new WebClient();
var proxies = wc.DownloadString(#"http://proxy-ip-list.com/download/free-proxy-list.txt");
var regex = new Regex(#"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}");
var match = regex.Matches(proxies);
Console.WriteLine("http://" + match[3].Value);
Console.ReadLine();
}
}
}
Is most save in case of changes in content of the request result.
Updated answer as per your comment. You just need to Trim() to remove all white spaces from start and end.
using System;
using System.Net;
static class Program
{
public static void Main()
{
WebClient wc = new WebClient();
var proxies = wc.DownloadString(#"http://proxy-ip-list.com/download/free-proxy-list.txt");
Console.WriteLine("http://" + proxies.Split(';')[5].Trim());
Console.ReadLine();
}
}

Trying to call R script from c# application

Error in code
cmd result
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using RDotNet;
using Microsoft.Win32;
using System.IO;
using System.Diagnostics;
namespace Con_R2
{
class Program
{
static string rPath = "";
static void Main(string[] args)
{
SetupPath(); // current process, soon to be deprecated
using (REngine engine = REngine.CreateInstance("RDotNet"))
{
engine.Initialize(); // required since v1.5
REngine.SetDllDirectory(rPath);
foreach (string path in engine.Evaluate(".libPaths()").AsCharacter())
{
Console.WriteLine(path);
}
engine.Evaluate(".libPaths(C:\\Program Files\\R\\R-3.3.1\\library)");
engine.Evaluate("source('c:/Program Files/R/R-3.3.1/bin/clustering_loadprofiles.r')");
Console.ReadLine();
Console.ReadKey();
}
}
public static void SetupPath(string Rversion = "R-3.3.1")
{
var oldPath = System.Environment.GetEnvironmentVariable("PATH");
rPath = System.Environment.Is64BitProcess ?
string.Format(#"C:\Program Files\R\{0}\bin\x64", Rversion) :
string.Format(#"C:\Program Files\R\{0}\bin\i386", Rversion);
if (!Directory.Exists(rPath))
throw new DirectoryNotFoundException(
string.Format(" R.dll not found in : {0}", rPath));
var newPath = string.Format("{0}{1}{2}", rPath,
System.IO.Path.PathSeparator, oldPath);
System.Environment.SetEnvironmentVariable("PATH", newPath);
}
}
}
Getting this error
Error in sqlFetch(channel, "sysadmin.loadprofile_allcustomers") :
first argument is not an open RODBC channel In addition: Warning
messages: 1: In RODBC::odbcDriverConnect("DSN=informix116") :
[RODBC] ERROR: state IM014, code 0, message [Microsoft][ODBC Driver
Manager] he specified DSN contains an architecture mismatch between
the Driver and Appl ation 2: In
RODBC::odbcDriverConnect("DSN=informix116") : ODBC connection failed

Inputting values to a string as a website URL for the page to be downloaded

I'm messing around with the System.Net library in C# and I'm trying to simply have it set up such that you enter an url and it will take that as a string and put that into the parameter for the URl in the Client.DownloadString() field.
Here is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace StringDownloadTest
{
class GetInformation
{
string EnterString;
public string InputString()
{
EnterString = Console.ReadLine();
return EnterString;
}
}
class DownloadString
{
static void Main(string[] args)
{
GetInformation R = new GetInformation();
R.InputString();
string downloadedString;
System.Net.WebClient client;
client = new System.Net.WebClient();
downloadedString = client.DownloadString(R.InputString());
Console.WriteLine("String: {0}", downloadedString);
}
}
}
Any help here, it will compile but the program crashes.
You're calling R.InputString twice and only entering input for the first time.
Try:
GetInformation R = new GetInformation();
Console.WriteLine("Please enter a valid url protocol://domain");
var input = R.InputString();
Uri uri;
if(!Uri.TryCreate(input, UriKind.Absolute, out uri))
{
Console.WriteLine("Url format could not be determined for {0}", input);
Environment.Exit(1);
}
var client = new System.Net.WebClient();
var downloadedString = client.DownloadString(uri);
Console.WriteLine("String: {0}", downloadedString);

Error Connecting To MongoDb from C# .NET Console Application

Unable to connect to server localhost:27017:
No connection could be made because the target machine actively refused it 127.0.0.1:27017.
This exception appears when i run a console application with C# using mongoDB
I've downloaded CSharpDriver-1.4.1.4490.msi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace ConsoleApplication4
{
public class Entity
{
public ObjectId Id { get; set; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
var connectionString = "mongodb://localhost:27017";
var server = MongoServer.Create(connectionString);
var database = server.GetDatabase("test");
var collection = database.GetCollection<Entity>("entities");
var entity = new Entity { Name = "Tom" };
collection.Insert(entity);
var id = entity.Id;
var query = Query.EQ("_id", id);
entity = collection.FindOne(query);
entity.Name = "Dick";
collection.Save(entity);
var update = Update.Set("Name", "Harry");
collection.Update(query, update);
collection.Remove(query);
}
}
I would follow the directions here, on the Mongo site. Windows quickstart is a really good resource to get started using Mongo on windows.
As far as connecting to the Mongo instance in .Net, if you didn't do anything special during the installation of Mongo, you shouldn't have to explicitly give a connection string. The following code works for my generic set up of Mongo.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Bson.Serialization.Options;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver.Builders;
using MongoDB.Driver.GridFS;
using MongoDB.Driver.Wrappers;
namespace MongoDB
{
class Program
{
static void Main(string[] args)
{
MongoServer server;
MongoDatabase moviesDb;
server = MongoServer.Create();
moviesDb = server.GetDatabase("movies_db");
//Create some data
var movie1 = new Movie { Title = "Indiana Jones and the Raiders of the Lost Ark", Year = "1981" };
movie1.AddActor("Harrison Ford");
movie1.AddActor("Karen Allen");
movie1.AddActor("Paul Freeman");
var movie2 = new Movie { Title = "Star Wars: Episode IV - A New Hope", Year = "1977" };
movie2.AddActor("Mark Hamill");
movie2.AddActor("Harrison Ford");
movie2.AddActor("Carrie Fisher");
var movie3 = new Movie { Title = "Das Boot", Year = "1981" };
movie3.AddActor("Jürgen Prochnow");
movie3.AddActor("Herbert Grönemeyer");
movie3.AddActor("Klaus Wennemann");
//Insert the movies into the movies_collection
var moviesCollection = moviesDb.GetCollection<Movie>("movies_collection");
//moviesCollection.Insert(movie1);
//moviesCollection.Insert(movie2);
//moviesCollection.Insert(movie3);
var query = Query.EQ("Year","1981");
var movieFound = moviesDb.GetCollection<Movie>("movies_collection").Drop();
}
}
}

Categories