[SOLVED] Remix vs index.html

hi there,

i have difficulties to show value when i called a function. It did well on remix, but did not show up when i call it using javascript.

here’s how it looks in the remix (successfully return the value).

and here is how it looks in index.html console log.

i did check several times on the ABI and contract address, no issue except this function.

any idea why?

here is the javascript in the index.html.

async function ShowtimeLock() {

    let user = Moralis.User.current();
  const walletAddress = user.get('ethAddress');
  const web3 = await Moralis.enableWeb3();
  const chainIdDec = await web3.eth.getChainId(); 
  
  if (chainIdDec == 97 ) {
  	const web3 = await Moralis.enableWeb3();
  	let slockcontract = new web3.eth.Contract(LockABI,LockContract);
  	const bukakunci = await slockcontract.methods.ShowUnlockTime("0xb15fa3FFe0292892abc77bD3bA50409d3628DB8A").call();
  	console.log(bukakunci);			
  } else {
  	console.log("Connect to BSC Test Network!")
  }

}

here is the ABI for particular function

{
“inputs”: [
{
“internalType”: “address”,
“name”: “token”,
“type”: “address”
}
],
“name”: “ShowUnlockTime”,
“outputs”: [
{
“internalType”: “uint256”,
“name”: “”,
“type”: “uint256”
}
],
“stateMutability”: “view”,
“type”: “function”
},

are you sure in remix it uses injected web3 to make that call and not a dev environment?

if you paste the contract address, I could test, you could also use runContractFunction: https://docs.moralis.io/moralis-server/web3-sdk/native#runcontractfunction

hi @cryptokid, i used injected web3 on remix.

here is the verified sc on bsc testnet.

https://testnet.bscscan.com/address/0xA78367b20f734E4cd136e14dd127ba45dc753eeD#code

i think it deals with showunlocktime function. on the smart contract, the input is only token address, while to show the unlock time it needs token address as well as msg.sender, which i don’t know how to fix it. did try but no success yet.

hi there, it is solved now. I add wallet owner into function and worked as expected.

    function ShowUnlockTime(address walletowner, address token) external view returns (uint256) {
        Token storage lockedToken = hodlers[walletowner].tokens[token];
        return lockedToken.unlockTime;
    }

thank you!

1 Like