Bitcoin Forum
November 08, 2024, 08:09:11 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: API C# call to sendtoaddress fails!  (Read 1303 times)
lakingsfan12 (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
October 09, 2012, 09:05:22 PM
 #1

Hi..  Im hoping someone here knows what i am doing wrong. Some of my calls work, but most return 500, so im confused what is wrong.

I really appreciate the help and feedback.

Here is code that works:

Code:
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
            webRequest.Credentials = new NetworkCredential("bitcoinrpc", "mypassword");
            /// important, otherwise the service can't desirialse your request properly
            webRequest.ContentType = "application/json-rpc";
            webRequest.Method = "POST";

            JObject joe = new JObject();
            joe.Add(new JProperty("jsonrpc", "1.0"));
            joe.Add(new JProperty("id", "1"));
            joe.Add(new JProperty("method", "listsinceblock"));

            JArray props = new JArray();
            if (_lastBlock != "")
            {
                props.Add(_lastBlock);
            }
            joe.Add(new JProperty("params", props));
            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();


            WebResponse webResponse = webRequest.GetResponse();

Basically, im looping and calling this to find new transactions that I am receiving.

However, when I go to send a transaction out:

Code:
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
            webRequest.Credentials = new NetworkCredential("bitcoinrpc", "mypassword");
            /// important, otherwise the service can't desirialse your request properly
            webRequest.ContentType = "application/json-rpc";
            webRequest.Method = "POST";

            JObject joe = new JObject();
            joe.Add(new JProperty("jsonrpc", "1.0"));
            joe.Add(new JProperty("id", "1"));
            joe.Add(new JProperty("method", "sendtoaddress"));

            JArray props = new JArray();
            props.Add("1diceDCd27Cc22HV3qPNZKwGnZ8QwhLTc");
            props.Add("0.001");
            joe.Add(new JProperty("params", props));
            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();


           WebResponse webResponse = webRequest.GetResponse();

I get a 500 error..  can anyone tell me what I am doing wrong?  I am able to make the call from the commandline with no problem.  I'm stumped and can't find any help anywhere on what could be wrong.

Thanks!

Kingsfan
gweedo
Legendary
*
Offline Offline

Activity: 1498
Merit: 1000


View Profile
October 09, 2012, 09:09:18 PM
 #2

Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
that should be
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8332");
or
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8332");
lakingsfan12 (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
October 09, 2012, 09:12:13 PM
 #3

Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
that should be
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8332");
or
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8332");

Thanks Gweedo, but that actually doesnt matter "localhost." will resolve to "localhost" will resolve to 127.0.0.1.  The 500 error happens on the GetRequest and works fine for the listsinceblock, getinfo, getbalance, etc. Just doesnt seem to work so far for sendtoaddress, sendmany, walletpassphrase - ive given up trying to see which works and which doesnt until I can get some clarity as to what other fields I might be missing.
gweedo
Legendary
*
Offline Offline

Activity: 1498
Merit: 1000


View Profile
October 09, 2012, 10:01:30 PM
 #4

Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
that should be
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8332");
or
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8332");

Thanks Gweedo, but that actually doesnt matter "localhost." will resolve to "localhost" will resolve to 127.0.0.1.  The 500 error happens on the GetRequest and works fine for the listsinceblock, getinfo, getbalance, etc. Just doesnt seem to work so far for sendtoaddress, sendmany, walletpassphrase - ive given up trying to see which works and which doesnt until I can get some clarity as to what other fields I might be missing.

Sounds like your wallet is probably encrypted, so you need to pass in the wallet password as well.
lakingsfan12 (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
October 10, 2012, 01:34:31 AM
 #5

Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
that should be
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8332");
or
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8332");

Thanks Gweedo, but that actually doesnt matter "localhost." will resolve to "localhost" will resolve to 127.0.0.1.  The 500 error happens on the GetRequest and works fine for the listsinceblock, getinfo, getbalance, etc. Just doesnt seem to work so far for sendtoaddress, sendmany, walletpassphrase - ive given up trying to see which works and which doesnt until I can get some clarity as to what other fields I might be missing.

Sounds like your wallet is probably encrypted, so you need to pass in the wallet password as well.

Well, it wasn't at first.  I did put a passphrase on it now.  But even when I call walletpassphrase, it fails.  Does anyone have a working c# solution project they can share with me?

Thanks
gweedo
Legendary
*
Offline Offline

Activity: 1498
Merit: 1000


View Profile
October 10, 2012, 01:36:06 AM
 #6

Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
that should be
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8332");
or
Code:
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8332");

Thanks Gweedo, but that actually doesnt matter "localhost." will resolve to "localhost" will resolve to 127.0.0.1.  The 500 error happens on the GetRequest and works fine for the listsinceblock, getinfo, getbalance, etc. Just doesnt seem to work so far for sendtoaddress, sendmany, walletpassphrase - ive given up trying to see which works and which doesnt until I can get some clarity as to what other fields I might be missing.

Sounds like your wallet is probably encrypted, so you need to pass in the wallet password as well.

Well, it wasn't at first.  I did put a passphrase on it now.  But even when I call walletpassphrase, it fails.  Does anyone have a working c# solution project they can share with me?

Thanks

https://github.com/mb300sd/Bitcoin.NET
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!