Hi! I'm trying to create Dogecoin transactions with JavaScript, and i recently discovered CryptoCoinJS. I know it was a fork of this lib intended for use with other currencies, but it seems dead, hasn't been updated in a while, and there is no documentation on how to create transactions.
Now since the dev of CryptoCoinJS isn't responding, I started looking at alternatives. I discovered that this lib also has some support for altcoins, but how would i go about doing this?
I've tried looking at other posts about this, but i didn't really find anything useful (or i just didn't look hard enough), but in any case i wanted to have some updated information.
How can i create altcoin (Dogecoin specifically) transactions and public & private keys with bitcoinjs?
I'm using electron and nodejs.
Thanks,
-Sas :)
Here's a test case that shows creating a transaction for another network: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L61
The test cases for this library cover a lot of things you're likely to be doing yourself, search through those if you need a place to start
Now since the dev of CryptoCoinJS isn't responding, I started looking at alternatives. I discovered that this lib also has some support for altcoins, but how would i go about doing this?
I'm so sorry @iSasFTW, completely dropped the ball here. CryptoCoinJS is not dead. However, I'd suggest that for all new development, you use bitcoinjs-lib. I'll respond to your email as well.
Also, I'd add that you can use coininfo to and convert to a compatible bitcoinjs-lib Network object: https://github.com/cryptocoinjs/coininfo#want-to-use-with-bitcore-or-bitconjs-lib - so using Dogecoin + bitcoinjs-lib should not be a problem.
@jprichardson Ooh! This sounds interesting! How would i got about doing this though? I don't understand bitcoinjs' documentation, as it's all just code demonstrations, without explanation...
Let us know if you need any more help.
@dcousens Well, i'm back and i need some help!
In the documentation here: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L61
I can see how the network is switched, but how can i apply that to a simpler 1 address to 1 address transaction?
Also, since i'm using browserify, do i not need anything special at my other js file to make sure that i can access bitcoinjs?
Thanks :)
I can see how the network is switched, but how can i apply that to a simpler 1 address to 1 address transaction?
That example is 2 inputs, 2 outputs. You want 1 input, 1 output.
Also, since i'm using browserify, do i not need anything special at my other js file to make sure that i can access bitcoinjs?
Browserify is all you need.
@dcousens Alright! So it should look kind of like this?
it('can create a [complex] Transaction', function (done) {
this.timeout(30000)
var network = bitcoin.networks.testnet
var alice = bitcoin.ECPair.makeRandom({ network: network })
var bob = bitcoin.ECPair.makeRandom({ network: network })
var alicesAddress = alice.getAddress()
var bobsAddress = bob.getAddress()
blockchain.t.faucetMany([
{
address: alicesAddress,
value: 4e4
},
{
address: bobsAddress,
value: 2e4
}
], function (err, unspents) {
if (err) return done(err)
var tx = new bitcoin.TransactionBuilder(network)
tx.addInput(unspents[0].txId, unspents[0].vout)
tx.addOutput(blockchain.t.RETURN, 3e4)
tx.sign(0, alice)
tx.sign(1, bob)
blockchain.t.transactions.propagate(tx.build().toHex(), done)
})
})
})
Also, what does this part do?
blockchain.t.faucetMany([
{
address: alicesAddress,
value: 4e4
},
{
address: bobsAddress,
value: 2e4
}
], function (err, unspents) {
if (err) return done(err)
@iSasFTW those tests are using testnet (see https://en.bitcoin.it/wiki/Testnet).
To run the test, it needs some testnet equivalent bitcoin, the faucet provides them so we can then broadcast the transaction.
@dcousens Alright! I'm just kind of scared to touch any of the code, since i don't really understand what it does. All i really need is to get a wallet from a private key and move a specified amount to another address. It just needs to happen on the dogecoin network. Thing is, i understand what the simpler transaction example does, but the other one is confusing. What do i need to add to the simple bitcoin transaction example to make it run on a different network?
since i don't really understand what it does
Then the best suggestion I could give you is to point out the parts you don't understand, and take a moment to understand each one.
Anything other than that could potentially be putting your dogecoin at risk of you accidentally losing them.
What do i need to add to the simple bitcoin transaction example to make it run on a different network?
You need a dogecoin node, or a dogecoin web API with which you could broadcast your transaction through.
Most helpful comment
Also, I'd add that you can use
coininfoto and convert to a compatible bitcoinjs-lib Network object: https://github.com/cryptocoinjs/coininfo#want-to-use-with-bitcore-or-bitconjs-lib - so using Dogecoin + bitcoinjs-lib should not be a problem.