I'm trying to call a function with parameters with web3 v1.7.0 .send() method which works fine without any parameters but fails when including them.

A simplified version:

contract Master{
constructor() {}
event AgreementCalled(address[] indexed initialParticipants);
function createAgreement(address[] memory initialParticipants) external {
    emit AgreementCalled (initialParticipants);

called from Javascript with web3

let contractTransaction =  await MasterContract.methods.createAgreement(["0x26..7b", "0xeA8..A3e" ])

I get the following console error

MetaMask - RPC Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"data":{"message":"VM Exception while processing transaction: revert","code":-32000,"data":{"0x680b1ed2c6c24f5150a4fa5d1c764d134d25ab122e14891a2348087e6e7eb51e":{"error":"revert","program_counter":81,"return":"0x"},

Interestingly enough, Ganache UI shows the transaction, including the array Ganache displays values

  • If I remove the parameter (an array of addresses) it works fine, like so: MasterContract.methods.createAgreement().send({from:currentAccount});
  • If I change the array with a simple string both in the contract and javascript, I get the same error.
  • Adding lots of gas, like .send({from:this.eth.currentAccount, gas: 10000000}) doesn't solve it
  • Using Web3 1.7.0, solidity >=0.7.0 <0.9.0, Ganache
  • From Remix it works just fine

Any idea on what can be going on?

1 Answer 1

  1. remove gas
  2. add payable after external

below code works

function createAgreement(address[] memory initialParticipants) external payable {
    emit AgreementCalled (initialParticipants);

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.