0 votes
1 view
in Blockchain by (12.8k points)

want to pass a single parameter as array into a function call :

contract MyToken is StandaloneERC20 {

function initialize(

     address owner,

        address minter,

        address[] memory pausers

    ) public initializer {

        address[] memory minters = [minter];

        StandaloneERC20.initialize("MyToken", "MTK", uint8(18), minters, pausers);

    }

StandaloneERC20.initialize expects an array for the forth argument minters:

function initialize(

    string memory name, string memory symbol, uint8 decimals, address[] memory minters, address[] memory pausers

) public initializer {

However, using my code I get the following compiler error with solidity 0.5.7:

TypeError: Type address[1] memory is not implicitly convertible to expected type address[] memory.

   address[] memory minters = [minter];

    ^---------------------------------^

I have also tried to pass the minter as array-argument:

contract MyToken is StandaloneERC20 {

    function initialize(

        address owner,

        address minter,

        address[] memory pausers

    ) public initializer {

        StandaloneERC20.initialize("MyToken", "MTK", uint8(18), [minter], pausers);

    }

But this seems to be completely different from what I would expect because of this compiler error:

Member "initialize" not found or not visible after argument-dependent lookup in type(contract StandaloneERC20).

        StandaloneERC20.initialize("MyToken", "MT", uint8(18), [minter], pausers);

        ^------------------------^

How can I pass a single argument as array?

1 Answer

0 votes
by (29.8k points)

HI, you can refer the code below to declare an array with single argument:

contract MyToken is StandaloneERC20 {
    function initialize(
        address owner,
        address minter,
        address[] memory pausers
    ) public initializer {
        address[] memory minters = new address[](1);
        minters[0] = minter;
        StandaloneERC20.initialize("MyToken", "MTK", uint8(18), minters, pausers);
    }
}

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...