How to use curl to access the Counterparty API from Windows


#1

On Linux it’s easy because examples you see out there are usually correct (for Linux). Not so for Windows.

This FAQ only shows how to use curl to execute one API call, to give you an idea of what needs to be done.

Let’s say we have a transaction like this:

{
"method": "create_send",
"params": {
"source": "1AbgbDkm3TD3prVWKxu8DcxvAN6zttpQMA", 
"destination": "19w9LciXjWi1Cch7pdXdrezWZ8x4wgpVVB",
"asset": "XCP", 
"quantity": 53572727273},
"jsonrpc": "2.0",
"id": 1
}

The easiest way is to get a browser add-on or plugin that lets you send this to the API server such as coindaddy.io, but you can also use curl.

  • Get the latest curl for Windows (32, 64 bit, whatever you use). No need to get the SSL version, but it’s up to you.
  • Enter your own details in the transaction (although for testing purposes you can use the one above)
  • Transform the above JSON file into single line without screwing it up. To do that, remove line breaks while not removing other content. Additionally - the key part for Windows - you must add the backward slash before each double quote character in the JSON line. So that "stuff" becomes "“stuff”`. You can paste the thing in Wordpad and replace all " with " or do it manually.
  • Now you can run it with curl. Open the CLI on Windows, navigate to your curl.exe directory (or not, if curl.exe is already in your PATH) using the cd command. For example, cd \user\myname\tools\
  • Now compose the curl action by inserting your part between 2 “generic” parts:
  • Paste into the console curl.exe --user rpc:1234 -H "Content-Type: application/json; charset=UTF-8" -H "Accept:application/json, text/javascript" --data without hitting ENTER
  • After that, paste the one-line JSON
  • After that, add http://public.coindaddy.io:4000/api/ (this is one mainnet API endpoint that’s currently available for public use (testnet port is 14000). You could use your own or some other server.)

This is what a working command, tested with curl 7.52.1 (without SSL( on Windows 10, looks like. You can paste it in your console and execute to see the returned raw unsigned transaction (you can’t do much with it unless you have the private key for the sending address).

curl.exe --user rpc:1234 -H "Content-Type: application/json; charset=UTF-8" -H "Accept:application/json, text/javascript" --data "{\"method\": \"create_send\", \"params\": { \"source\": \"1AbgbDkm3TD3prVWKxu8DcxvAN6zttpQMA\", \"destination\": \"19w9LciXjWi1Cch7pdXdrezWZ8x4wgpVVB\", \"asset\": \"XCP\", \"quantity\": 53572727273}, \"jsonrpc\": \"2.0\", \"id\": 1 }" http://public.coindaddy.io:4000/api/

After this you would sign and send using a Bitcoin wallet or the API / CLI. That is explained in other topics of this Web site.

One advantage of composing your own transactions may be that you may be having some issues with the wallet (or Counterwallet server may be down) or you may want to set a custom transaction fee, etc.

Keywords: Windows, curl, Counterparty, API


Sweep Private Keys- Issue
How to cancel pending trades?
Node installation error (windows)
How to claim XCP?