1

I have a smartcontract deployed on Goerli at 0x77a286b658191c9A8504D9e8E5c7B6381caA9e72. It uses @openzeppelin/contracts/access/AccessControl.sol, allowing granting roles to some addresses, and baseUri() is allowed to be read only by USER_ROLE. The creator is 0x19D67dBE3018E2565A7b17Fe7F673770BC95a3FF, and so he has the USER_ROLE thanks to the constructor. The contract is verified, you can check the code it's pretty straightforward.

I'm calling baseUri() with creator's address, but how can I decode this ???

  useEffect(() => {
    alchemy.core
      .call({
        from: "0x19D67dBE3018E2565A7b17Fe7F673770BC95a3FF",
        to: "0x02fcd793358C8a7Aa4b1e723035e80c65C67eeDe",
        data: "0xa4e0f3be", // keccak256(baseUri)
      })
      .then((res) => {
        console.log(res);
        setUri(res);
        setIsUriSuccess(true);
      });
  }, []);

returns

0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005168747470733a2f2f697066732e696f2f697066732f62616679626569636e73686f687265686864753370646c366d34797469636f7078746d6c336b74786a36377777766d6f77357a36326b33656c6a652f000000000000000000000000000000

How can I decode this ? I want to retrieve the string "https://www.google.fr", the original value.

1 Answer 1

1

If you know, that the return type is string, to decode it:

import { utils } from 'ethers';

let [ myString ] = utils.defaultAbiCoder.decode(
                   ['string'], '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005168747470733a2f2f697066732e696f2f697066732f62616679626569636e73686f687265686864753370646c366d34797469636f7078746d6c336b74786a36377777766d6f77357a36326b33656c6a652f000000000000000000000000000000'
);

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.