简体   繁体   English

与Bitcore简单的一对一比特币交易

[英]Simple 1-to-1 Bitcoin Transaction with Bitcore

I try to understand Bitcoin Transactions. 我尝试了解比特币交易。 I use the Bitcore Javascript Library. 我使用Bitcore Javascript库。

I have a Source Wallet1 (Address1/PublicKey1 and PrivateKey1) - with 10 Bitcoins (simplified). 我有一个Source Wallet1(Address1 / PublicKey1和PrivateKey1) - 有10个比特币(简化)。

Now a friend gives me his Wallet2 (Address2/PublicKey2), and wants to receive 1 Bitcoin. 现在,一位朋友给了我他的Wallet2(Address2 / PublicKey2),并希望获得1比特币。

When I read the documentation then for a simple Transaction (1-to-1) the code looks like this: 当我阅读文档然后进行简单的事务(1对1)时,代码如下所示:

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. utxos .from(utxos)函数的utxos int是什么参数。 Is this the PublicKey1 from my Wallet1? 这是我Wallet1的PublicKey1吗?
  2. The argument address for the .to(address) function is the PublicKey2 of my Friends Wallet2? .to .to(address)函数的参数address是我的朋友Wallet2的PublicKey2?
  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? change(address)功能的参数address是一个新的Address3,属于MY Wallet3,我必须在进行交易之前创建它? => 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? =>这意味着我需要知道这个Wallet3的PrivateKey3,这是Wallet3,我将获得剩余的9个比特币? => Is it possible to do the Transaction without this .change(address) function? =>是否可以在没有此.change(address)功能的情况下进行交易? If I say, I don't want to transfer the rest of my 9 Bitcoins to the new Address? 如果我说,我不想将剩余的9比特币转移到新地址? They should just stay in the original Wallet1? 他们应该留在原来的Wallet1?
  4. The .fee(5430) means that I will spend 5430 Satoshi = USD $0.2337424950 for this Transaction? .fee(5430)意味着我将花费5430 Satoshi = 0.2337424950美元用于此次交易?
  5. The privkeySet in the .sign(privkeySet) function is the PrivateKey1 from my original Wallet1 right? privkeySet.sign(privkeySet)函数是我原来的Wallet1权PrivateKey1? After this .sign() function the Transaction will be 'fired' and the job is done? 在此.sign()函数之后,事务将被“解雇”并且作业完成了吗?

    Thank you very much for your support. 非常感谢您的支持。

What is the argument utxos int the .from(utxos) function is. .from(utxos)函数的utxos int是什么参数。 Is this the PublicKey1 from my Wallet1? 这是我Wallet1的PublicKey1吗?

These are outpoints (ie unspent outputs from prior transactions) that you can spend. 这些是您可以花费的外点(即先前交易的未花费的输出)。

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

The argument address for the .to(address) function is the PublicKey2 of my Friends Wallet2? .to(地址)函数的参数地址是我的朋友Wallet2的PublicKey2?

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. 您需要了解如何生成p2sh / p2pkh / p2pk地址。

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. 但一般来说,如果你只是想给付一个简单消费条件的人,那么付费的规范地址就是一个p2pkh地址,它来自收件人的公钥。

https://bitcore.io/api/lib/address 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? 更改(地址)功能的参数地址是一个新的Address3,属于MY Wallet3,我必须在进行交易之前创建它? => 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? =>这意味着我需要知道这个Wallet3的PrivateKey3,这是Wallet3,我将获得剩余的9个比特币? => Is it possible to do the Transaction without this .change(address) function? =>是否可以在没有此.change(地址)功能的情况下进行交易? If I say, I don't want to transfer the rest of my 9 Bitcoins to the new Address? 如果我说,我不想将剩余的9比特币转移到新地址? They should just stay in the original Wallet1? 他们应该留在原来的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. 您将需要一个更改地址,除非您花费的UTXO等于您向朋友发送的金额+费用。 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 . 但是也可以重复使用wallet1的地址。

The .fee(5430) means that I will spend 5430 Satoshi = USD $0.2337424950 for this Transaction? .fee(5430)意味着我将花费5430 Satoshi = 0.2337424950美元用于此次交易?

Yes. 是。

The privkeySet in the .sign(privkeySet) function is the PrivateKey1 from my original Wallet1 right? .sign(privkeySet)函数中的privkeySet是我原来的Wallet1中的PrivateKey1吗? After this .sign() function the Transaction will be 'fired' and the job is done? 在此.sign()函数之后,事务将被“解雇”并且作业完成了吗?

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. 序列化后,您应该获得一个十六进制ASCII字符串,您可以使用该字符串使用第三方提供商或您自己的比特币节点广播到比特币网络。

bitcoin-cli sendrawtransaction <serialized transaction>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM