智能合约方法始终返回零

时间:2019-04-07 10:04:28

标签: ethereum solidity web3

我遇到一个问题,需要帮助进行故障排除:我已经部署了基本的智能合约,并且其所有方法始终返回零。构造函数运行良好,并且使用web3.getStorateAt可以让我证明是这种情况

起初,我以为我的功能不好,但是即使是一个简单的标识调用(标记为视图,并由嵌入到geth中的web3制成)也无法正常工作。

    constructor(address ca, uint256 zkp, bytes32 uid) public {
        creator = tx.origin;
        coinAddress = ca;
        secret = zkp;
        userId = uid;
        seed = block.timestamp;
    }

    function f(uint256 a) public view returns (uint256) {return a;}
    function ff(uint256 a) public view returns (uint256, uint256) {return (a, a & (2**128 - 1));}
    function fff(uint256 a) public view returns (uint256, uint256, uint256) {return (seed, a, a & (2**128 - 1));}

构造函数工作正常,但即使简单的f函数也返回零。 实际上,即使getStorageAt证明了我已存储了东西,但当我尝试使用生成的方法(将某些状态公开)读取它们时,它也会返回0! 我这样称呼它:

contract = web3.eth.contract([{"constant":false,"inputs":[{"name":"claim","type":"uint256"},{"name":"proof","type":"uint256"},{"name":"command","type":"bytes"}],"name":"storeTransaction","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"a","type":"uint256"}],"name":"ffff","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"commandHash","type":"uint256"}],"name":"createChallenge","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"a","type":"uint256"}],"name":"fff","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"a","type":"uint256"}],"name":"f","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"a","type":"uint256"}],"name":"ff","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"ca","type":"address"},{"name":"zkp","type":"uint256"},{"name":"uid","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}])
contract.eth.defaultAccount=contract.eth.coinbase
ct = contract.at('0x3d262eb4a0986def5d5340c0e1251b297165c1b3')
ct.f(3333, console.log)
ct.creator(console.log)

打印: 空0 空0x

如果您知道出什么问题了,我非常希望 已经谢谢你了,

0 个答案:

没有答案