1

I want to call a function from another contract. Can I pass a string?

IUpgrade(upgradeAddress).wrap(label, wrappedOwner, _fuses, resolver);

label is a string. I read somewhere that you can't pass strings between contracts, but maybe that was only for an older version of solidity.

2 Answers 2

0

I just tested it out on remix.ethereum and made a demo code below , and yes you can send string between contracts since contract functions are still functions :D

  • However the contract function parameter must have a string parameter to take in a string
    function foo(string memory content) public pure returns(string memory) {
            return content;
    }
1
  • 1
    Thanks for the tip to just jump into Remix and try it.
    – nxt3d
    Mar 4, 2022 at 3:32
0

This is the code I used to test it in Remix.

pragma solidity ^0.8.4;


interface IName {

    function upgrade (string calldata name) external;

}

contract Storage {

    address public upgradeAddress;


    function setUpgradeAddress(address _upgradeAddress)
        public
    {
            upgradeAddress = _upgradeAddress;
    }

 
    function upgrade(string calldata name) public {
        IName(upgradeAddress).upgrade(name);
    }


}

contract UpgradeStorage is IName{

    string public name;
    
    function upgrade(string calldata _name) public override{
        name = _name;
    }

}

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.