0

This is the deployer contract of truffle react

var MyToken =  artifacts.require("MyToken.sol");
var MyTokenSale = artifacts.require("MyTokenSale.sol");

module.exports = async function(deployer){
    let addr = await wev3.eth.getAccounts();
    await deployer.deploy(MyToken, 10000);
    await deployer.deploy(MyTokenSale, 1, addr[0], MyToken.address);

    let instance = await MyToken.deployed();
    await instance.transfer(MyTokenSale.address, 10000);
}

MyToken contract

// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("GoldBucks", "GLD") {
        _mint(msg.sender, initialSupply);
    }
}

MyTokenSale contract

pragma solidity ^0.8.1;

import "./Crowdsale.sol";

contract MyTokenSale is Crowdsale{
    KycContract kyc;
    constructor(
        uint256 rate,
        address payable wallet,
        IERC20 token // this token will be sent to that particular addres that we specify in the deployer
    )

    Crowdsale(rate,wallet,token) public{

    }
}

What is the use of MyToken.address in the deployer contract?

1 Answer 1

0

In your deployment script, parameters that follow the name of the smart contract (e.g MyTokenSale) are the constructor arguments for that contract.

So you can see arguments for MyTokenSale are: uint256 rate, address payable wallet, IERC20 token

This means in the call await deployer.deploy(MyTokenSale, 1, addr[0], MyToken.address);

rate = 1, wallet = addr[0], token = MyToken.address

{contract}.address is available for access in truffle after the contract is deployed and references the contract's address.

HTH

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.