I'm trying to read a mapping storage variable from blockchain. Below, are my attempts, from client and server. Testing on Rinkeby network.
From client: Metamask is installed and I'm trying from the browser console. Web3 version is 0.2.x.
const index = "0000000000000000000000000000000000000000000000000000000000000005";
const key = web3.toHex('my_key');
web3.eth.getStorageAt(
'contract_address_here',
web3.sha3(key + index, { encoding: 'hex' }),
(err, result) => {
console.log(result); // Returns 0x00.....1; // Key exists
}
);
It works. The key does exist on the Rinkeby network.
Attempt from server:
Please note, that web3 version is 1.0.0-beta.26
and I'm using Infura as the provider.
// Init web3
const Web3 = require('web3');
const provider = new Web3.providers.HttpProvider(
"my rinkeby infura link here"
);
const web3 = new Web3(provider);
const index = "0000000000000000000000000000000000000000000000000000000000000005";
const key = web3.utils.toHex('my_key');
web3.eth.getStorageAt(
'contract_address_here',
web3.utils.sha3(key + index, { encoding: 'hex' }),
(err, result) => {
console.log(result); On the server, the result is always 0x...0
}
);
Does anyone know what is going on here? I'm making double sure, the Contract address is the one that is on Rinkeby and also my Infura link is one from Rinkeby.
Edit: 1. Looks like the web3 version is the problem. If I try to use web3 0.2.x on the server and hook it up with Infura provider, it works well.
() => (err, result) {
It seems to me that would be a callback that takes no arguments and returns a function that takes two arguments? (But it's missing a fat arrow if that's the case.) – user19510 Mar 2 '18 at 20:16