How to use the solc/linker.linkBytecode function in solc

To help you get started, we’ve selected a few solc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OriginProtocol / origin-playground / test / _helper.js View on Github external
// Deploy linked libraries
    for (let linkedFile in bytecode.linkReferences) {
      for (let linkedLib in bytecode.linkReferences[linkedFile]) {
        let libObj = output.contracts[linkedFile][linkedLib]
        let LibContract = new web3.eth.Contract(libObj.abi)
        var libContract = await LibContract.deploy({
          data: libObj.evm.bytecode.object
        }).send({
          from,
          gas: 3000000
        })

        let libs = { [`${linkedFile}:${linkedLib}`]: libContract._address }

        bytecode.object = linker.linkBytecode(bytecode.object, libs)
      }
    }

    if (!bytecode.object) {
      throw new Error(
        'No Bytecode. Do the method signatures match the interface?'
      )
    }

    if (process.env.BUILD) {
      fs.writeFileSync(
        __dirname + '/../src/contracts/' + contractName + '.js',
        'module.exports = ' +
          JSON.stringify(
            {
              abi,
github OriginProtocol / origin / origin-contracts / test-alt / _helper.js View on Github external
]) {
          libObj.evm.bytecode.object = await deployLib(
            linkedFile2,
            linkedLib2,
            libObj.evm.bytecode
          )
        }
      }

      const LibContract = new web3.eth.Contract(libObj.abi)
      const gas = solidityCoverage ? 3000000 * 5 : 3000000
      const libContract = await LibContract.deploy({
        data: libObj.evm.bytecode.object
      }).send({ from, gas })
      const libs = { [`${linkedFile}:${linkedLib}`]: libContract._address }
      return linker.linkBytecode(bytecode.object, libs)
    }
github OriginProtocol / origin / packages / contracts / test-alt / _helper.js View on Github external
for (const linkedLib2 in linkReferences[linkedFile2]) {
          libObj.evm.bytecode.object = await deployLib(
            linkedFile2,
            linkedLib2,
            libObj.evm.bytecode
          )
        }
      }

      const LibContract = new web3.eth.Contract(libObj.abi)
      const gas = solidityCoverage ? 3000000 * 5 : 3000000
      const libContract = await LibContract.deploy({
        data: libObj.evm.bytecode.object
      }).send({ from, gas })
      const libs = { [`${linkedFile}:${linkedLib}`]: libContract._address }
      return linker.linkBytecode(bytecode.object, libs)
    }
github dogethereum / dogethereum-contracts / scripts / measure_gas.js View on Github external
async function measureFunctionGas(
    compiledContracts,
    contractName,
    contractCreationGas,
    dependencies,
    functionInfo
) {
    let contract = compiledContracts.contracts[contractName];
    let bytecode = contract.bytecode;
    bytecode = linker.linkBytecode(bytecode, dependencies);
    let abi = JSON.parse(contract.interface);
    let createdContract = web3.eth.contract(abi);
    let returnedMap = await new Promise((resolve, reject) => {
        createdContract.new({
            from: web3.eth.coinbase,
            gas: contractCreationGas,
            data: '0x' + bytecode
        }, (err, myContract) => {
            if (err) {
                console.log(err);
                return reject(err);
            }

            let gasPerFunction = [];

            if (myContract.address != undefined) {
github dogethereum / dogethereum-contracts / scripts / measure_gas.js View on Github external
function measureDeploymentGasPerContract(compiledContracts, contractDeploymentInfo) {
    let bytecode;
    let gasPerContract = [];

    for (contract in contractDeploymentInfo) {
        dependencies = contractDeploymentInfo[contract].dependencies;
        bytecode = '0x' + compiledContracts.contracts[contract].bytecode;
        
        if (Object.keys(dependencies).length > 0) {
            bytecode = linker.linkBytecode(bytecode, dependencies);
        }
        
        gasPerContract[contract] = web3.eth.estimateGas({
            data: bytecode,
            gasLimit: contractDeploymentInfo[contract].deploymentGasLimit
        });
    }

    return gasPerContract;
}
github mosaicdao / mosaic.js / lib / setup / GatewayDeployer.js View on Github external
linkMessageBus: async function(bin, libraryName, libAddress) {
    let linkOptions = {};
    linkOptions[libraryName] = libAddress;

    return linker.linkBytecode(bin, linkOptions);
  }
};