Cannot read properties of undefined (reading 'toHexString')

thanks tried this unfortunately . not solved the problem tried to reach to protocol dev team. waiting for response

got answer from smart contract devs, the _salt parameter is deprecated so I tried to remove it and run function still I get same results / error

Cannot read properties of undefined (reading ‘toHexString’) :expressionless:

so this is related to front-end code any Idea …?

Can you paste the code version that uses values for the parameters and not other variables?

ye sure here is

 let options = {
          contractAddress:  unlockAddress,
          functionName: "createLock",
           abi: unlockABI,
           //Parameters 
           params: {
            
            _expirationDuration: eventDuration,
            _tokenAddress: usdcContract,
            _keyPrice: ticketPrice,
            _maxNumberOfKeys: ticketQuantity,
            _lockName: eventName, 
            
             
           },

is this code version you wanted or smart contract code version??

if you meant

smart contract code version here is

function createLock(
    uint _expirationDuration,
    address _tokenAddress,
    uint _keyPrice,
    uint _maxNumberOfKeys,
    string calldata _lockName,
    bytes12 // _salt
  ) public returns(address) {

    bytes memory data = abi.encodeWithSignature(
      'initialize(address,uint256,address,uint256,uint256,string)',
      msg.sender,
      _expirationDuration,
      _tokenAddress,
      _keyPrice,
      _maxNumberOfKeys,
      _lockName
    );

Hey, the salt parameter looks ok to me,
you must pass in a byte
example of a byte :

// 0x0000000000000000000000000000000000000000000000000000000001020304
bytes32(0x01020304);

// 0x3031303230333034000000000000000000000000000000000000000000000000
bytes32("01020304");

The above show that byte are very sensitive and changes depending on any slight change (first a a number, second is a string)
to learn more abt bytes, take a look at this

and basically you will want to create a sol function that converts string to byte and the you can pass that in instead of the normal "abdul" bytes should have 0x000000000000152...

example:


This is an example testing create 2, you should see that i converted a uint to a byte to be able to pass it as the salt for create2 (you can pass in a string) e.t.c

This should solve the issue

Yesterday i asked Unlock protocol dev team about _salt parameter here is what they replide

Hey! This is deprecated… so you don’t need to use it anymore. This param was used to create locks at “unique” addresses.

Do i still have to pass _salt parameter even after this response from dev team

Hey! This is deprecated… so you don’t need to use it anymore. This param was used to create locks at “unique” addresses. ???

no, if that is what the dev team said, i was just showing how to pass bytes in general in contract calls

Oh thank you so what do you think this problem maybe related to front-end or smart contract ?

which problem ?
i just explained here Cannot read properties of undefined (reading 'toHexString') ?

yes i mean the problem that causes this error

Cannot read properties of undefined (reading ‘toHexString’)

it looks like you are converting it ? but the values it undefined ?
idk what you are trying to do, but you should not get (reading ‘toHexString’) for incorrect type except if you are trying to do an undefined conversion ?

example:

lol.toString();
//where lol is undefined 

I’m not converting anything I’m just passing string to all params ,
except on the _salt parameter I do not set any value
what I’m trying to do is to interact with this function

can you show me where exactly you are getting the error ?
you can pass all as a string, but the _salt should be in byte so the smart contract can processed it

1 Like

This error happens when use useWeb3Contract hook to execute on-chain function

the function i am using to runc contract is this one

const runContract = useWeb3ExecuteFunction()
 async function createEventFunc() {
        let options = {
          chain: "rinkeby",
          contractAddress:  "0xD8C88BE5e8EB88E38E6ff5cE186d764676012B0b",
          functionName: "createLock",
           abi: unlockABI2,
           //Parameters 
           params: {
            _expirationDuration: "100",
            _tokenAddress:  "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",  //USDC ADDRESS
            _keyPrice:   "120",
            _maxNumberOfKeys: "300",
            _lockName: "abdul",
            
          },
         
           
        }
        await runContract({
          params: options,
          onSuccess:() =>{
            alert("you  have  succesful  ran  function")
          },
          onError: (errori) =>{
            alert(errori.message)
          }
        })
        console.log("clicked button")
      }

as unlock team said the _salt parameter is deprecated I don’t pass it I omitted it
also this is PROXY contract is there defference between interacting with proxy contract and noraml contract in moralis ??

@0xprof i saw your member of unlock discord server can you take look in developer group today’s discussion, The conversation is related to this question i think this will help to know the source of error

No, they should be the same
ok, i will take a look

thank you i’ll be waiting :blush: for your help

Got another idea

someone answered :point_down:t3:

It shows the smart contract is output format not readable by moralis

is there any way to console the result of smart contract in console ??

This function will not return output as long as it isnt view
Although it has a returns and returns

1 Like