Blockchain 如何在私人连锁店上发送无汽油费的交易
我想发送无汽油费的交易。 我做了一个私人连锁店,开始了燃气价格为0的geth,如下所示Blockchain 如何在私人连锁店上发送无汽油费的交易,blockchain,ethereum,solidity,web3,Blockchain,Ethereum,Solidity,Web3,我想发送无汽油费的交易。 我做了一个私人连锁店,开始了燃气价格为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 --gaspric
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'
但是,它不需要煤气费,但错误消息显示,固有煤气太低
。
我的代码如下所示
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
这将激活挖掘并为新块创建一个要挖掘的线程。
另外,必须使用--unlock
来解锁您的帐户(在本例中,帐户0是coinbase)。
为了成功解锁您的帐户,您必须在.sec文件中提供帐户0的密码。该文件仅包含密码,不包含任何空格或新行。
创建文件后,添加以下内容:
--密码
如果您正在处理私有链,请添加--允许不安全解锁,否则解锁将无法工作。如果你愿意的话,你可以在另一篇文章中查找原因
因此,总而言之,您应该添加以下内容:
--mine--miner.threads 1--解锁--允许不安全的解锁--密码
在查看“geth帮助”时,选项“gasprice”被标记为已弃用。
您应该使用-miner.gasprice“0”