<p><code>importpubkey</code> imports a public key, not a scriptPubKey.</p>
<p>A public key in this context is a 66 character hexadecimal string starting with 02 or 03, or a 130 character hexadecimal string starting with 04. It encodes a secp256k1 public key. A scriptPubKey is any hexadecimal string, and encodes a locking script. These are distinct things; you can't use one in place of the other.</p>
<p>In this case, it appears you want to import an address. You can do so directly using <code>importaddress</code>.</p>

CC BY-SA 4.0
2022-03-27T05:48:31.063Z
and a scriptpubkey _for P2PKH_ as in this Q _includes_ the address (in binary or hex rather than base58check) but from the address (in any form) you can't backtrack to the pubkey
dave_thompson_085
CC BY-SA 4.0
2022-03-26T20:22:29.650Z
2022-03-26T20:22:29.650Z
Pieter Wuille
<p>I have been trying to import a public key into my bitcoin[1] node, but it keeps saying that it isn't valid.</p>
<p>The address '18uLJohita1yWTAcDpoLPpd2vNAtnsLW4E' publishes front-pages of the New York times into the BSV ledger and I want to add its public key to my bitcoin server so I can see new UTXOs. The key must be in HEX, per the command.</p>
<blockquote>
<p>bitcoin-cli validateaddress 18uLJohita1yWTAcDpoLPpd2vNAtnsLW4E</p>
</blockquote>
<p>{
&quot;isvalid&quot;: true,
&quot;address&quot;: &quot;18uLJohita1yWTAcDpoLPpd2vNAtnsLW4E&quot;,
&quot;scriptPubKey&quot;: &quot;76a91456aea08d8feaefb18222fcef953366da2a7f200588ac&quot;,
&quot;ismine&quot;: false,
&quot;iswatchonly&quot;: false,
&quot;isscript&quot;: false
}</p>
<blockquote>
<p>bitcoin-cli importpubkey 76a91456aea08d8feaefb18222fcef953366da2a7f200588ac
error code: -5
error message:
Pubkey is not a valid public key</p>
</blockquote>
<p>It accepts that I have sent hex, but it doesn't like it. This is clearly more than just the public key, I can see that from a vout:</p>
<p>&quot;asm&quot;: &quot;OP_DUP OP_HASH160 56aea08d8feaefb18222fcef953366da2a7f2005 OP_EQUALVERIFY # OP_CHECKSIG&quot;,</p>
<p>So maybe it wants me to remove the OP_DUP, OP_HASH160 and OP_EQUALVERIFY:</p>
<blockquote>
<p>bitcoin-cli importpubkey 56aea08d8feaefb18222fcef953366da2a7f2005
Pubkey is not a valid public key</p>
</blockquote>
<p>Hmm? Maybe it wants the checksum at the end...</p>
<blockquote>
<p>echo 18uLJohita1yWTAcDpoLPpd2vNAtnsLW4E | base58 -d | xxd -p
0056aea08d8feaefb18222fcef953366da2a7f200559461147
bitcoin-cli importpubkey 0056aea08d8feaefb18222fcef953366da2a7f200559461147
error code: -5
error message:
Pubkey is not a valid public key</p>
</blockquote>
<p>I them write a bigendian reversal script and tried it, didn't help either.</p>
<p>I am official stumped.</p>
<p>Thanks in advance.</p>
<p>[1] I currently run bitcoin.sv and digibyte and have the same problem on both.</p>

CC BY-SA 4.0
2022-03-27T12:44:02.963Z
I was considering to close this question as off-topic because the user was asking about problems using altcoin software. However, since the question appears to have been based on a usage error that also applies to Bitcoin Core, I voted to reopen it.
Murch
<utxo><importaddress>
I can't figure out how to use importpubkey
John Rigler
# I can't figure out how to use importpubkey

(Asked by: username_0 on 2022-03-26)

I have been trying to import a public key into my bitcoin[1] node, but it keeps saying that it isn't valid.

The address '18uLJohita1yWTAcDpoLPpd2vNAtnsLW4E' publishes front-pages of the New York times into the BSV ledger and I want to add its public key to my bitcoin server so I can see new UTXOs. The key must be in HEX, per the command.

> bitcoin-cli validateaddress 18uLJohita1yWTAcDpoLPpd2vNAtnsLW4E

{
"isvalid": true,
"address": "18uLJohita1yWTAcDpoLPpd2vNAtnsLW4E",
"scriptPubKey": "76a91456aea08d8feaefb18222fcef953366da2a7f200588ac",
"ismine": false,
"iswatchonly": false,
"isscript": false
}

> bitcoin-cli importpubkey 76a91456aea08d8feaefb18222fcef953366da2a7f200588ac
> error code: -5
> error message:
> Pubkey is not a valid public key

It accepts that I have sent hex, but it doesn't like it. This is clearly more than just the public key, I can see that from a vout:

"asm": "OP\_DUP OP\_HASH160 56aea08d8feaefb18222fcef953366da2a7f2005 OP\_EQUALVERIFY # OP\_CHECKSIG",

So maybe it wants me to remove the OP\_DUP, OP\_HASH160 and OP\_EQUALVERIFY:

> bitcoin-cli importpubkey 56aea08d8feaefb18222fcef953366da2a7f2005
> Pubkey is not a valid public key

Hmm? Maybe it wants the checksum at the end...

> echo 18uLJohita1yWTAcDpoLPpd2vNAtnsLW4E | base58 -d | xxd -p
> 0056aea08d8feaefb18222fcef953366da2a7f200559461147
> bitcoin-cli importpubkey 0056aea08d8feaefb18222fcef953366da2a7f200559461147
> error code: -5
> error message:
> Pubkey is not a valid public key

I them write a bigendian reversal script and tried it, didn't help either.

I am official stumped.

Thanks in advance.

[1] I currently run bitcoin.sv and digibyte and have the same problem on both.

**Tags:** utxo, importaddress

> **Comments:**
> **username_1**: I was considering to close this question as off-topic because the user was asking about problems using altcoin software. However, since the question appears to have been based on a usage error that also applies to Bitcoin Core, I voted to reopen it.  

---

## 1 answers

### Answer by username_2 on 2022-03-26. Score: 3

`importpubkey` imports a public key, not a scriptPubKey.

A public key in this context is a 66 character hexadecimal string starting with 02 or 03, or a 130 character hexadecimal string starting with 04. It encodes a secp256k1 public key. A scriptPubKey is any hexadecimal string, and encodes a locking script. These are distinct things; you can't use one in place of the other.

In this case, it appears you want to import an address. You can do so directly using `importaddress`.

> **Comments:**
> **username_3**: and a scriptpubkey _for P2PKH_ as in this Q _includes_ the address (in binary or hex rather than base58check) but from the address (in any form) you can't backtrack to the pubkey  

---

