1

I know how to pass an ETH address to the constructor in truffle. What is the best way to do it in Remix?

Say contract A is in Remix to create Tokens and contract B (another solidity file) is the actual Crowdsale contract.

What is the best way to send the contract address that is generated when you compile the token contract to the crowdsale's constructor?

For example here is my Constructor:

function Crowdsale(address _tokenAddress) {
    require(_tokenAddress !=0);
    token = Token(_tokenAddress);
  }

I In truffle you pass it in to the 2_deploy_contracts.js file. How would the same be done in Remix?

1 Answer 1

3

Remix will see the constructor needs an argument so it will put a field next to the Create button, in this case labeled _tokenAddress.

Put the token contract address there, in quotes.

In case it isn't clear, deploy the token contract first and copy the deployed address to the clipboard and then paste into Crowdsale's Create (constructor) function.

Hope it helps.

4
  • Hi, I'd like to ask, how about for running unit tests in remix? How would one pass an ERC20 address to instantiate a contract?
    – momoja
    Commented Apr 27, 2022 at 10:24
  • The UI will take it in a field for parameters next to the deploy button. You'll see the variable name hint. Paste it there. Commented Apr 28, 2022 at 5:33
  • Hi, yes I am familiar with UI and testing the contracts manually via on the Deploy and Run tab. But for writing unit tests in solidity, how would one instantiate a contract that needs an already deployed ERC20 address in the constructor?
    – momoja
    Commented Apr 28, 2022 at 8:05
  • I don't use Solidity for testing but this might be what you need: docs.soliditylang.org/en/develop/… Commented Apr 28, 2022 at 15:40

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.