<p><strong>The electrum public key</strong> <code>xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd</code> is a <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys" rel="noreferrer">BIP32 extended public key</a>. This can be used to derive child addresses.</p>

<p><strong>The Bitcoin-Core public key</strong> <code>037acd3408dfb612a69204c5f5bafe2a326646398cdd16c85fedd65a4e96a28278</code> is a hex representation of the <a href="https://bitcoin.stackexchange.com/questions/3059/what-is-a-compressed-bitcoin-key">compressed form of a public key</a>.</p>

<p>In order to convert to from the extended to compressed format, all you need to do is decode from <a href="https://en.bitcoin.it/wiki/Base58Check_encoding" rel="noreferrer">Base58Check</a> and grab the last 33 bytes (32 for private keys). I'm sure there's an implementation in PHP for Base58Check decoding. See <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format" rel="noreferrer">BIP32 - Extended Key Serialization</a>:</p>

<p><code>$ printf "xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd" | base58 -dc | xxd -p 0488b21e0000000000000000009f8b20f34eceef6ea60d35db00446763f7 dc76bd60ec8cf6fd63dc912499cbd4039edccce0e93f436a283947412378 8b33a28ed7ad7cffc3a130889f232344ad1c</code></p>

<p>The last 33 bytes represent the hex version of the compressed public key (last 32 bytes for private keys).</p>

<p><code>039edccce0e93f436a2839474123788b33a28ed7ad7cffc3a130889f232344ad1c</code></p>

CC BY-SA 4.0
2018-11-05T19:22:46.730Z
2018-11-05T19:22:46.730Z
JBaczuk
<p>I am experiencing some major issues which I honestly can't understand.
When I am generating a wallet from Electrum the public key looks like this: <code>xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd</code></p>

<p>When I am generating a wallet address from bitcoin core rpc, the public key looks like this: <code>037acd3408dfb612a69204c5f5bafe2a326646398cdd16c85fedd65a4e96a28278</code></p>

<p>When I am trying to create a multisig address in the core using this type of public keys, I get errror: <code>xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd</code></p>

<p>When I am trying to create a multisig address in the core ( via PHP ) using this type of public keys, it works: <code>037acd3408dfb612a69204c5f5bafe2a326646398cdd16c85fedd65a4e96a28278</code></p>

<p>I am super confused. </p>

<p>I am developing a multisig system for bitcoin, but it seems that I can't do it, since the clients will almost always use this type of public key generated from Electrum: <code>xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd</code></p>

<p>Is there any type of conversion way in PHP from this type of public key:  <code>xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd</code> to this type: <code>037acd3408dfb612a69204c5f5bafe2a326646398cdd16c85fedd65a4e96a28278</code> ? 
I am trying to understand what I am doing wrong</p>

<p>Thank you for your time, and hope to get an answer!</p>

<bitcoin-core><blockchain><bitcoind><public-key><xpub>
Converting xpub key to core format
L. Mark
# Converting xpub key to core format

(Asked by: username_0 on 2018-11-05)

I am experiencing some major issues which I honestly can't understand.
When I am generating a wallet from Electrum the public key looks like this: `xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd`

When I am generating a wallet address from bitcoin core rpc, the public key looks like this: `037acd3408dfb612a69204c5f5bafe2a326646398cdd16c85fedd65a4e96a28278`

When I am trying to create a multisig address in the core using this type of public keys, I get errror: `xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd`

When I am trying to create a multisig address in the core ( via PHP ) using this type of public keys, it works: `037acd3408dfb612a69204c5f5bafe2a326646398cdd16c85fedd65a4e96a28278`

I am super confused.

I am developing a multisig system for bitcoin, but it seems that I can't do it, since the clients will almost always use this type of public key generated from Electrum: `xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd`

Is there any type of conversion way in PHP from this type of public key: `xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd` to this type: `037acd3408dfb612a69204c5f5bafe2a326646398cdd16c85fedd65a4e96a28278` ?
I am trying to understand what I am doing wrong

Thank you for your time, and hope to get an answer!

**Tags:** bitcoin-core, blockchain, bitcoind, public-key, xpub


---

## 1 answers

### Answer by username_1 on 2018-11-05. Score: 6

**The electrum public key** `xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd` is a [BIP32 extended public key](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys). This can be used to derive child addresses.

**The Bitcoin-Core public key** `037acd3408dfb612a69204c5f5bafe2a326646398cdd16c85fedd65a4e96a28278` is a hex representation of the [compressed form of a public key](https://bitcoin.stackexchange.com/questions/3059/what-is-a-compressed-bitcoin-key).

In order to convert to from the extended to compressed format, all you need to do is decode from [Base58Check](https://en.bitcoin.it/wiki/Base58Check_encoding) and grab the last 33 bytes (32 for private keys). I'm sure there's an implementation in PHP for Base58Check decoding. See [BIP32 - Extended Key Serialization](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format):

`$ printf "xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd" | base58 -dc | xxd -p 0488b21e0000000000000000009f8b20f34eceef6ea60d35db00446763f7 dc76bd60ec8cf6fd63dc912499cbd4039edccce0e93f436a283947412378 8b33a28ed7ad7cffc3a130889f232344ad1c`

The last 33 bytes represent the hex version of the compressed public key (last 32 bytes for private keys).

`039edccce0e93f436a2839474123788b33a28ed7ad7cffc3a130889f232344ad1c`


---

