我是刚踏实的。在从映射中存储和检索数据的简单操作(uint=>地址)中,我面临一个问题。
我定义了一个简单的合同:
contract test {
mapping (uint => address) public testmap;
function add_to_map (uint _key, address _val) public{
testmap[_key] = _val;
}
function get_from_map(uint _key) returns (address){
return testmap[_key];
}
}在html中,我要做的是:
function createTestContract(){
var test = testContract.at("0xc383dfb5fc71ff1bb2bbadb812229681fb7a8e3c");
test.add_to_map(1, "0x12ca4a043753cd5537af99ad314a299962238ed2");
console.log('Key: 1' + ' address: ' + test.get_from_map(1));
}作为输出,我期望地址- 0x12ca4a043753cd5537af99ad314a299962238ed2,它存储在键1上,但是它在控制台日志中返回一些随机地址。
Key: 1 address: 0x07824f2f2a330dd2e260437af299800175dc2642a63c71a5f824cee54eae2264我在AlethZero上使用私人连锁。感谢有人能帮忙。
发布于 2016-05-21 09:51:33
您需要指定constant,以便获得call的返回值:
function get_from_map(uint _key) constant returns (address)。
没有常量,test.get_from_map(1)是一个sendTransaction,它总是返回一个事务哈希。请参阅交易和呼叫之间有什么区别?
https://ethereum.stackexchange.com/questions/4155
复制相似问题