Let's assume I have multiple contracts defined, say 1 lib, 1 interface, A contract and B contract and B is A and finally, B uses both, the lib and the interface specified.

The question is, should I pack them up into one file, compile and simply deploy only B like below?

const HDWalletProvider = require('truffle-hdwallet-provider'); 
const Web3 = require('web3'); 

const {interface, bytecode} = require('./compile');
const provider = new HDWalletProvider(
    'https://link to infura'

const web3 = new Web3(provider);
const deploy = async () => {
    const accounts = await web3.eth.getAccounts();
    const result = await web3.eth.Contract(JASON.parse('interface'))
        .deploy({data: bytecode})
        .send({gas: '1000000', from: accounts[0]});



Thanks for help

  • Hey, when you're supplying code, it's best to indent it with 4 spaces to block quote (you can also select and just Command-K or Control-K to indent the selected lines).
    – supakaity
    Commented Mar 26, 2018 at 14:56

1 Answer 1


If I understand your question, everything you described except the Lib are compiler-only concerns. You deploy the Lib, bind B to the Lib at the Lib address and deploy B.

  • That makes sense. However how to bind the library to B? Where to include the information in B to direct it to the lib?
    – Arson
    Commented Mar 26, 2018 at 14:45
  • 1
    If you have the source code for the library, there is an easier way: stackoverflow.com/questions/46299286/… Commented Mar 26, 2018 at 15:07

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.