0

I have a contract in which there is a function which has 16 arguments which is giving me stack too deep error. So I am thinking of passing a javascript object using web3 to the smart contract which I will destructure in the method. So here I have two questions:

  1. How to pass a javascript object using web3 to a smart contract?

  2. How to destructure the object in a smart contract with each field having its respective values?

1 Answer 1

0

You can use solidity structs.

struct MyStruct {
   uint256 number1;
   address address1;
   // ...
}

contract MyContract {
    function foo(MyStruct memory data) public {
        uint256 num1 = data.number1;
        address addr1 = data.address1;
        // ...
    }
}

Using web3js, you should be able to call the function like this:

contract.foo({number1: 123, address1: '0x...'}).send()

Your Answer

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

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