Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string RequestServer(string methodName, List<string> parameters)
- {
- string ServerIp = "http://localhost:18332";
- string UserName = "user name goes here";
- string Password = "password goes here";
- HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(ServerIp);
- webRequest.Credentials = new NetworkCredential(UserName, Password);
- webRequest.ContentType = "application/json-rpc";
- webRequest.Method = "POST";
- string respVal = string.Empty;
- JObject joe = new JObject();
- joe.Add(new JProperty("jsonrpc", "1.0"));
- joe.Add(new JProperty("id", "1"));
- joe.Add(new JProperty("method", methodName));
- JArray props = new JArray();
- foreach (var parameter in parameters)
- {
- props.Add(parameter);
- }
- joe.Add(new JProperty("params", props));
- // serialize json for the request
- string s = JsonConvert.SerializeObject(joe);
- byte[] byteArray = Encoding.UTF8.GetBytes(s);
- webRequest.ContentLength = byteArray.Length;
- Stream dataStream = webRequest.GetRequestStream();
- dataStream.Write(byteArray, 0, byteArray.Length);
- dataStream.Close();
- StreamReader streamReader = null;
- try
- {
- WebResponse webResponse = webRequest.GetResponse();
- streamReader = new StreamReader(webResponse.GetResponseStream(), true);
- respVal = streamReader.ReadToEnd();
- var data = JsonConvert.DeserializeObject(respVal).ToString();
- return data;
- }
- catch (Exception exp)
- {
- throw (exp);
- }
- finally
- {
- if (streamReader != null)
- {
- streamReader.Close();
- }
- }
- return string.Empty;
- }
- double AmountToSend = Convert.ToDouble(txtAmountToSend.Text);
- string ReceivingAddress = txtSendToAddress.Text;
- JObject data = JObject.Parse(RequestServer("sendtoaddress", new List<string>() { ReceivingAddress, Convert.ToString(AmountToSend) }));
- listunspent
- listunspent 1000
Add Comment
Please, Sign In to add comment