1

What is the approach to take an array as input from the user on frontend and then storing it in useState and pass it to a smart contract using ethers. I am just unable to create the correct format. Using react for frontend.

This is the function I wanna call.

   // SPDX-License-Identifier: SEE LICENSE IN LICENSE

pragma solidity ^0.8.0;

import "./MultiSig.sol";

contract ZarFactory {
    event Created(MultiSig walletAddress, address creator);

    function createWallet(address[] memory _owners, uint requiredSignature) external {
        MultiSig wallet = new MultiSig(_owners,requiredSignature);

        emit Created(wallet, msg.sender);
    }
}
3
  • An array of what exactly? Providing some snippets of what code you have would be helpful.
    – PSS
    Feb 28 at 3:47
  • Updated the question Mar 1 at 8:36
  • The contract is fine. I am not a frontend dev that's why unable to take correct input from the frontend and pass it to the contract. Mar 1 at 8:56

1 Answer 1

0

To pass an array to smart contract function from your React component, you can use the ethers.utils.arrayify function to convert the array to a format that can be passed to the smart contract

Here's a simple example

const values = [1, 2, 3, 4, 5];
const valuesBytes = ethers.utils.arrayify(values);

setValues(valuesBytes);

After setting the state in react component you can pass that array to the smart contract

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.