Using peercoin with Bitcore

There was a thread on this a while ago, but I thought I’d make a new one instead of bumping the old one.

Bitcore is a javascript library for doing a bunch of different things for bitcoin. It was written by bitpay, and its pretty good. Looking at the source code, it seems that the developers did a pretty good job of writing it so altcoins can be easiely supported.

https://github.com/bitpay/bitcore/blob/master/lib/networks.js#L89

That link above points to a point in bitcore’s code where it includes the network details of the bitcoin ‘mainnet’. To get peercoin working with bitcore, all we need to do is construct a call to that same function with peercoin’s network values. Where can one find these values? The call looks like this for btc:

addNetwork({
  name: 'livenet',
  alias: 'mainnet',
  pubkeyhash: 0x00,
  privatekey: 0x80,
  scripthash: 0x05,
  xpubkey:  0x0488b21e,
  xprivkey: 0x0488ade4,
  networkMagic: 0xf9beb4d9,
  port: 8333,
  dnsSeeds: [
    'seed.bitcoin.sipa.be',
    'dnsseed.bluematt.me',
    'dnsseed.bitcoin.dashjr.org',
    'seed.bitcoinstats.com',
    'seed.bitnodes.io',
    'bitseed.xf2.org'
  ]
});

hopefully this should help :slight_smile:

http://wiki.peercointalk.org/index.php?title=Peercoin_developer_notes

