简体   繁体   English

如何务实地将流明发送到未初始化的恒星地址

[英]How to send Lumens to an uninitialised stellar address pragmatically

I am new to stellar so please bear with my question if it sounds too basic.我是新来的恒星,所以如果这听起来太基本,请耐心等待我的问题。 So, using the stellar laboratory , I created two accounts lets name 1 and 2. I funded the 1st account with test-net coins using friend-bot and left the 2nd account empty.因此,使用恒星实验室,我创建了两个帐户,分别命名为 1 和 2。我使用朋友机器人为第一个帐户提供了测试网硬币,而第二个帐户为空。 Now as I understand that an account to be active on stellar network, it should have a minimum balance of about 1XLM.现在,据我了解,要在恒星网络上活跃的帐户,它的最低余额应约为 1XLM。 So using the transaction builder , I tried to perform a Payment Operation by trying to transfer 2XLM to the 2nd account.因此,使用交易生成器,我尝试通过尝试将 2XLM 转移到第二个帐户来执行付款操作 However I recieved the following response :但是我收到了以下回复:

{
  "type": "https://stellar.org/horizon-errors/transaction_failed",
  "title": "Transaction Failed",
  "status": 400,
  "detail": "The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details.  Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html",
  "extras": {
    "envelope_xdr": "AAAAAKNyr+6/r2REKzMV3sOL4jztg1HSdqlQhmthUU41BjPdAAAAZAAEmkQAAAADAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAmWhqbEZTUrZWFtvR1HU7VUW0pp3BwN4E9h4iQwvMr9kAAAAAAAAAAAExLQAAAAAAAAAAATUGM90AAABAHvtdpnjhq3usHFphQ/4naDHbKVhu+QqD8UFSavo/qlGo7Yiz/dLI3lQ0fmfa37uvwXWsYAn8mObDkrTjofc3Aw==",
    "result_codes": {
      "transaction": "tx_failed",
      "operations": [
        "op_no_destination"
      ]
    },
    "result_xdr": "AAAAAAAAAGT/////AAAAAQAAAAAAAAAB////+wAAAAA="
  }
}

So can someone tell me which operation I need to use to send XLM to an un-initialised address so I can activate it, not by using friendbot.那么有人可以告诉我需要使用哪个操作将 XLM 发送到未初始化的地址,以便我可以激活它,而不是使用friendbot。

I think it's because the Stellar laboratory is not set up for this exact use case.我认为这是因为 Stellar 实验室不是为这个确切的用例设置的。 It is more for getting a general feel of the basics.它更多地是为了获得基本的一般感觉。 In order to create an account this way using an SDK and communicating with horizon you would have to both create the account and fund it in a single transaction, and therefore you would have to input the source account's secret key.为了使用 SDK 以这种方式创建帐户并与 Horizo​​n 通信,您必须在单个交易中创建帐户并为其提供资金,因此您必须输入源帐户的密钥。

In the Stellar lab's account creation tab there is no way to input a source address its secret key (or at least I didn't see one).在 Stellar 实验室的帐户创建选项卡中,无法输入源地址的密钥(或者至少我没有看到)。

So in your example, your first account is created and funded by the testbot.因此,在您的示例中,您的第一个帐户是由 testbot 创建和资助的。 However, when you create the second account and try to send a payment to it from the first account, the reason it fails is because the second account is not yet a valid account as it has not been funded yet.但是,当您创建第二个帐户并尝试从第一个帐户向其发送付款时,失败的原因是因为第二个帐户尚未入金,因此还不是有效帐户。 Kind of a chicken and egg problem.有点鸡和蛋的问题。

The good news is you can definitely do this using the SDK, but I haven't found a way to do it using the lab.好消息是您绝对可以使用 SDK 完成此操作,但我还没有找到使用实验室的方法。

This from stellar.org about building transactions: https://www.stellar.org/developers/js-stellar-base/reference/building-transactions.html这来自 stellar.org 关于构建交易: https ://www.stellar.org/developers/js-stellar-base/reference/building-transactions.html

TransactionBuilder The TransactionBuilder class is used to construct new transactions. TransactionBuilder TransactionBuilder 类用于构造新事务。 TransactionBuilder is given an account that is used as transaction's “source account”. TransactionBuilder 被赋予一个帐户,用作交易的“源帐户”。 The transaction will use the current sequence number of the given Account object as its sequence number and increments the given account's sequence number when build() is called on the TransactionBuilder.事务将使用给定 Account 对象的当前序列号作为其序列号,并在 TransactionBuilder 上调用 build() 时递增给定帐户的序列号。

Operations can be added to the transaction calling addOperation(operation) for each operation you wish to add to the transaction.可以为您希望添加到事务的每个操作调用 addOperation(operation) 将操作添加到事务中。 See operation.js for a list of possible operations you can add.有关您可以添加的可能操作的列表,请参阅 operation.js。 addOperation(operation) returns the current TransactionBuilder object so you can chain multiple calls. addOperation(operation) 返回当前的 TransactionBuilder 对象,以便您可以链接多个调用。

After adding the desired operations, call the build() method on the TransactionBuilder.添加所需操作后,调用 TransactionBuilder 上的 build() 方法。 This will return a fully constructed Transaction.这将返回一个完全构造的事务。 The returned transaction will contain the sequence number of the source account.返回的交易将包含源账户的序列号。 This transaction is unsigned.此交易未签名。 You must sign it before it will be accepted by the Stellar network.您必须在它被 Stellar 网络接受之前对其进行签名。

# This is the relevant code

StellarSdk.Network.useTestNetwork();
// StellarBase.Network.usePublicNetwork(); if this transaction is for the public network
// Create an Account object from an address and sequence number.

var account=new StellarBase.Account("GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD","2319149195853854");

var transaction = new StellarBase.TransactionBuilder(account, {
      fee: StellarBase.BASE_FEE
    })
        // add a payment operation to the transaction
        .addOperation(StellarBase.Operation.payment({
                destination: "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW",
                asset: StellarBase.Asset.native(),
                amount: "100.50"  // 100.50 XLM
            }))
        // add a set options operation to the transaction
        .addOperation(StellarBase.Operation.setOptions({
                signer: {
                    ed25519PublicKey: secondAccountAddress,
                    weight: 1
                }
            }))
        // mark this transaction as valid only for the next 30 seconds
        .setTimeout(30)
        .build();

# Note that it is adding different operations to a single transaction.

First, you need to execute Create Account from the Transaction Builder.首先,您需要从 Transaction Builder 执行Create Account Only then you can transfer funds to this address.只有这样您才能将资金转移到该地址。

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

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