1

as the official simple of solidity contract SimpleAuction { … function SimpleAuction(uint _biddingTime, address _beneficiary) { beneficiary = _beneficiary; auctionStart = now; biddingTime = _biddingTime; } … } if a normal type,I could write in the 1_initial_migration.js like this module.exports = function(deployer) { var proposalNames = ['huangDY', 'lvDY', 'heiDY']; deployer.deploy(Ballot, proposalNames); };

but it needs a parameter of address type, so how to set the constructor parameters?

4

The short answer is you do it the same way as is your "normal type" example. Just make sure the value you pass in is the address it should be.

var auctionBiddingTime = 111;
var auctionBeneficiaryAddress = "0x123 ...";
deployer.deploy(SimpleAuction, auctionBiddingTime, auctionBeneficiaryAddress);

Possibly a more helpful answer is it doesn't look like SimpleAuction should be migrated at all. I don't think a useful system would work that way.

The constructor accepts a beneficiary address. To me, this implies a separate SimpleAuction contract for each item to be auctioned. That further implies that a useful system will deploy SimpleAuction contracts "on-the-fly" - without help from "migrations". Think of it as post-deployment normal operations.

There are a few ways to accomplish that. The common element is that the address of the beneficiary will have to be known so it can be supplied to the constructor.

Consider deploying a factory for producing new SimpleAuction contracts. It might include something like this:

import "SimpleAuction.sol"; // defines "SimpleAuction"

contract SimpleAuctionFactory {

    function newSimpleAuction(uint duration) returns(address createdAuctionContract) {
        SimpleAuction newSimpleAuction = new SimpleAuction(duration, msg.sender);
        return newSimpleAuction;
    }
}

newSimpleAuction() deploys a new SimpleAuction contract with the duration that was passed in, and the msg.sender address. Whoever called it will be the new SimpleAuction's beneficiary.

In this arrangement, you only need to deploy the factory. Life is pretty simple, because you can use the factory's function to deploy as many SimpleAuctions as needed.

You can also log the SimpleAuctions the factory creates.

import "SimpleAuction.sol"; // defines "SimpleAuction"

contract Hub {

    event LogNewAuction(address auction);

    function newSimpleAuction(uint duration) returns(address createdAuctionContract) {
        SimpleAuction newSimpleAuction = new SimpleAuction(duration, msg.sender);
        LogNewAuction(newSimpleAuction);
        return newSimpleAuction;
    }
}

Hope it's helpful.

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.