<p>If anyone else need it i post the solution here:</p>
<p><code>Dim seg As JToken = JToken.Parse(&quot;{&quot;&quot;rules&quot;&quot;: [&quot;&quot;segwit&quot;&quot;]}&quot;)</code></p>

CC BY-SA 4.0
2020-07-31T09:37:07.763Z
2020-07-31T09:37:07.763Z
Hamita
<p>I am using
<a href="https://github.com/cryptean/bitcoinlib" rel="nofollow noreferrer">bitcoinlib</a> to communicate with bitcoin-qt</p>
<p>This is the code i tried:</p>
<pre><code> Dim BitcoinService As Services.RpcServices.RpcService.IRpcService = New Services.Coins.Bitcoin.BitcoinService(&quot;http://localhost:8332&quot;, &quot;Username&quot;, &quot;Password&quot;, &quot;wallet password&quot;, 200)
</code></pre>
<p>for <code>getblocktemplate</code> this is the call</p>
<pre><code>   Dim seg As JToken = &quot;{&quot;&quot;rules&quot;&quot;: [&quot;&quot;segwit&quot;&quot;]}&quot;

        RichTextBox5.Text = BitcoinService.GetBlockTemplate(seg).PreviousBlockHash
</code></pre>
<p>It gives me this error</p>
<pre><code>BitcoinLib.ExceptionHandling.Rpc.RpcInternalServerErrorException
  HResult=0x80131500
  Message=JSON value is not an object as expected
  Source=BitcoinLib
  Arborescence des appels de procédure :
   à BitcoinLib.RPC.Connector.RpcConnector.MakeRequest[T](RpcMethods rpcMethod, Object[] parameters)
   à BitcoinLib.Services.CoinService.GetBlockTemplate(Object[] parameters)
   à WindowsApp3.Form1.Button2_Click(Object sender, EventArgs e) dans C:\Users\Hama\source\repos\WindowsApp3\WindowsApp3\Form1.vb :ligne 76
   à System.Windows.Forms.Control.OnClick(EventArgs e)
   à System.Windows.Forms.Button.OnClick(EventArgs e)
   à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   à System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks)
   à System.Windows.Forms.Control.WndProc(Message&amp; m)
   à System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)
   à System.Windows.Forms.Button.WndProc(Message&amp; m)
   à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
   à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
   à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
   à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   à WindowsApp3.My.MyApplication.Main(String[] Args) dans  :ligne 81

  Cette exception a été levée à l'origine dans cette pile des appels :
    System.Net.HttpWebRequest.GetResponse()
    BitcoinLib.RPC.Connector.RpcConnector.MakeRequest&lt;T&gt;(BitcoinLib.RPC.Specifications.RpcMethods, object[])

Exception interne 1 :
WebException : Le serveur distant a retourné une erreur : (500) Erreur interne du serveur.


</code></pre>
<p>I dont understand what i am doing wrong, i think it's a json problem</p>
<p>Help is appreciated, thank you</p>

<bitcoin-core><json-rpc><library>
How to use getblocktemplate method with Bitcoinlib Library
Hamita
# How to use getblocktemplate method with Bitcoinlib Library

(Asked by: username_0 on 2020-07-30)

I am using
[bitcoinlib](https://github.com/cryptean/bitcoinlib) to communicate with bitcoin-qt

This is the code i tried:

```
 Dim BitcoinService As Services.RpcServices.RpcService.IRpcService = New Services.Coins.Bitcoin.BitcoinService("http://localhost:8332", "Username", "Password", "wallet password", 200)

```

for `getblocktemplate` this is the call

```
   Dim seg As JToken = "{""rules"": [""segwit""]}"

        RichTextBox5.Text = BitcoinService.GetBlockTemplate(seg).PreviousBlockHash

```

It gives me this error

```
BitcoinLib.ExceptionHandling.Rpc.RpcInternalServerErrorException
  HResult=0x80131500
  Message=JSON value is not an object as expected
  Source=BitcoinLib
  Arborescence des appels de procédure :
   à BitcoinLib.RPC.Connector.RpcConnector.MakeRequest[T](RpcMethods rpcMethod, Object[] parameters)
   à BitcoinLib.Services.CoinService.GetBlockTemplate(Object[] parameters)
   à WindowsApp3.Form1.Button2_Click(Object sender, EventArgs e) dans C:\Users\Hama\source\repos\WindowsApp3\WindowsApp3\Form1.vb :ligne 76
   à System.Windows.Forms.Control.OnClick(EventArgs e)
   à System.Windows.Forms.Button.OnClick(EventArgs e)
   à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   à System.Windows.Forms.Control.WndProc(Message& m)
   à System.Windows.Forms.ButtonBase.WndProc(Message& m)
   à System.Windows.Forms.Button.WndProc(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   à WindowsApp3.My.MyApplication.Main(String[] Args) dans  :ligne 81

  Cette exception a été levée à l'origine dans cette pile des appels :
    System.Net.HttpWebRequest.GetResponse()
    BitcoinLib.RPC.Connector.RpcConnector.MakeRequest<T>(BitcoinLib.RPC.Specifications.RpcMethods, object[])

Exception interne 1 :
WebException : Le serveur distant a retourné une erreur : (500) Erreur interne du serveur.

```

I dont understand what i am doing wrong, i think it's a json problem

Help is appreciated, thank you

**Tags:** bitcoin-core, json-rpc, library


---

## 1 answers

### Answer by username_0 on 2020-07-31. Score: 0 | Accepted answer

If anyone else need it i post the solution here:

`Dim seg As JToken = JToken.Parse("{""rules"": [""segwit""]}")`


---

