0

Suppose that I have a token contract as follow. How can i write the new migration.js file in truffle to deploy the contract?

TestCoin.sol

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";

contract ERC20 is IERC20 {

}

contract TestCoin is ERC20 {

}

1_initial_migration.js

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

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

I am thinking of something like this but not sure if it is correct

var SafeMath = artifacts.require("./SafeMath.sol");
var TestCoin = artifacts.require("./TestCoin.sol");

module.exports = function(deployer) {
  deployer.deploy(SafeMath);
  deployer.link(SafeMath, TestCoin);
  deployer.deploy(TestCoin);
};
0

Yes, you are right, but you need linkind for truffle when you explicitly use imported libraries, meanwhile you can use:

Contract:

pragma solidity ^0.4.23;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";

contract TestCoin is ERC20 {
}

Deployment script:

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

module.exports = function(deployer) {
    deployer.deploy(TestCoin);
};
|improve this answer|||||
  • What do you mean? You mention need linking for truffle when explicitly use imported libraries but in the deployment script example u show did not use link to library – stackdisplay Nov 10 '18 at 12:29
  • 1. Truffle will not ask to link external library. 2. If you use migration for testing purposes you don't need to link SafeMath with TestCoin, because you don't use SafeMath in constructor – Aquila Nov 10 '18 at 13:32
  • I omit the using SafeMath in the code for sample code. .. in the actual code there is using safemath. so do i need to link SafeMath? – stackdisplay Nov 10 '18 at 16:56
  • and what does it mean by truffle will not ask to link external library – stackdisplay Nov 10 '18 at 18:32
  • external library is library from npm package (openzeppelin-solidity), when you use the library you don't need to link. – Aquila Nov 10 '18 at 22:08

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.