0

I was recently viewing a DApp on GitHub. The following is a part of .sol

    address contractOwner;
    address withdrawWallet;

    function contractName(address _contractOwner, address _withdrawWallet) {
        require(_contractOwner != address(0));
        require(_withdrawWallet != address(0));

        contractOwner = _contractOwner;
        withdrawWallet = _withdrawWallet;
    }

When I publish the app, am I supposed to assign values to contractOwner, and withdrawWallet? Something like

address contractOwner = "0xc0f ... legit wallet address";
address withdrawWallet = "0x00010dB ... legit wallet address";
function contractName(address _contractOwner, address _withdrawWallet) {
    require(_contractOwner != address(0));
    require(_withdrawWallet != address(0));

    contractOwner = _contractOwner;
    withdrawWallet = _withdrawWallet;
 }

2_deploy_contract.js contains

  const owner = accounts[0];
  if (network == "live") {
    const withdrawWallet = "0x00010dB ... legit wallet address";
    deployer.deploy(contractName, owner, withdrawWallet);
    return;
  }

Thanks a ton.

0

You can do that, but you should remove the function contractName(...) in .sol and also change the deployment script to deployer.deploy(contractName).

You have this function in your contract which is not correct

function contractName(address _contractOwner, address _withdrawWallet)

it can be called by anyone and changes the contract owner and the withdrawWallet.

However, the correct and better way is:

I don't know who wrote the contract and script but his idea is to give the parameters owner and withdrawWallet when the contract is deployed (only once and can't be changed)

so what you should do is change the contract (transform the method to constructor) like this:

    address contractOwner;
    address withdrawWallet;

    constructor(address _contractOwner, address _withdrawWallet) public {
        require(_contractOwner != address(0));
        require(_withdrawWallet != address(0));
        contractOwner = _contractOwner;
        withdrawWallet = _withdrawWallet;
    }

and you can keep the deployment script and replace the parameters there

  const owner = "0xc0f ... legit wallet address";
  if (network == "live") {
    const withdrawWallet = "0x00010dB ... legit wallet address";
    deployer.deploy(contractName, owner, withdrawWallet);
    return;
  }

can you share your truffle-config(make sure you remove any sensitive data from it)? cause deploying it to "live" mean usually the ethereum main net and you should try first on one of the ethereum test net.

2
  • my truffle config - codepile.net/pile/Vno9EGZP – dragic34 Mar 28 at 16:12
  • @dragic34 okay live is localhost with the Id of the main network, u don’t want to us that. Are u willing to deploy the contract somewhere ? If yes do u know how to change those thing to use infura and rinkeby or other test networks and do u know how to use hdwalletprovider to sign transactions – Majd TL Mar 28 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.