Passing Empty String to executeFunction()

Hello,

I have a contract function with the ABI below:

{
      "inputs": [
        {
          "internalType": "uint256",
          "name": "numberOfTokens",
          "type": "uint256"
        },
        {
          "internalType": "enum SalientYachtsSYONE_v02.NFTType",
          "name": "nftType",
          "type": "uint8"
        },
        {
          "internalType": "string",
          "name": "affiliateId",
          "type": "string"
        }
      ],
      "name": "buyYachtNFT",
      "outputs": [],
      "stateMutability": "payable",
      "type": "function"
    }

The affiliateId parameter is supposed to be optional. However, I am having an issue where if I pass a value for affiliateId, the transaction is executed (connecting with MetaMask). However, if I pass an empty string for affiliateId, I get the error below:

‘affiliateId is required’

I am not sure where that error is coming from and would like to be able to pass an empty string to the method above. How can I do that? Thanks!

The stack trace is below:

App.jsx:149 ----> noOfNfts     =  1
App.jsx:150 ----> nftTxnAmount =  100000000000000000
App.jsx:151 ----> affiliateId  =  
App.jsx:162 Uncaught (in promise) ['affiliateId is required']0: "affiliateId is required"length: 1[[Prototype]]: Array(0)
onClick @ App.jsx:162
await in onClick (async)
handleClick @ button.js:201
callCallback @ react-dom.development.js:3945
invokeGuardedCallbackDev @ react-dom.development.js:3994
invokeGuardedCallback @ react-dom.development.js:4056
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:4070
executeDispatch @ react-dom.development.js:8243
processDispatchQueueItemsInOrder @ react-dom.development.js:8275
processDispatchQueue @ react-dom.development.js:8288
dispatchEventsForPlugins @ react-dom.development.js:8299
(anonymous) @ react-dom.development.js:8508
batchedEventUpdates$1 @ react-dom.development.js:22396
batchedEventUpdates @ react-dom.development.js:3745
dispatchEventForPluginEventSystem @ react-dom.development.js:8507
attemptToDispatchEvent @ react-dom.development.js:6005
dispatchEvent @ react-dom.development.js:5924
unstable_runWithPriority @ scheduler.development.js:468
runWithPriority$1 @ react-dom.development.js:11276
discreteUpdates$1 @ react-dom.development.js:22413
discreteUpdates @ react-dom.development.js:3756
dispatchDiscreteEvent @ react-dom.development.js:5889

it may be a problem in the executeFunction code, it may consider that an empty string is as there was no data provided for that parameter

Thank you @cryptokid - is there a workaround for this? or should I create two methods on the contract one that accepts the affiliateId param and one that does not. Then let the front-end decide which one to call?

you can use web3 directly to make the transaction instead of executeFunction, or create 2 methods as you said, or try to check what is wrong in executeFunction code, or change the method so what a string as “-” is ignored by the function and it considers that the parameter was not provided

Thanks we will check asap