I'm trying to post to a local bitcoin-qt via json-rpc but I'm getting error 500 from the server.
Following the documentation here
I tried this code but it's giving the error 500, it works fine with other methods like getblockcount
or getnewaddress
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim jArray As JContainer = New JArray() '
Dim jToTx As New JObject
jToTx.Add("Tbc1q5t4sexcufx9ecnepfd4v88j8fvq3q5ymzetmqt", "6.5")
Dim jArray2 As JContainer = New JArray From {jToTx}
Dim jFromTx As New JObject
jFromTx.Add("txid", "0000000000000000000000000000000000000000000000000000000000000000")
jFromTx.Add("vout", "0")
jArray.Add(jFromTx)
RichTextBox5.Text = RequestServer("createrawtransaction", New List(Of JToken) From {jArray, jArray2})
End Sub
RequestServer Function:
Public Shared Function RequestServer(ByVal methodName As String, ByVal parameters As List(Of JToken)) As JToken
Dim ServerIp As String = "http://localhost:8332"
Dim UserName As String = "hama"
Dim Password As String = "hama"
Dim webRequest As HttpWebRequest = CType(webRequest.Create(ServerIp), HttpWebRequest)
webRequest.Credentials = New NetworkCredential(UserName, Password)
webRequest.ContentType = "application/json-rpc"
webRequest.Method = "POST"
Dim respVal As String = String.Empty
Dim joe As JObject = New JObject
joe.Add(New JProperty("jsonrpc", 1))
joe.Add(New JProperty("id", 1))
joe.Add(New JProperty("method", methodName))
Dim props As JArray = New JArray
For Each parameter In parameters
props.Add(parameter)
Next
joe.Add(New JProperty("params", props))
' serialize json for the request
Dim s As String = JsonConvert.SerializeObject(joe)
Dim byteArray() As Byte = Encoding.UTF8.GetBytes(s)
webRequest.ContentLength = byteArray.Length
Dim dataStream As Stream = webRequest.GetRequestStream
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim streamReader As StreamReader = Nothing
Try
Dim webResponse As WebResponse = webRequest.GetResponse
streamReader = New StreamReader(webResponse.GetResponseStream, True)
respVal = streamReader.ReadToEnd
Dim data = JsonConvert.DeserializeObject(respVal).ToString
Return data
Catch exp As Exception
MsgBox(exp.ToString)
Finally
If (Not (streamReader) Is Nothing) Then
streamReader.Close()
End If
End Try
Return String.Empty
End Function
My bitcoin.conf
server=1
rpcuser=hama
rpcpassword=hama
rpcallowip=127.0.0.1
rpcport=8332
The error code from catch block:
System.Net.WebException
HResult = 0x80131509
Message = The remote server returned an error: (500) Internal server error.
Source = WindowsApp3
Procedure call tree:
to WindowsApp3.Form1.RequestServer (String methodName, List`1 parameters) in C: \ Users \ Hama \ source \ repos \ WindowsApp3 \ WindowsApp3 \ Form1.vb: line 170
to WindowsApp3.Form1.Button1_Click (Object sender, EventArgs e) in C: \ Users \ Hama \ source \ repos \ WindowsApp3 \ WindowsApp3 \ Form1.vb: line 40
at System.Windows.Forms.Control.OnClick (EventArgs e)
at System.Windows.Forms.Button.OnClick (EventArgs e)
at System.Windows.Forms.Button.OnMouseUp (MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp (Message & m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc (Message & m)
at System.Windows.Forms.ButtonBase.WndProc (Message & m)
at System.Windows.Forms.Button.WndProc (Message & m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message & m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m)
at System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG & msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun ()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel ()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run (String [] commandLine)
to WindowsApp3.My.MyApplication.Main (String [] Args) in: line 81
Help will be appreciated, thank you
User contributions licensed under CC BY-SA 3.0