Cannot read properties of undefined (reading 'toHexString')

Hey Devs I want to interact with this smart contract function

but i get this error Cannot read properties of undefined (reading ‘toHexString’)

smart contract function

function createLock(
    uint _expirationDuration, 
    address _tokenAddress, 
    uint _keyPrice, 
    uint _maxNumberOfKeys, 
    string calldata _lockName, 
    bytes12 _salt 
  ) external returns(address); 

here is my front-end function to interact with smart contract function

all parameters states

const [eventDuration, setEventDuration]  =  useState("")  //for  _expirationDuration
const [ticketQuantity, setTicketQuantiy]  =  useState("")  // for  _maxNumberOfKeys
 const [ticketPrice, setTicketPrice]  =  useState("")  // for  _keyPrice
 const [eventName, setEventName]  =  useState("") // for  _lockName
   const [salt, setSalt]  =  useState("abdul") // for  _salt 
 const usdcContract  = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"  // for  _tokenAddress

const contractExcuter = useWeb3ExecuteFunction()

// // create event  function

async function createEventFunc() {
        let options = {
          contractAddress:  unlockAddress,
          functionName: "createLock",
           abi: unlockABI,
           //Parameters 
           params: {
            
            _expirationDuration: eventDuration,
            _tokenAddress: usdcContract,
            _keyPrice: ticketPrice,
            _maxNumberOfKeys: ticketQuantity,
            _lockName: eventName, 
            _salt: "abdul"
             
           },
          
           
        }
        await contractExcuter.fetch({
          params: options,
          onSuccess:() =>{
            alert("you  have  succesful  ran  function")
          },
          onError: (errori) =>{
            alert(errori.message)
          }
        })
        console.log("clicked button")
      }


what could be the source of the problem

Maybe is this salt that is expected to be of a specific type and not a string.

Here is the protocol repo https://github.com/unlock-protocol/unlock/blob/master/smart-contracts/contracts/Unlock.sol

can you give it a look :pray:

Maybe you can find an example on blockchain with a transaction and see the expected parameters there

it shows input must be bytes i have no idea about bytes
here is how salt explained in documentation :point_down:

bytes12 _salt // Unique salt used to compute the counterfactual lock address

Did you try to search on google what bytes12 means?

found this as an example online: bytes8 example = 0x11030330f020D5C5;
you could add 4 more bytes encoded in hex to have 12 bytes

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