getting value of public storage variable returns empty array
Expected behavior
- It must return valid address
Actual behavior
- It is returning empty array. It works fine with remix but not work when i call the same function from react client, I tried making getter function but still same problem. getting data always returning empty array but making changes in contract is working fine. Also tried changing version of web3 but didn't help
This is my solidity code
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract Test{
address public creator;
constructor() {
creator= msg.sender;
}
}
This is my react code
// test is instance of the solidity contract created with abi and deployed contract address
const creator= await test.methods
.creator()
.call({ from: accounts[0] });
Environment
npm: latest node: latest web3: latest OS: windows device: laptop
I tried reproducing this issue. With remix (injected web3) and local truffle suite, it was working as intended. Only in case the contract is deployed to remix javascript VM, I get the creator as undefined.
With remix it works fine, but when I integrated it with react and created connection to blockchain with web3js and then tried then it returns empty array, for every getters it returns empty array and for all transactions or calls that modifies blockchain it works fine.
@MananDesai54 Just for understanding, can you tell what is your local setup? I am using truffle with ganache, and I created a simple react app to check the code, and it is working fine for me. I am getting the creator as an array, with having only one value.
Mine is same only difference is mine is not ganache cli but mine is ethereum rinkeby network, for ganache is works fine but for real network it didn't work as expected
@MananDesai54 I checked by deploying the contract to rinkeby network. It's working for me there also. You can check the contract here 0xbAfe539eDE72D552D3E8A662C40813Db569B35C1
@Kankan-0 that's awesome can you share GitHub or code sand box link?
Btw I have used web3js for connecting to blockchain insgoof truffle @Kankan-0
@MananDesai54 I created this https://codesandbox.io/s/happy-dream-wfc9o
@Kankan-0 thanks I'll try this one
@Kankan-0 didn't work for me still getting empty array
@Kankan-0 this is my codepen link : https://codesandbox.io/s/silly-stallman-qfeec?file=/package.json
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.
@Kankan-0 this is my codepen link : https://codesandbox.io/s/silly-stallman-qfeec?file=/package.json
I have the same issue with an empty array for manager, did you figure out what is wrong?
so I fix it was from abi - the correct ABI that needs to use is after I add JSON.stringnify(abi)
console.log(JSON.stringify(abi)); => copy/paste in new web3.eth.Contract(abi, address);
Was you error fixed as I am having the same errors.
@MananDesai54
so I fix it was from abi - the correct ABI that needs to use is after I add JSON.stringnify(abi) console.log(JSON.stringify(abi)); => copy/paste in new web3.eth.Contract(abi, address);
Thanks @ancutadaniel . It worked for me.
The issue lies with the ABI you are feeding to web3.eth.Contract and you need a comprehensive one. Go to https://remix.ethereum.org/ and compile your contract there, then copy the ABI from there.
You can find the copy button for the ABI at the bottom of this image.