Can't interact with smart contract

**is  solidity function with  external visibility   can be  called   from front-end??**

if yes I donā€™t know why for me if I click the button nothing happens no success/ errors

here is my code
ABI

onst unlockABI = [{"inputs":[{"internalType":"address","name":"_lockAddress","type":"address"},{"internalType":"address","name":"_nftAddress","type":"address"}],"name":"createMapping","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lockAddress","type":"address"},{"internalType":"address","name":"_keyOwner","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bool","name":"isValidKey","type":"bool"}],"name":"hasValidKey","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nftAddresses","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]``

**function**
const contractCaller = useWeb3ExecuteFunction()

 async function config() {

   let options = {

     contractAddress: "0x910F56Fb797D9c7a978a08e73D7280e67eb81372",

     functionName: "createMapping",

      abi: unlockABI,

      params: {

        _lockAddress: lockAddress,

         _nftAddress:  exiAddress,

      },

   }

   await contractCaller.fetch({

     params: options,

     onSuccess:() =>{

       alert("wooow  you  made it")

     },

     onerror: (errori) =>{

       alert(errori)

     }

   })

   console.log("clicked button")

 }
   console.log("clicked button")
**JSX CODE **
`` return  <div>
      <h2>hellow</h2>
      <div className='all-inputs'>
     <input type="text" value={exiAddress} placeholder="your  nfts  address" onChange={ e => setExiAddress(e.target.value)}  />
     <input type="text" value={lockAddress} placeholder="your  lock  address" onChange={ e => setLockAddress(e.target.value)}  />
       
      </div>
     <button onClick={config}>change lock</button>
    </div>`

lockAddress and exiAddress is a form value stored on State
what could be wrong with my code

you can see here how to format code on forum:

hey crypto kid tried to edit but filed to be highlighted decided to paste all codes in this reply

const unlockABI = [{"inputs":[{"internalType":"address","name":"_lockAddress","type":"address"},{"internalType":"address","name":"_nftAddress","type":"address"}],"name":"createMapping","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lockAddress","type":"address"},{"internalType":"address","name":"_keyOwner","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bool","name":"isValidKey","type":"bool"}],"name":"hasValidKey","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nftAddresses","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

function

const contractCaller = useWeb3ExecuteFunction()
 async function config() {
   let options = {
     contractAddress: "0x910F56Fb797D9c7a978a08e73D7280e67eb81372",
     functionName: "createMapping",
      abi: unlockABI,
      params: {
        _lockAddress: lockAddress,
         _nftAddress:  exiAddress,
      },
   }
   await contractCaller.fetch({
     params: options,
     onSuccess:() =>{
       alert("wooow  you  made it")
     },
     onerror: (errori) =>{
       alert(errori)
     }
   })
   console.log("clicked button")
 }

On what network is the contract deployed?

its on renkeby

here is link to actual smart contract
https://rinkeby.etherscan.io/address/0x910F56Fb797D9c7a978a08e73D7280e67eb81372#code

Hey Frens in trying i have found what could be the source of the problem but still i donā€™t whats exact problem and how to solve it

tried to use another contract o polygon worked
the source problem could how i pass parameters ?
here is a solidity function

function createMapping(
    address _lockAddress, 
    address _nftAddress
  ) 
  external 
  {
    require(_lockAddress != address(0), 'Lock address can not be zero');
    require(_nftAddress != address(0), 'ERC721 address can not be zero');

    // make sure lock manager
    IPublicLockV9 lock = IPublicLockV9(_lockAddress);
    require(lock.isLockManager(msg.sender), 'Caller does not have the LockManager role');
    
    // store mapping
    nftAddresses[_lockAddress] = _nftAddress;
  }

how i pass parameters for function

front-end function

async function config() {
   let options = {
     contractAddress:  unlockCAddress,
     functionName: "createMapping",
      abi: unlockABI,
 //Parameters 
      params: {
        _lockAddress: lockAddress,
         _nftAddress:  exiAddress,
        
      },
      
   }
   await contractCaller.fetch({
       
     params: options,
     onSuccess:() =>{
       alert("wooow  you  made it")
     },
     onerror: (errori) =>{
       alert(errori)
     }
   })
   console.log("clicked button")
 }

and ABI For this function is

ABI

const unlockABI = [{"inputs":[{"internalType":"address","name":"_lockAddress","type":"address"},{"internalType":"address","name":"_nftAddress","type":"address"}],
"name":"createMapping","outputs":[],"stateMutability":"nonpayable","type":"function"},]

waiting for your help hackers :slightly_smiling_face:

In your fetch function, thereā€™s onError not onerror, which case matters.
But at first, make sure web3 is enabled if not, you might notice nothing happens

Thank You changing from on onerror to onError helped me to know what i ma doing wrong :smiley:

1 Like