获取block.coinbase交易会失败

合约在测试网络部署后,调用获取block.coinbase转账交易就会失败,移除获取block.coinbase代码后交易就成功了,conflux不支持获取吗?

放在以太坊测试网上转账是交易成功的,conflux上交易失败。

不支持。Conflux没有coinbase交易

好的,谢谢龙老大

Could you share an example? I just tried and it worked well for me on the testnet.

pragma solidity >=0.5.0 <0.7.0;

contract Test {
    event Coinbase(address);

    constructor() public {
        emit Coinbase(block.coinbase);
    }
}

@Fan_Long block.coinbase in Solidity will return the block miner’s address (might be a misnomer).

contract TestToken is ERC20 {
    constructor() ERC20("TestToken", "Test") {
        _mint(msg.sender, 10**9 * 10**18);
    }
    
    function _mintMinerReward() internal {
        _mint(block.coinbase, 10);
    }

    function _beforeTokenTransfer(address from, address to, uint256 value) internal virtual override {
        _mintMinerReward();
        super._beforeTokenTransfer(from, to, value);
    }
}

上面的block.coinbase会导致交易失败,如果改成其他msg.sender就没有问题。

I just tried and this works fine. But with this contract, estimation (cfx_estimateGasAndCollateral) will fail because during estimation block.coinbase will be the null address and your ERC20 implementation probably does not allow minting to the null address.

1 Like

非常感谢你的解答,我打算试着给矿工奖励的,这样看就给不了了

发交易是可以的,只是estimate和call不行,节点下个版本我们会处理这个问题:https://github.com/Conflux-Chain/conflux-rust/issues/2152.