1

Simple deployment command of a contract with two constructor arguments using forge is as follows
forge create src/Contract.sol:MyToken --constructor-args "My Token" "MT"

But in my case, I should pass some objects as constructor arguments to deploy a contract similar to below one

struct DiamondArgs {
    address owner;
    address init;
    bytes initCalldata;
}

contract MyContract {
    constructor(DiamondArgs memory _args) {}
}

So, the deployment command would look like this
forge create src/MyContract.sol:MyContract --constructor-args '{owner: "ownerAddress", init: "initAddress", initCalldata: "initCalldata"}'

When trying to pass that object, the result looks like this :
forge create --constructor-args [object Object] ...

What's the workaround for this?

4
  • Why is your struct DiamondArgs declared outside of your contract? Commented Dec 5, 2022 at 5:52
  • It's a global variable, will also be used in inherited contracts, not only in MyContract contract Commented Dec 5, 2022 at 14:41
  • 2
    Here is a final answer to this issue with the reference of @OlivierD's answer. When using --constructor-args, the deployment command would look something like this. forge create src/MyContract.sol:MyContract --constructor-args '(0xMyAddress1,0xMyAddress2,0x03)' When using --constructor-args-path, forge create src/MyContract.sol:MyContract --constructor-args-path args And in the arg file(with no extension), the content is as follows (0xMyAddress1,0xMyAddress2,0x03) Please be careful not to add whitespace between arguments Commented Dec 7, 2022 at 8:13
  • This has been tested in this repo Commented Dec 7, 2022 at 8:16

1 Answer 1

1

Ok, took me too long to figure it out but you can pass objects by using --constructor-args-path and creating a file named 'args' with your arguments in it.

In your case:

(0xMyAddress1, 0xMyAddress2, 0x03)

Hope this helps, let me know if you have questions!

6
  • Thanks a lot @OlivierD. but how does the args file look like? args.json? I've tried --constructor-args-path in a few ways, but still no hope Commented Dec 5, 2022 at 14:42
  • I create a file ‘args’. No .txt, .json, .whatever. Just ‘args’. In it, with vscode, I wrote “(0xMyAddress1, 0xMyAddress2, 0x03)“ and it worked Commented Dec 5, 2022 at 23:40
  • Not working on my side, Could you check this repo and test? Commented Dec 6, 2022 at 1:25
  • 1
    Just cloned your repo. So, first, remove the " around the parentheses of (0x9F79941335e54A11eCD13cedf58375657FdA97A1, 0x9F79941335e54A11eCD13cedf58375657FdA97A1). Second, change those addresses. Didn't work for me when I tried with those 2 addresses so replaced it with my metamask address and it worked on the first try. Don't know if it's a checksum issue or what... Let me know if this works and mark my answer as valid and upvote if it helped you! Thanks Commented Dec 6, 2022 at 4:25
  • Yeah, thanks for your detailed explanation, but seems it's not related checksum issue, I guess. That worked with original addresses on my side, though in case of ContractV1. I have updated the repo with 2 contracts, it will be more understandable for what I'v faced Commented Dec 6, 2022 at 14:50

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.