我如何在私有链上发送没有汽油费的交易

How can I send transaction with no gas fee on private chain

我想发送没有gas费的交易。

我创建了一个私有链,并开始使用 gas 价格为 0 的 geth,如下所示。

geth --datadir node1/ --syncmode 'full' --port 30311 --rpc --rpcaddr '0.0.0.0' --rpcport 8545 --rpccorsdomain "*" --rpcvhosts "*" --rpcapi 'personal,db,eth,net,web3,txpool,miner'  --networkid 1515 --gasprice '0'

然而,它不应该需要汽油费,但错误消息显示intrinsic gas too low。 我的代码如下

const customCommon = Common.forCustomChain(
      'mainnet',
      {
        name: 'privatechain',
        networkId: 1515,
        chainId: 1515,
      },
      'petersburg',
    )
    const functionAbi = await this.state.contract.methods.setGreeting(this.state.text).encodeABI()
    console.log(this.state.nonce)
    var details = await {
      nonce : this.state.nonce,
      gasPrice : 0,
      gas : 0,
      gasLimit: 0,
      from : this.state.web3.eth.coinbase,
      to: this.state.address,
      value : 0,
      data : functionAbi,
    };
    const transaction = await new EthereumTx(details, { common: customCommon },);  
    await transaction.sign(this.state.pk)

    var rawdata = await '0x' + transaction.serialize().toString('hex');
    console.log(rawdata)

    await this.state.web3.eth.sendSignedTransaction(rawdata)
    .on('transactionHash', function(hash){
      console.log(['transferToStaging Trx Hash:' + hash]);
    })
    .on('receipt', function(receipt){
      console.log(['transferToStaging Receipt:', receipt]);
    })
    .on('error', console.error);

我的代码有问题吗?可以给我一些建议吗?

当没有可用的块时,交易不能被包含在块中。您必须激活挖矿才能挖出区块并包含您发送的交易。

您必须添加 --mine --mine.threads 1 这将激活挖掘并创建 1 个线程来挖掘新块。 此外 --unlock 必须用于解锁您的帐户(在本例中为帐户 0,即 coinbase)。 为了成功解锁您的帐户,您必须在 .sec 文件中提供帐户 0 的密码。该文件仅包含密码,没有任何空格或换行符。 创建文件后添加以下内容: --password <path of the .sec file> 如果你在你的私人链上工作,请添加 --allow-insecure-unlock,否则解锁将不起作用。如果需要,您可以在另一个 post 中查找原因。

总而言之,您应该添加以下内容:

--mine --miner.threads 1 --unlock --allow-insecure-unlock --password <path of the .sec file>

选项 "gasprice" 在查看 "geth help" 时被标记为已弃用。 你应该使用 --miner.gasprice '0'.