How to perform a simple 1-to-1 Bitcoin Transaction with Bitcore

+1 vote

I try to understand Bitcoin Transactions. I use the Bitcore Javascript Library.

I have a Source Wallet1 (Address1/PublicKey1 and PrivateKey1) - with 10 Bitcoins (simplified).

Now a friend gives me his Wallet2 (Address2/PublicKey2), and wants to receive 1 Bitcoin.

When I read the documentation then for a simple Transaction (1-to-1) the code looks like this:

var transaction = new Transaction()
.from(utxos)          // Feed information about what unspent outputs one can use
.to(address, amount)  // Add an output with the given amount of satoshis
.change(address)      // Sets up a change address where the rest of the funds will go
.fee(5430) // Minimum non-dust amount
.sign(privkeySet)     // Signs all the inputs it can

But I have these Questions:

  1. What is the argument utxos int the .from(utxos) function is. Is this the PublicKey1 from my Wallet1?
  2. The argument address for the .to(address) function is the PublicKey2 of my Friends Wallet2?
  3. The argument address for the change(address) function is a new Address3, which belongs to MY Wallet3, which I have to create just before I make the transaction? => This means I need to know the PrivateKey3 of this Wallet3 and this is the Wallet3 which I will get my rest of the 9 Bitcoins? => Is it possible to do the Transaction without this .change(address) function? If I say, I don't want to transfer the rest of my 9 Bitcoins to the new Address? They should just stay in the original Wallet1?
  4. The .fee(5430) means that I will spend 5430 Satoshi = USD $0.2337424950 for this Transaction?
  5. The privkeySet in the .sign(privkeySet) function is the PrivateKey1 from my original Wallet1 right? After this .sign() function the Transaction will be 'fired' and the job is done?

    Thank you very much for your support.

Jul 20, 2018 in Blockchain by aryya
• 7,450 points
1,934 views

1 answer to this question.

0 votes

What is the argument utxos int the .from(utxos) function is. Is this the PublicKey1 from my Wallet1?

These are outpoints (i.e. unspent outputs from prior transactions) that you can spend.

https://bitcore.io/api/lib/unspent-output

The argument address for the .to(address) function is the PublicKey2 of my Friends Wallet2?

An address is not necessarily derived from just a destination public key. You will need to read up on how p2sh/p2pkh/p2pk addresses are generated.

But in general, if you just want to pay someone with simple spend conditions, the canonical address to pay to is simply a p2pkh address, which is derived from the recipient's public key.

https://bitcore.io/api/lib/address

// recipientPublicKey should be provided
var address = new Address(recipientPublicKey);
// alternative interface
var address = Address.fromPublicKey(recipientPublicKey);

Usually though, your friend should just provide you with an address to pay to, so you don't have to worry about address generation. The example above assumes that your friend has provided you with their public key (for whatever reason).

The argument address for the change(address) function is a new Address3, which belongs to MY Wallet3, which I have to create just before I make the transaction? => This means I need to know the PrivateKey3 of this Wallet3 and this is the Wallet3 which I will get my rest of the 9 Bitcoins? => Is it possible to do the Transaction without this .change(address) function? If I say, I don't want to transfer the rest of my 9 Bitcoins to the new Address? They should just stay in the original Wallet1?

You will need a change address unless the UTXO(s) you are spending is equal to the amount you are sending to your friend + fees. Typically, it is good practice to generate a new keypair and address to use as a change address as address re-use is generally considered bad. But it is also OK to reuse your address for wallet1.

The .fee(5430) means that I will spend 5430 Satoshi = USD $0.2337424950 for this Transaction?

Yes.

The privkeySet in the .sign(privkeySet) function is the PrivateKey1 from my original Wallet1 right? After this .sign() function the Transaction will be 'fired' and the job is done?

After you sign, you need to serialize your transaction. After serialization, you should get an hexadecimal ASCII string which you can use to broadcast to the bitcoin network using a 3rd party provider or your own Bitcoin node.

bitcoin-cli sendrawtransaction <serialized transaction>

answered Jul 20, 2018 by charlie_brown
• 7,720 points

Related Questions In Blockchain

0 votes
1 answer
+1 vote
1 answer

How does a miner get to know that a transaction is verified by all the nodes?

Contrary to the popular belief, it is ...READ MORE

answered Mar 27, 2018 in Blockchain by Johnathon
• 9,090 points
2,487 views
0 votes
1 answer
0 votes
2 answers

How is a transaction public key related to original public?

The details like account balance, nonce etc., ...READ MORE

answered Jul 24, 2018 in Blockchain by digger
• 26,740 points
467 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,655 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,211 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,123 views
0 votes
1 answer

Not Able to register a user with Hyperledger-Fabric v1.1 preview

The error: "Certificate not found with AKI 'e729224e8b3f31784c8a93c5b8ef6f4c1c91d9e6e577c45c33163609fe40011' ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,720 points
1,639 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP