2

I have seen some examples of Contracts where people are passing other Contract or Interface as a parameter. (Linear example, Synthetix example. However, when I was trying it in one of my contracts, I face the following error consistently. It can be reproduced with the following code.

NOTE: The error is huge. I exceeded Github's content body limit, so pasting the error as a gist here https://gist.github.com/r4881t/2adceda43d25927ddc265dd645edee22

contracts/A.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.1;

contract A {
  uint public value;

  function setV(uint _x) public { value = _x; }
  function getV() public view returns (uint) { return value; }
}

contracts/B.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.1;

import "./A.sol";

contract B {
  uint public someValue;

  function setVal(A _a) public { someValue = _a.value(); }
  function getVal() public view returns (uint) { return someValue; }

}

My test that throws this error is

tests/testB.js

const A = artifacts.require("./A.sol");
const B = artifacts.require("./B.sol");

let a, b, c;

contract('B', (accounts) => {
  beforeEach(async() => {
    a = await A.new();
    console.log("A @", a.address);

    b = await B.new();
    console.log("B @", b.address);
  })

  it('is able to pass A as a parameter', async() => {
    c = await B.new();
    await c.setVal(a);

  })
})

Here's the output of my test

pra@MacBook-Pro-2 testArgumentPassing % truffle test --network development
Using network 'development'.


Compiling your contracts...
===========================
> Compiling ./contracts/B.sol
> Artifacts written to /var/folders/jn/1xhkgc6x5h39kptrbcs7z18m0000gn/T/test--17214-bDMlrcw2WZby
> Compiled successfully using:
   - solc: 0.7.1+commit.f4a555be.Emscripten.clang



  Contract: B
A @ 0xa979130554ec1b5940Ce621F2ac3324aec08d87a
B @ 0xf80d8Ef0BB02459F53aB511011Cb52801eae2AeD
    1) is able to pass A as a parameter
    > No events were emitted


  0 passing (1s)
  1 failing

  1) Contract: B
       is able to pass A as a parameter:
     Error: invalid address (argument="address", value={"constructor":{"contractName":"A","abi":[{"inputs":[],"name":"value","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x3fa4f245"},{"inputs":[{"internalType":"uint256","name":"_x","type":"uint256"}],"name":"setV","outputs":[],"stateMutability":"nonpayable","type":"function","signature":"0xaf6dcca3"},{"inputs":[],"name":"getV","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x78eb1c3d"}],"metadata":"{\"compiler\":{\"version\":\"0.7.1+commit.f4a555be\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"getV\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_x\",\"type\":\"uint256\"}],\"name\":\"setV\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"value\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"/Users/rae/wark/test/testArgumentPassing/contracts/A.sol\":\"A\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"/Users/rae/wark/test/testArgumentPassing/contracts/A.sol\":{\"keccak256\":\"0x7157e12f50a7006067f9eb4b1619f0cb611ef6cf0abf6cb4401b3efd732f29aa\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48a7e109e94e69c07af3543f0ef4fd9f891f8c96e5f6661d0fe9f2e1d59fbc95\",\"dweb:/ipfs/QmdwsMuxdpR84aodrSNjR13wK3cRXcDeYwsaDQA5ZHR1Ut\"]}},\"version\":1}","bytecode":"0x608060405234801561001057600080fd5b5060f38061001f6000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fa4f24514604157806378eb1c3d14605d578063af6dcca3146079575b600080fd5b604760a4565b6040518082815260200191505060405180910390f35b606360aa565b6040518082815260200191505060405180910390f35b60a260048036036020811015608d57600080fd5b810190808035906020019092919050505060b3565b005b60005481565b60008054905090565b806000819055505056fea2646970667358221220ed65c4fabb69e8a0919d5c57f7cc538bd8f65f6cf5a68cdc493f3e52d4d5ee8e64736f6c63430007010033","deployedBytecode":"0x6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fa4f24514604157806378eb1c3d14605d578063af6dcca3146079575b600080fd5b604760a4565b6040518082815260200191505060405180910390f35b606360aa565b6040518082815260200191505060405180910390f35b60a260048036036020811015608d57600080fd5b810190808035906020019092919050505060b3565b005b60005481565b60008054905090565b806000819055505056fea2646970667358221220ed65c4fabb69e8a0919d5c57f7cc538bd8f65f6cf5a68cdc493f3e52d4d5ee8e64736f6c63430007010033","immutableReferences":{},"sourceMap":"57:147:0:-:0;;;;;;;;;;;;;;;;;;;","deployedSourceMap":"57:147:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;72:17;;;:::i;:::-;;;;;;;;;;;;;;;;;;;142:60;;;:::i;:::-;;;;;;;;;;;;;;;;;;;94:45;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;72:17;;;;:::o;142:60::-;179:4;194:5;;187:12;;142:60;:::o;94:45::-;134:2;126:5;:10;;;;94:45;:::o","source":"// SPDX-License-Identifier: MIT\npragma solidity ^0.7.1;\n\ncontract A {\n  uint public value;\n\n  function setV(uint _x) public { value = _x; }\n  function getV() public view returns (uint) { return value; }\n}\n\n","sourcePath":"/Users/rae/wark/test/testArgumentPassing/contracts/A.sol","ast":{"absolutePath":"/Users/rae/wark/test/testArgumentPassing/contracts/A.sol","exportedSymbols":{"A":[22]},"id":23,"license":"MIT","nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity","^","0.7",".1"],"nodeType":"PragmaDirective","src":"32:23:0"},{"abstract":false,"baseContracts":[],"contractDependencies":[],"contractKind":"contract","fullyImplemented":true,"id":22,"linearizedBaseContracts":[22],"name":"A","nodeType":"ContractDefinition","nodes":[{"constant":false,"functionSelector":"3fa4f245","id":3,"mutability":"mutable","name":"value","nodeType":"VariableDeclaration","scope":22,"src":"72:17:0","stateVariable":true,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":2,"name":"uint","nodeType":"ElementaryTypeName","src":"72:4:0","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"visibility":"public"},{"body":{"id":12,"nodeType":"Block","src":"124:15:0","statements":[{"expression":{"id":10,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftHandSide":{"id":8,"name":"value","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":3,"src":"126:5:0","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"Assignment","operator":"=","rightHandSide":{"id":9,"name":"_x","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":5,"src":"134:2:0","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"src":"126:10:0","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":11,"nodeType":"ExpressionStatement","src":"126:10:0"}]},"functionSelector":"af6dcca3","id":13,"implemented":true,"kind":"function","modifiers":[],"name":"setV","nodeType":"FunctionDefinition","parameters":{"id":6,"nodeType":"ParameterList","parameters":[{"constant":false,"id":5,"mutability":"mutable","name":"_x","nodeType":"VariableDeclaration","scope":13,"src":"108:7:0","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":4,"name":"uint","nodeType":"ElementaryTypeName","src":"108:4:0","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"visibility":"internal"}],"src":"107:9:0"},"returnParameters":{"id":7,"nodeType":"ParameterList","parameters":[],"src":"124:0:0"},"scope":22,"src":"94:45:0","stateMutability":"nonpayable","virtual":false,"visibility":"public"},{"body":{"id":20,"nodeType":"Block","src":"185:17:0","statements":[{"expression":{"id":18,"name":"value","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":3,"src":"194:5:0","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"functionReturnParameters":17,"id":19,"nodeType":"Return","src":"187:12:0"}]},"functionSelector":"78eb1c3d","id":21,"implemented":true,"kind":"function","modifiers":[],"name":"getV","nodeType":"FunctionDefinition","parameters":{"id":14,"nodeType":"ParameterList","parameters":[],"src":"155:2:0"},"returnParameters":{"id":17,"nodeType":"ParameterList","parameters":[{"constant":false,"id":16,"mutability":"mutable","name":"","nodeType":"VariableDeclaration","scope":21,"src":"179:4:0","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":15,"name":"uint","nodeType":"ElementaryTypeName","src":"179:4:0","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"visibility":"internal"}],"src":"178:6:0"},"scope":22,"src":"142:60:0","stateMutability":"view","virtual":false,"visibility":"public"}],"scope":23,"src":"57:147:0"}],"src":"32:174:0"},"legacyAST":{"attributes":{"absolutePath":"/Users/rae/wark/test/testArgumentPassing/contracts/A.sol","exportedSymbols":{"A":[22]},"license":"MIT"},"children":[{"attributes":{"literals":["solidity","^","0.7",".1"]},"id":1,"name":"PragmaDirective","src":"32:23:0"},{"attributes":{"abstract":false,"baseContracts":[null],"contractDependencies":[null],"contractKind":"contract","fullyImplemented":true,"linearizedBaseContracts":[22],"name":"A","scope":23},"children":[{"attributes":{"constant":false,"functionSelector":"3fa4f245","mutability":"mutable","name":"value","scope":22,"stateVariable":true,"storageLocation":"default","type":"uint256","visibility":"public"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":2,"name":"ElementaryTypeName","src":"72:4:0"}],"id":3,"name":"VariableDeclaration","src":"72:17:0"},{"attributes":{"functionSelector":"af6dcca3","implemented":true,"isConstructor":false,"kind":"function","modifiers":[null],"name":"setV","scope":22,"stateMutability":"nonpayable","virtual":false,"visibility":"public"},"children":[{"children":[{"attributes":{"constant":false,"mutability":"mutable","name":"_x","scope":13,"stateVariable":false,"storageLocation":"default","type":"uint256","visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":4,"name":"ElementaryTypeName","src":"108:4:0"}],"id":5,"name":"VariableDeclaration","src":"108:7:0"}],"id":6,"name":"ParameterList","src":"107:9:0"},{"attributes":{"parameters":[null]},"children":[],"id":7,"name":"ParameterList","src":"124:0:0"},{"children":[{"children":[{"attributes":{"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"operator":"=","type":"uint256"},"children":[{"attributes":{"overloadedDeclarations":[null],"referencedDeclaration":3,"type":"uint256","value":"value"},"id":8,"name":"Identifier","src":"126:5:0"},{"attributes":{"overloadedDeclarations":[null],"referencedDeclaration":5,"type":"uint256","value":"_x"},"id":9,"name":"Identifier","src":"134:2:0"}],"id":10,"name":"Assignment","src":"126:10:0"}],"id":11,"name":"ExpressionStatement","src":"126:10:0"}],"id":12,"name":"Block","src":"124:15:0"}],"id":13,"name":"FunctionDefinition","src":"94:45:0"},{"attributes":{"functionSelector":"78eb1c3d","implemented":true,"isConstructor":false,"kind":"function","modifiers":[null],"name":"getV","scope":22,"stateMutability":"view","virtual":false,"visibility":"public"},"children":[{"attributes":{"parameters":[null]},"children":[],"id":14,"name":"ParameterList","src":"155:2:0"},{"children":[{"attributes":{"constant":false,"mutability":"mutable","name":"","scope":21,"stateVariable":false,"storageLocation":"default","type":"uint256","visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":15,"name":"ElementaryTypeName","src":"179:4:0"}],"id":16,"name":"VariableDeclaration","src":"179:4:0"}],"id":17,"name":"ParameterList","src":"178:6:0"},{"children":[{"attributes":{"functionReturnParameters":17},"children":[{"attributes":{"overloadedDeclarations":[null],"referencedDeclaration":3,"type":"uint256","value":"value"},"id":18,"name":"Identifier","src":"194:5:0"}],"id":19,"name":"Return","src":"187:12:0"}],"id":20,"name":"Block","src":"185:17:0"}],"id":21,"name":"FunctionDefinition","src":"142:60:0"}],"id":22,"name":"ContractDefinition","src":"57:147:0"}],"id":23,"name":"SourceUnit","src":"32:174:0"},"compiler":{"name":"solc","version":"0.7.1+commit.f4a555be.Emscripten.clang"},"networks":{},"schemaVersion":"3.3.4","updatedAt":"2021-04-03T00:59:56.097Z","networkType":"ethereum","devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"methods":{},"abi":[{"inputs":[],"name":"value","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x3fa4f245"},{"inputs":[{"internalType":"uint256","name":"_x","type":"uint256"}],"name":"setV","outputs":[],"stateMutability":"nonpayable","type":"function","signature":"0xaf6dcca3"},{"inputs":[],"name":"getV","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x78eb1c3d"}],"address":"0xa979130554ec1b5940Ce621F2ac3324aec08d87a","transactionHash":"0x72688f0b4b81034dfed9e1a2e4e2ab969cf6607d2b27308f2cbf815a90aba90a","contract":{"currentProvider":{"withCredentials":false,"timeout":0,"connected":true,"host":"http://127.0.0.1:8545","httpAgent":{"_events":{},"_eventsCount":2,"defaultPort":80,"protocol":"http:","options":{"keepAlive":false,"path":null},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"scheduling":"fifo","maxTotalSockets":null,"totalSocketCount":0},"_alreadyWrapped":true},"_requestManager":{"provider":{"withCredentials":false,"timeout":0,"connected":true,"host":"http://127.0.0.1:8545","httpAgent":{"_events":{},"_eventsCount":2,"defaultPort":80,"protocol":"http:","options":{"keepAlive":false,"path":null},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"scheduling":"fifo","maxTotalSockets":null,"totalSocketCount":0},"_alreadyWrapped":true},"providers":{},"subscriptions":{}},"givenProvider":null,"providers":{},"_provider":{"withCredentials":false,"timeout":0,"connected":true,"host":"http://127.0.0.1:8545","httpAgent":{"_events":{},"_eventsCount":2,"defaultPort":80,"protocol":"http:","options":{"keepAlive":false,"path":null},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"scheduling":"fifo","maxTotalSockets":null,"totalSocketCount":0},"_alreadyWrapped":true},"options":{"address":"0xa979130554ec1b5940Ce621F2ac3324aec08d87a","jsonInterface":[{"inputs":[],"name":"value","outputs":{"constant":false,"mutability":"mutable","name":"_x","scope":13,"stateVariable":false,"storageLocation":"default","type":"uint256","visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":4,"name":"ElementaryTypeName","src":"108:4:0"}],"id":5,"name":"VariableDeclaration","src":"108:7:0"}],"id":6,"name":"ParameterList","src":"107:9:0"},{"attributes":{"parameters":[null]},"children":[],"id":7,"name":"ParameterList","src":"124:0:0"},{"children":[{"children":[{"attributes":{"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"operator":"=","type":"uint256"},"children":[{"attributes":{"overloadedDeclarations":[null],"referencedDeclaration":3,"type":"uint256","value":"value"},"id":8,"name":"Identifier","src":"126:5:0"},{"attributes":{"overloadedDeclarations":[null],"referencedDeclaration":5,"type":"uint256","value":"_x"},"id":9,"name":"Identifier","src":"134:2:0"}],"id":10,"name":"Assignment","src":"126:10:0"}],"id":11,"name":"ExpressionStatement","src":"126:10:0"}],"id":12,"name":"Block","src":"124:15:0"}],"id":13,"name":"FunctionDefinition","src":"94:45:0"},{"attributes":{"functionSelector":"78eb1c3d","implemented":true,"isConstructor":false,"kind":"function","modifiers":[null],"name":"getV","scope":22,"stateMutability":"view","virtual":false,"visibility":"public"},"children":[{"attributes":{"parameters":[null]},"children":[],"id":14,"name":"ParameterList","src":"155:2:0"},{"children":[{"attributes":{"constant":false,"mutability":"mutable","name":"","scope":21,"stateVariable":false,"storageLocation":"default","type":"uint256","visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":15,"name":"ElementaryTypeName","src":"179:4:0"}],"id":16,"name":"VariableDeclaration","src":"179:4:0"}],"id":17,"name":"ParameterList","src":"178:6:0"},{"children":[{"attributes":{"functionReturnParameters":17},"children":[{"attributes":{"overloadedDeclarations":[null],"referencedDeclaration":3,"type":"uint256","value":"value"},"id":18,"name":"Identifier","src":"194:5:0"}],"id":19,"name":"Return","src":"187:12:0"}],"id":20,"name":"Block","src":"185:17:0"}],"id":21,"name":"FunctionDefinition","src":"142:60:0"}],"id":22,"name":"ContractDefinition","src":"57:147:0"}],"id":23,"name":"SourceUnit","src":"32:174:0"},"compiler":{"name":"solc","version":"0.7.1+commit.f4a555be.Emscripten.clang"},"networks":{},"schemaVersion":"3.3.4","updatedAt":"2021-04-03T00:59:56.097Z","networkType":"ethereum","devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"methods":{},"abi":[{"inputs":[],"name":"value","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x3fa4f245"},{"inputs":[{"internalType":"uint256","name":"_x","type":"uint256"}],"name":"setV","outputs":[],"stateMutability":"nonpayable","type":"function","signature":"0xaf6dcca3"},{"inputs":[],"name":"getV","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x78eb1c3d"}],"address":"0xa979130554ec1b5940Ce621F2ac3324aec08d87a","transactionHash":"0x72688f0b4b81034dfed9e1a2e4e2ab969cf6607d2b27308f2cbf815a90aba90a","contract":{"currentProvider":{"withCredentials":false,"timeout":0,"connected":true,"host":"http://127.0.0.1:8545","httpAgent":{"_events":{},"_eventsCount":2,"defaultPort":80,"protocol":"http:","options":{"keepAlive":false,"path":null},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"scheduling":"fifo","maxTotalSockets":null,"totalSocketCount":0},"_alreadyWrapped":true},"_requestManager":{"provider":{"withCredentials":false,"timeout":0,"connected":true,"host":"http://127.0.0.1:8545","httpAgent":{"_events":{},"_eventsCount":2,"defaultPort":80,"protocol":"http:","options":{"keepAlive":false,"path":null},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"scheduling":"fifo","maxTotalSockets":null,"totalSocketCount":0},"_alreadyWrapped":true},"providers":{},"subscriptions":{}},"givenProvider":null,"providers":{},"_provider":{"withCredentials":false,"timeout":0,"connected":true,"host":"http://127.0.0.1:8545","httpAgent":{"_events":{},"_eventsCount":2,"defaultPort":80,"protocol":"http:","options":{"keepAlive":false,"path":null},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"scheduling":"fifo","maxTotalSockets":null,"totalSocketCount":0},"_alreadyWrapped":true},"options":{"address":"0xa979130554ec1b5940Ce621F2ac3324aec08d87a","jsonInterface":[{"inputs":[],"name":"value","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x3fa4f245"},{"inputs":[{"internalType":"uint256","name":"_x","type":"uint256"}],"name":"setV","outputs":[],"stateMutability":"nonpayable","type":"function","signature":"0xaf6dcca3"},{"inputs":[],"name":"getV","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x78eb1c3d"}]},"handleRevert":false,"transactionPollingTimeout":750,"transactionConfirmationBlocks":24,"transactionBlockTimeout":50,"defaultAccount":null,"defaultBlock":"latest","methods":{},"events":{},"_address":"0xa979130554ec1b5940Ce621F2ac3324aec08d87a","_jsonInterface":[{"inputs":[],"name":"value","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x3fa4f245"},{"inputs":[{"internalType":"uint256","name":"_x","type":"uint256"}],"name":"setV","outputs":[],"stateMutability":"nonpayable","type":"function","signature":"0xaf6dcca3"},{"inputs":[],"name":"getV","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function","constant":true,"signature":"0x78eb1c3d"}],"transactionHash":"0x72688f0b4b81034dfed9e1a2e4e2ab969cf6607d2b27308f2cbf815a90aba90a"}}, code=INVALID_ARGUMENT, version=abi/5.0.0-beta.153)
      at Context.<anonymous> (test/Btest.js:17:13)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)



pra@MacBook-Pro-2 testArgumentPassing %

I can have a workaround where I can change the parameter from A to address and it works. But I don't want to do that.

1 Answer 1

3

The problem is passing a as parameter

await c.setVal(a);

For it to work you have to pass its address

await c.setVal(a.address);
2
  • 1
    Can confirm this works. I thought that if i pass the address, I will also have to change the parameter type from A to address. Isn't this somehow misleading?
    – pr4n
    Apr 3, 2021 at 2:22
  • 2
    @pr4n It is kinda of confusing. For the ABI specification all contracts used as parameters are addresses.
    – Ismael
    Apr 3, 2021 at 2:30

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.