Ethereum 如何强制在某个未来块上执行事务?(以太坊,JS API)

Ethereum 如何强制在某个未来块上执行事务?(以太坊,JS API),ethereum,Ethereum,我正在尝试发送一个事务,并让它在某个块上执行。根据JS API,这似乎是可能的: 请参见参数#2,除非我误解了它 但每次我尝试这样做时,它都会以“无效地址”失败: …而删除块参数28410 incrementer.increment.sendTransaction({from:eth.coinbase}, function(err, address) { if (!err) console.log("no err " + address); else console.

我正在尝试发送一个事务,并让它在某个块上执行。根据JS API,这似乎是可能的:

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

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

…而删除块参数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])函数实际上只有两个参数

(请参见此处:,可选回调是隐式的)

wiki中的文本很可能是复制的&过去的错误。我现在已经解决了这个问题,所以请不要因为没有阅读文档而责怪我:)

注意。我不明白您为什么希望针对事务包含的特殊块。您永远无法确定您的事务是否包含在块中,因为这是由矿工而不是事务提交人决定的。如果您希望延迟执行,则需要使用合同


编辑:添加以下评论回复,因为这是一般信息

“交易”和“合同”是两个不同层次的东西。当谈到“合同”时,通常(在以太坊的上下文中)会提到定义逻辑的应用程序代码,该逻辑要么完全执行,要么根本不执行(由区块链确保,因此不需要第三方信任方,因此是“智能合同”)。该代码“存在”于区块链上,即其代码存储在区块链上,且其状态/内存在区块链上

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

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

(用两个词来解释这一切有点困难。每次我重读课文,我都会添加新的句子;)我希望这会有所帮助。)

可以在特定的时间或块安排契约函数调用。它目前正在mainnet和TestNet上工作。您还可以在本地网络上部署它

  • 以太坊契约有助于在将来调度指定块的函数调用
  • 可以针对任何契约安排执行函数调用
  • 日程安排可由合同或以太坊账户持有人完成
  • 完全包含在以太坊网络中
例如,以下合同可能会延迟付款:

以编程方式安排事务的最简单方法是使用。这是带有TypeScript类型的JS库(更易于使用)

以下是如何使用此库的文本教程:


下面是视频教程:

所以一个新的契约可以保证被挖掘,但事务不能被挖掘?另外,在特定块中包含的原因是我希望创建一个类似cron的守护进程。它将使用块#,而不是小时、分钟和。将块计数器用作(cron)计时器不是一个好主意。这有点像在网络上计算数据包来实现应用软件计时。你需要一些独立于网络的东西作为参考。以太坊有多种可能性,最佳解决方案取决于您希望实现的目标。也许你可以在以太坊论坛上讨论你的想法。很多聪明的人都会给你一些想法和建议,而不是像这样的问答网站。
incrementer.increment.sendTransaction({from:eth.coinbase}, function(err, address) {
  if (!err)
    console.log("no err " + address); 
  else
    console.log("err " + address); 
});
pragma solidity 0.4.24;

import "contracts/Interface/SchedulerInterface.sol";

/// Example of using the Scheduler from a smart contract to delay a payment.
contract DelayedPayment {

    SchedulerInterface public scheduler;

    address recipient;
    address owner;
    address public payment;

    uint lockedUntil;
    uint value;
    uint twentyGwei = 20000000000 wei;

    constructor(
        address _scheduler,
        uint    _numBlocks,
        address _recipient,
        uint _value
    )  public payable {
        scheduler = SchedulerInterface(_scheduler);
        lockedUntil = block.number + _numBlocks;
        recipient = _recipient;
        owner = msg.sender;
        value = _value;

        uint endowment = scheduler.computeEndowment(
            twentyGwei,
            twentyGwei,
            200000,
            0,
            twentyGwei
        );

        payment = scheduler.schedule.value(endowment)( // 0.1 ether is to pay for gas, bounty and fee
            this,                   // send to self
            "",                     // and trigger fallback function
            [
                200000,             // The amount of gas to be sent with the transaction.
                0,                  // The amount of wei to be sent.
                255,                // The size of the execution window.
                lockedUntil,        // The start of the execution window.
                twentyGwei,    // The gasprice for the transaction (aka 20 gwei)
                twentyGwei,    // The fee included in the transaction.
                twentyGwei,         // The bounty that awards the executor of the transaction.
                twentyGwei * 2     // The required amount of wei the claimer must send as deposit.
            ]
        );

        assert(address(this).balance >= value);
    }

    function () public payable {
        if (msg.value > 0) { //this handles recieving remaining funds sent while scheduling (0.1 ether)
            return;
        } else if (address(this).balance > 0) {
            payout();
        } else {
            revert();
        }
    }

    function payout()
        public returns (bool)
    {
        require(block.number >= lockedUntil);

        recipient.transfer(value);
        return true;
    }

    function collectRemaining()
        public returns (bool) 
    {
        owner.transfer(address(this).balance);
    }
}