2

I followed the below links

http://y-nakajo.hatenablog.com/entry/2018/01/15/174743

Truffle post-deployment actions

and tried to create a migrations file as below.

const string_lib = artifacts.require('strings.sol');
const safemath_lib = artificats.require('safemath.sol');
const PublishService_contract = artifacts.require('PublishService.sol');

module.exports = function(deployer) {
    deployer.then(async () => {
        await deployer.deploy(string_lib);
        await deployer.deploy(safemath_lib);
    });
    deployer.deploy(PublishService_contract);
    deployer.link(string_lib, PublishService_contract);
    deployer.link(safemath_lib, PublishService_contract);
};

The publish service file here is dependent on strings and safemath libraries. But it gives the below error:

deployer.then(async () => { ^

SyntaxError: Unexpected token (

can someone help me with this?

Even I tried to do it this way, without async calls

const string_lib = artifacts.require('strings.sol');
const safemath_lib = artifacts.require('SafeMath.sol');
const PublishService_contract = artifacts.require('PublishService.sol');

module.exports = function(deployer) {
        deployer.deploy(string_lib).then(() => {  
        deployer.deploy(safemath_lib).then(() => {
                deployer.deploy(PublishService_contract);
        });
    });
    deployer.link(string_lib, PublishService_contract);
    deployer.link(safemath_lib, PublishService_contract);
};

But this also resulted in an error.

Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: Cannot link library: SafeMath has no address. Has it been deployed?

Here is the complete console output.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0xb60508071fa5b0ba282da1c1b8bce5ed2157fff096292e73550bf357f7468f5b
  Migrations: 0xf633f429e089a049cd29189c0505336e69e88173
Saving successful migration to network...
  ... 0x3ad495b3643e84b769a79cdeafe88c158d9f13653f773f6dc074b99bf1a688ee
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Replacing strings...
  ... 0x314516c05d9733925df2832cd8a411af8d0694f89b1050e3c0b2403f4af5c48a
  strings: 0x13e9875bb07843af3f360e4fd274626ba2ba66ef
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: Cannot link library: SafeMath has no address. Has it been deployed?
    at Object.link (/usr/lib/node_modules/truffle/build/webpack:/~/truffle-deployer/src/linker.js:25:1)
    at /usr/lib/node_modules/truffle/build/webpack:/~/truffle-deployer/src/actions/link.js:5:1
    at /usr/lib/node_modules/truffle/build/webpack:/~/truffle-deployer/src/deferredchain.js:20:1
    at process._tickCallback (internal/process/next_tick.js:109:7)
0

In your first attempt, async functions may not be used with your browser. Just try to stack promises.

Your second attempt it is just a javascript async and sync problem. promises are always async so you need to wait for them to finish then call the deployer.link :

const string_lib = artifacts.require('strings.sol');
const safemath_lib = artifacts.require('SafeMath.sol');
const PublishService_contract = artifacts.require('PublishService.sol');

module.exports = function(deployer) {
    deployer.deploy(string_lib).then(() => {
        deployer.deploy(safemath_lib).then(() => {
            deployer.deploy(PublishService_contract).then(()=>{
                deployer.link(string_lib, PublishService_contract);
                deployer.link(safemath_lib, PublishService_contract);
            });

        });
    });
};
  • can you give a sample on how to stack promises. I am totally new to javascripting. – K Kolluru Apr 19 '18 at 12:33
  • The second solution worked :):) – K Kolluru Apr 19 '18 at 12:34
  • what i meant by "stack promises" is something like function().then(res=>{function2().then(res=>{....})}) – Kaki Master Of Time Apr 19 '18 at 12:36
  • that is how i did in the second solution right. But the thing is in this case safemath should wait until the strings is deployed. they two are independent and can be deployed parallely where publish service has to wait until these two are deployed. I am exactly looking for a solution that does this. – K Kolluru Apr 19 '18 at 12:38
  • since they are not related you can deploy the first contract then deploy the safemath and link and in paralell deploy the string lib and link. but this way you won't be able to know exactly when the whole deployment will end. – Kaki Master Of Time Apr 19 '18 at 12:52
0

The problem with the first script is the version of node JS. I was not using a latest version (v6...). After upgrading to latest version (v9.10.1), the script worked as expected. The solution to the second one is already given by kaki and it worked.

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.