Peercoin Attribute Value
Peercoin source code https://github.com/ppcoin/ppcoin
Peercoin Public Address lead Character P
Peercoin Public Address lead Decimal 50
Peercoin Public Address lead Hex value 0x37
Peercoin Private Address lead Character 7
Peercoin Private Address lead Decimal 183
Peercoin Private Address lead Hex value 0xB7
Peercoin Private Address lead K
Peercoin magic bytes \xe6\xe8\xe9\xe5
Peercoin Genesis hash hex e327cd80c8b17efda4ea08c5877e95d877462ab66349d5667167fe3200000000
Peercoin Genesis hash e3\x27\xcd\x80\xc8\xb1\x7e\xfd\xa4\xea\x08\xc5\x87\x7e\x95\xd8\x77\x46\x2a\xb6\x63\x49\xd5\x66\x71\x67\xfe\x32\x00\x00\x00\x00
Peercoin Genesis tx hash ;\xa3\xed\xfdz{\x12\xb2z\xc7,>gv\x8fa\x7f\xc8\x1b\xc3\x88\x8aQ2:\x9f\xb8\xaaK\x1e^J
Peercoin Genesis tx hash hex
Peercoin default port 9901

fuzzybear

[quote=“FuzzyBear, post:2, topic:3358”]hopefully this should help :slight_smile:

http://wiki.peercointalk.org/index.php?title=Peercoin_developer_notes

Peercoin Attribute Value
Peercoin source code https://github.com/ppcoin/ppcoin
Peercoin Public Address lead Character P
Peercoin Public Address lead Decimal 50
Peercoin Public Address lead Hex value 0x37
Peercoin Private Address lead Character 7
Peercoin Private Address lead Decimal 183
Peercoin Private Address lead Hex value 0xB7
Peercoin Private Address lead K
Peercoin magic bytes \xe6\xe8\xe9\xe5
Peercoin Genesis hash hex e327cd80c8b17efda4ea08c5877e95d877462ab66349d5667167fe3200000000
Peercoin Genesis hash e3\x27\xcd\x80\xc8\xb1\x7e\xfd\xa4\xea\x08\xc5\x87\x7e\x95\xd8\x77\x46\x2a\xb6\x63\x49\xd5\x66\x71\x67\xfe\x32\x00\x00\x00\x00
Peercoin Genesis tx hash ;\xa3\xed\xfdz{\x12\xb2z\xc7,>gv\x8fa\x7f\xc8\x1b\xc3\x88\x8aQ2:\x9f\xb8\xaaK\x1e^J
Peercoin Genesis tx hash hex
Peercoin default port 9901

fuzzybear[/quote]

thanks for the help!

that gives us port, pubkeyhash, and privatekey.

maybe also networkmagic, but the value from the wiki seems to be using a different encoding. how do I convert it so it looks like 0xf9beb4d9 ?

as for scripthash, dnsseeds, xpubkey and xprivkey, these are still missing.

fuzzy@anonymized.invalid

Awesome, thanks! This is what we have now:

addNetwork({
name: ‘peercoin’,
alias: ‘peercoin’,
pubkeyhash:0x37,
privatekey: 0xB7,
scripthash: ,
xpubkey: ,
xprivkey: ,
networkMagic: 0xe6e8e9e5,
port: 9901,
dnsSeeds: [
seed.ppcoin.net”,
seedppc.ppcoin.net”,
dnsseed.ppc.altcointech.net”,
tnseed.ppcoin.net”,
tnseedppc.ppcoin.net”,
]
})

This thread is a bit old and the topic is also treated in more recent threads, but this is the most technical and parameter specific.

The missing parameters are:
scripthash is the prefix for the P2SH addresses. For peercoin, it is 0x75.
xpubkey and xprivkey are the prefixes for the HD public and private keys. In bitcoin network, they lead to keys starting with xpub and xprv, respectively. For bitcoin testnet, they are tpub and tprv.
I don’t know if there are such prefixes defined for peercoin somewhere. Leaving them as in bitcoin default would work, but all the other compatible wallets would need to use the same convention to be 100% compatible.

[quote=“azuabotlas, post:6, topic:3358”]This thread is a bit old and the topic is also treated in more recent threads, but this is the most technical and parameter specific.

The missing parameters are:
scripthash is the prefix for the P2SH addresses. For peercoin, it is 0x75.
xpubkey and xprivkey are the prefixes for the HD public and private keys. In bitcoin network, they lead to keys starting with xpub and xprv, respectively. For bitcoin testnet, they are tpub and tprv.
I don’t know if there are such prefixes defined for peercoin somewhere. Leaving them as in bitcoin default would work, but all the other compatible wallets would need to use the same convention to be 100% compatible.[/quote]

ppcd has kept the original bitcoin values.

[quote=“azuabotlas, post:6, topic:3358”]This thread is a bit old and the topic is also treated in more recent threads, but this is the most technical and parameter specific.

The missing parameters are:
scripthash is the prefix for the P2SH addresses. For peercoin, it is 0x75.
xpubkey and xprivkey are the prefixes for the HD public and private keys. In bitcoin network, they lead to keys starting with xpub and xprv, respectively. For bitcoin testnet, they are tpub and tprv.
I don’t know if there are such prefixes defined for peercoin somewhere. Leaving them as in bitcoin default would work, but all the other compatible wallets would need to use the same convention to be 100% compatible.[/quote]

Thanks for the info!

I’m doing some experimentation with Peercoin and I really need a Bitcore equivalent. Are you planning on a JS fork of Bitcore or something down that line?

Project described here: http://peer4commit.com/projects/158

You should ask [member=1]FuzzyBear[/member] for project current state.

Here is [member=1]FuzzyBear[/member] github repository: https://github.com/FuzzyBearBTC/peercore

[member=30004]thehuntergames[/member] has started to work on his own fork:

https://github.com/jointhepartypooper/peercore

Contributions are welcome!

sorry, been busy lately,
but basically a transaction is created like so:


  var privateKey = 'U6qzSDvd2Kjc8DJZR6YuLFqistTvDXxFhoVHLSrvmyT3qnGPGmRt';
  var fromAddress = 'mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1';
  var privkey = PrivateKey.fromWIF(privateKey);
  var pubkey = privkey.toPublicKey();

  var toAddress = 'PNQGpF1TjirwLAN3it79ybinx5g7hgHuBN';
  var changeAddress = 'PRwekKSxNUnpQu8vGbKGEJPGdK3YvEenZX';

  var simpleUtxo = {
    address: fromAddress,
    txId: 'a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458',
    outputIndex: 0,
    script: Script.buildPublicKeyHashOut(fromAddress).toString(),
    satoshis: 123
  };
  var transaction = new Transaction()
          .from(simpleUtxo)
          .to(toAddress, 321)
          .change(changeAddress)
          .sign(privateKey);

  var transactionhex = transaction.toString(); // this hexstring can be pushed with sendrawtransaction or use bitcore-p2p

I’m reviving this thread as Peercoin current momentum makes this extremely relevant again.

JavaScript is ridiculously popular by quite some time already, sum up with the fact that cryptocurrencies are growing everyday in popularity too, and you have the perfect recipe to bring a flow of devs creating new projects, helping in existing (JS) ones, etc. The possibilities are endless.

This is not possible today, as you’re stuck with C++ or Python if you want to do anything Peercoin related.

@Fuzzybear Do you have any feedback on your fork? Is it working? What parts are left to be done? I’ve never used Bitcore before, but am willing to help in any way you find useful in order for us to have a “Peercore” version fully working.

If anyone knows JavaScript and is willing to help, I think we could make a group effort to get this going, would be really promising for the community as a whole.

“Peercore”

I think a better approach is to create a project called “Altcore” (or whatever you want to call it) that supports all altcoins, including peercoin, and it does it by having a plugin system that any coin can make a plugin for.

I assume that most projects that use peercoin don’t use just peercoin, they support multiple currencies as well. Bitcore is over 1MB in size. imagine having to add 1MB worth of library code for every single currency supported, thats insanity. A batter way would be to have only one bitcore library, but one that is flexible enough to have support for every single coin your project wants to support.

2 years past, all are just a conception

Makes sense. It could bring even more maintainers to the project in the long run.

However I don’t know how we would proceed with features more Peercoin-related. If its an altcoin project, would we need to implement every minting format possible? (I’m sure every minting coin implements the technology its own way). What about PeerAssets? If its a “Peercoin only” project it would make sense to add some support to it, which isn’t exactly true in the case we follow a more neutral “Altcore” implementation of Bitcore.

@hrobeers has made bitcore work with Peercoin about a year ago, as part of “PeerScript labs” project as well as the javascript implementation of PeerAssets protocol.

There is also earlier work by some community members which AFAIK yielded working bitcoin library to Peercoin back in 2015 or 2014. However I recommend the version linked above due to cleaner implementation.