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).
    – norganna
    Mar 26 '18 at 14:56

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
    Mar 26 '18 at 14:45
  • 1
    If you have the source code for the library, there is an easier way: stackoverflow.com/questions/46299286/… Mar 26 '18 at 15:07
  • Wow, I had no idea this is possible. Thanks a lot.
    – Arson
    Mar 26 '18 at 15:18
  • Glad to help. Thanks for accepting the answer. ;-) Mar 26 '18 at 15:34

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.