Giter VIP home page Giter VIP logo

Comments (13)

kramer65 avatar kramer65 commented on May 18, 2024 151

For any future readers. The solution is to simply provide the constructor arguments after the Contract name in the deploy method:

deployer.deploy(Test, "This is the first constructor argument", "and this is another one");

from truffle.

iam-peekay avatar iam-peekay commented on May 18, 2024 24

@elenadimitrova that's right.

var MyContract = artifacts.require("./MyContract.sol");

module.exports = function(deployer) {
    deployer.deploy(MyContract, arg1, arg2, arg3);
}

from truffle.

lorepieri8 avatar lorepieri8 commented on May 18, 2024 20

This functionality is so basic that I would suggest including it with an explicit example in the contracts generated with truffle init.

from truffle.

tcoulter avatar tcoulter commented on May 18, 2024 16

Closing, as if you have complex deployment needs you should manage that yourself.

from truffle.

kramer65 avatar kramer65 commented on May 18, 2024 12

I think it is quite weird that providing contract constructor arguments is considered "complex". Is there still no possibility to provide these at this moment (a year after this question was posted)?

from truffle.

chuacw avatar chuacw commented on May 18, 2024 6

Hi @nickjuntilla See example below.

--- Solidity contract ----
pragma solidity ^0.4;

contract testContract {

string public mymsg;
int public value;

function testContract(string _msg, int _value) {
mymsg = _msg;
value = _value;
}
}
---- Truffle test script -----
"use strict";
const TestContract = artifacts.require('./testContract.sol');

contract('TestContract', function(accounts) {

let wallet = accounts[2];
let anotherwallet = accounts[3];
let thirdwallet = accounts[4];
let TestContractInstance = null;

beforeEach('setup contract for each test', async() => {
TestContractInstance = await TestContract.new("Hello", 5);
})

it('should have msg and value initialized', async() => {
let value = await TestContractInstance.value();
let mymsg = await TestContractInstance.mymsg();
assert.equal(value, 5);
assert.equal(mymsg, "Hello");
})

})

from truffle.

tcoulter avatar tcoulter commented on May 18, 2024 4

It's not, currently. Truffle hasn't taken a stance on what the ideal deployment structure should be. When deploying contracts with truffle deploy, the constructors shouldn't take an argument - these will be your hub contracts, and ones that exist as an intermediary so you can update your other contracts later. For more complex deployment options, check out Myth 8 here, where truffle exec is used to run a custom deploy: https://medium.com/@timothyjcoulter/truffle-tricks-for-ethereum-development-dispelling-8-myths-first-impressions-880f66bf3320

from truffle.

nickjuntilla avatar nickjuntilla commented on May 18, 2024 3

I am trying to do unit tests and using module exports in the test directory before Contract.deployed() isn't working. How do you unit test a contract that has parameters?

from truffle.

FaizulMustafiz avatar FaizulMustafiz commented on May 18, 2024 2

can it be done ???
var Test= artifacts.require('./Test.sol');
var testType= document.getElementById('testType');
var type= parseInt(testType);

module.exports = function (deployer) {
deployer.deploy(Test, type)
}

i am having trouble with this ... when i am trying to migrate its saying that document is not defined

from truffle.

nickjuntilla avatar nickjuntilla commented on May 18, 2024 1

Thanks @chuacw I'll give that a shot, but I also solved my problem by creating a migration file for the token contract I needed for set up. I didn't realize the tests actually use the main migration files. That's a little annoying since I don't need a migration file for some of the set up contracts my contract depends on. I think it will be cleaner to use .new so I can just test the contract I'm working on in my repo. Thanks!

from truffle.

jjc12 avatar jjc12 commented on May 18, 2024

@kramer65 But it says deployer is undefined.

from truffle.

elenadimitrova avatar elenadimitrova commented on May 18, 2024

@jjc12 are you doing that in the context of 2_deploy_contracts.js

module.exports = function (deployer, network) { deployer.deploy... }

from truffle.

mallapurbharat avatar mallapurbharat commented on May 18, 2024

@FaizulMustafiz

FaizulMustafiz commented on Sep 18, 2017
can it be done ???
var Test= artifacts.require('./Test.sol');
var testType= document.getElementById('testType');
var type= parseInt(testType);

module.exports = function (deployer) {
deployer.deploy(Test, type)
}

i am having trouble with this ... when i am trying to migrate its saying that document is not defined

document is a client-side javascript object (DOM). It would typically not be available in a deploy script.

from truffle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.