importpubkey
Overview
The 'importpubkey' method allows you to Add a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.
Request
- shell
- csharp
- php
- python
- javascript
- go
- ruby
- java
wget --no-check-certificate --quiet \
--method POST \
--timeout=0 \
--header 'Content-Type: application/json' \
--header 'accept: application/json' \
--header 'X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY' \
--body-data '{"jsonrpc":"2.0","id":1,"method":"importpubkey","params": [ ]}' \
'https://bitcoin-mainnet.node.coinapi.io'
var options = new RestClientOptions("https://bitcoin-mainnet.node.coinapi.io")
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("", Method.Post);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("accept", "application/json");
request.AddHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY");
var body = @"{""jsonrpc"":""2.0"",""id"":1,""method"":""importpubkey"",""params"": [ ]}";
request.AddStringBody(body, DataFormat.Json);
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
<?php
$client = new Client();
$headers = [
'Content-Type' => 'application/json',
'accept' => 'application/json',
'X-CoinAPI-Key' => '73034021-THIS-IS-SAMPLE-KEY'
];
$body = '{
"jsonrpc": "2.0",
"id": 1,
"method": "importpubkey",
"params": []
}';
$request = new Request('POST', 'https://bitcoin-mainnet.node.coinapi.io', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
?>
import http.client
import json
conn = http.client.HTTPSConnection("mainnet-bitcoin.node.coinapi.io")
payload = json.dumps({
"jsonrpc": "2.0",
"id": 1,
"method": "importpubkey",
"params": []
})
headers = {
'Content-Type': 'application/json',
'accept': 'application/json',
'X-CoinAPI-Key': '73034021-THIS-IS-SAMPLE-KEY'
}
conn.request("POST", "/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
var settings = {
"url": "https://bitcoin-mainnet.node.coinapi.io",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"accept": "application/json",
"X-CoinAPI-Key": "73034021-THIS-IS-SAMPLE-KEY"
},
"data": JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "importpubkey",
"params": []
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://bitcoin-mainnet.node.coinapi.io"
method := "POST"
payload := strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"importpubkey","params": [ ]}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("accept", "application/json")
req.Header.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require "uri"
require "json"
require "net/http"
url = URI("https://bitcoin-mainnet.node.coinapi.io")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["accept"] = "application/json"
request["X-CoinAPI-Key"] = "73034021-THIS-IS-SAMPLE-KEY"
request.body = JSON.dump({
"jsonrpc": "2.0",
"id": 1,
"method": "importpubkey",
"params": []
})
response = https.request(request)
puts response.read_body
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"importpubkey\",\"params\": [ ]}");
Request request = new Request.Builder()
.url("https://bitcoin-mainnet.node.coinapi.io")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("accept", "application/json")
.addHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
.build();
Response response = client.newCall(request).execute();
Request Parameters
- pubkey: The hex-encoded public key
- label: An optional label
- rescan: Rescan the wallet for transactions
Response
{
// Response structure here
}
Was this section helpful?