如何强制在某个未来的块#上执行交易? (以太坊,JS API)

问题描述:

我想发送一个事务并让它在某个块上执行。这似乎根据JS API成为可能:如何强制在某个未来的块#上执行交易? (以太坊,JS API)

https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction

参见参数#2,除非我误解了。

但每次我尝试这样做时,它失败, “无效地址”:

incrementer.increment.sendTransaction({from:eth.coinbase}, 28410, function(err, address) { 
    if (!err) 
    console.log("no err " + address); 
    else 
    console.log("err " + address); 
}); 

...而去掉固定参数28410 ...

incrementer.increment.sendTransaction({from:eth.coinbase}, function(err, address) { 
    if (!err) 
    console.log("no err " + address); 
    else 
    console.log("err " + address); 
}); 

...成功就好。

有人知道这是怎么回事吗?我试图做甚至可能吗?

web3.eth.sendTransaction(transactionObject [,callback])函数确实只有2个参数。

(请参阅:https://github.com/ethereum/web3.js/blob/master/lib/web3/methods/eth.js#L177,可选的回调是隐含的)。

维基中的文本可能是一个副本&以前的错误。我现在解决了这个问题,所以请不要责怪没有阅读文档:)

注意。我不明白你为什么希望将目标锁定在一个特殊的交易区块中。您无法确定您的交易是否包含在一个区块中,因为这是由矿工而不是交易提交者决定的。如果您希望延期执行,您需要使用合同。


编辑:添加回复下面评论,因为它是一般信息。

“交易”和“合同”是不同级别的两件事情。当谈到“契约”时,人们通常(在以太坊的背景下)定义一个逻辑的应用程序代码,它完全或者根本不执行(由区块链保证,因此不需要第三方信任方,因此“智能合同“)。这段代码“活在”区块链中,即。它的代码存储在那里,并在那里有它的状态/内存。

交易是您在区块链上“做”的事情。当你想部署一个契约时,你把它(代码)放在一个事务对象中,并发送它没有目标地址(可以这么说)到区块链。部署由矿工执行,并将合约插入区块链中。部署操作是一个事务。

执行以太转账也是交易(基本上是调用简单的内部价值转移合同)。调用和执行复杂的“用户” - 合同是一项交易,也由矿工执行,结果/结果存储在区块链中(作为当前开采区块的一部分)。基本的交易执行包括成本(发送价值,部署),执行复杂合同(cf等)。

(这是一个有点难以解释这一切都在2个字每一次,我重新阅读这些文字,我添加新的句子;)我希望这有助于)

+0

因此,一个新的合同是保证被挖掘,但交易不是? – fivedogit

+0

此外,包含在特定块中的原因是我希望创建一个类似cron的守护进程。而不是几小时,几分钟,它会使用块#。 – fivedogit

+0

(我在上面回答) – Imifos

Ethereum Alarm Clock可以安排合同的功能。在特定时间或区块拨打电话。

  • 以太坊合同,有助于在将来为特定的块调度函数调用。
  • 功能调用可以安排在任何合同上执行
  • 调度可以由合同或以太坊账户持有人完成。
  • 完全包含在以太坊网络中。

以下的合同,例如,可以延迟付款:

contract DelayedPayment { 
    SchedulerInterface constant scheduler = SchedulerInterface(0x6c8f2a135f6ed072de4503bd7c4999a1a17f824b); 

    uint lockedUntil; 
    address recipient; 

    function DelayedPayment(address _recipient, uint numBlocks) { 
     // set the time that the funds are locked up 
     lockedUntil = block.number + numBlocks; 
     recipient = _recipient; 

     uint[3] memory uintArgs = [ 
      200000,  // the amount of gas that will be sent with the txn. 
      0,   // the amount of ether (in wei) that will be sent with the txn 
      lockedUntil, // the first block number on which the transaction can be executed. 
     ]; 
     scheduler.scheduleTransaction.value(2 ether)(
      address(this), // The address that the transaction will be sent to. 
      "",    // The call data that will be sent with the transaction. 
      255,   // The number of blocks this will be executable. 
      uintArgs,  // The tree args defined above 
     ) 
    } 

    function() { 
     if (this.balance > 0) { 
      payout(); 
     } 
    } 

    funtion payout() public returns (bool) { 
     if (now < lockedUntil) return false; 

     return recipient.call.value(this.balance)(); 
    } 
} 

当前版本的这个地址托管:0x6c8f2a135f6ed072de4503bd7c4999a1a17f824b。检查出alarm clock documentation for more details