0

I have tests 100% working and returning values but when I try and read the data using the web3 api in javascript for the homework i retrieve a return value of /u0000 for name and symbol, I'm not sure why.

Result

0: ""
1: "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
name: ""
symbol: "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
[[Prototype]]: Object

JS

  lookUp: async function (){
    const { lookUptokenIdToStarInfo } = this.meta.methods;
    const id = document.getElementById("lookid").value;
    var star = await lookUptokenIdToStarInfo(id).call();
    console.log(star)
    console.log(JSON.stringify(star));
    App.setStatus("star info is name:" + star.name + " symbol:" +   
    star.symbol + ".");
  }

Solidity

function lookUptokenIdToStarInfo (uint _tokenId) public view returns 
        (string memory name, string memory symbol) {
        //Solidity 0.8.0 and above can return our Star struct but to 
        be pure to previous standard way of doing things we are 
        returning it as a string
        name = tokenIdToStarInfo[_tokenId].name;
        symbol = tokenIdToStarInfo[_tokenId].symbol;
        return (name,symbol);
    }

Test

it('lookUptokenIdToStarInfo test', async() => {
    let tokenId = 7;
    let instance = await StarNotary.deployed();
    await instance.createStar('Awesome Star!', "AS", tokenId, {from: accounts[0]})
    var getByTokenId = await instance.lookUptokenIdToStarInfo(tokenId); 
    assert.equal(await getByTokenId.name, 'Awesome Star!')
    assert.equal(await getByTokenId.symbol, 'AS')
});
2
  • no idea, if i have to guess then i would say this: const { lookUptokenIdToStarInfo } = this.meta.methods; what is this.meta? is it initialized correctly?
    – Majd TL
    Feb 19, 2022 at 10:27
  • that is my contract apologies I have this above this.meta = new web3.eth.Contract( starNotaryArtifact.abi, deployedNetwork.address, );
    – keil
    Feb 20, 2022 at 20:42

1 Answer 1

0

So I solved this issue by doing these steps.

  1. truffle Compile
  2. truffle Test
  3. truffle Deploy
  4. truffle migrate

MetaMask

  1. settings
  2. advanced
  3. reset account

It seems just reseting my metamask account fixed everything. unsure why but it now works and i can retrieve data. I wish this answer was more sexy :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.