How to use ganache-cli - 10 common examples

To help you get started, we’ve selected a few ganache-cli 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 trufflesuite / truffle-artifactor / test / contracts.js View on Github external
describe("artifactor + require", function() {
  var Example;
  var accounts;
  var abi;
  var binary;
  var network_id;
  var artifactor;
  var provider = TestRPC.provider();
  var web3 = new Web3();
  web3.setProvider(provider)

  before(function(done) {
    web3.version.getNetwork(function(err, id) {
      if (err) return done(err);
      network_id = id;
      done();
    });
  });

  before(function(done) {
    this.timeout(10000);

    // Compile first
    var result = solc.compile(fs.readFileSync("./test/Example.sol", {encoding: "utf8"}), 1);
github wangshijun / ethereum-contract-workflow / tests / project.spec.js View on Github external
const assert = require('assert');
const path = require('path');
const ganache = require('ganache-cli');
const BigNumber = require('bignumber.js');
const Web3 = require('web3');

const web3 = new Web3(ganache.provider());
const ProjectList = require(path.resolve(__dirname, '../compiled/ProjectList.json'));
const Project = require(path.resolve(__dirname, '../compiled/Project.json'));

let accounts;
let projectList;
let project;

describe('Project Contract', () => {
    // 1. 每次跑单测时需要部署全新的合约实例,起到隔离的作用
    beforeEach(async () => {
        // 1.1 拿到 ganache 本地测试网络的账号
        accounts = await web3.eth.getAccounts();

        // 1.2 部署 ProjectList 合约
        projectList = await new web3.eth.Contract(JSON.parse(ProjectList.interface))
            .deploy({ data: ProjectList.bytecode })
github Lamarkaz / parasol / index.js View on Github external
replInstance.displayPrompt()
                    }
                });
            }
        },
        function(contracts){
            context.parasol.executeDeployed(contracts)
            addressbook.add(contracts);
        });
        docs(contractDocs)
    }
}

if (program.dev || !process.argv.slice(2).length) { // Default argument
    if (fs.existsSync("./parasol.js")) {
        var provider = ganache.provider(config.dev)
        provider.ganache = true;
        var web3 = new Web3(provider);
        logger.success('Ethereum development network running on port ' + config.dev.port)
        web3.eth.getAccounts().then(function(accounts){
            replInstance = repl.start({ prompt: 'parasol> '.bold.cyan, useGlobal:true, ignoreUndefined:true, useColors:true });
            replInstance.defineCommand('help', {
                action: function(){
                    console.log(literals.dev)
                    replInstance.displayPrompt()
                }
            })
            replInstance.defineCommand('recompile', {
                action: function(){
                    compile(web3, accounts, "dev")
                }
            })
github leapdao / solEVM-enforcer / tools / executionPoker.js View on Github external
);

    process.exit(0);
  }

  let deployerWallet = ethers.Wallet.createRandom();
  let solverWallet = ethers.Wallet.createRandom();
  let challengerWallet = ethers.Wallet.createRandom();

  const accounts = [
    { secretKey: deployerWallet.privateKey, balance: ethers.constants.MaxUint256 },
    { secretKey: solverWallet.privateKey, balance: ethers.constants.MaxUint256 },
    { secretKey: challengerWallet.privateKey, balance: ethers.constants.MaxUint256 },
  ];

  const provider = ganache.provider({ locked: false, accounts: accounts, gasLimit: GAS_LIMIT });
  global.provider = provider;

  // yes, we need a new Web3Provider. Otherwise we get duplicate events -.-
  deployerWallet = deployerWallet.connect(new ethers.providers.Web3Provider(provider));
  solverWallet = solverWallet.connect(new ethers.providers.Web3Provider(provider));
  challengerWallet = challengerWallet.connect(new ethers.providers.Web3Provider(provider));

  // faster unit tests :)
  solverWallet.provider.pollingInterval = 30;
  challengerWallet.provider.pollingInterval = 30;

  const timeout = 10;
  const taskPeriod = 100000;
  const challengePeriod = 10000;
  const bondAmount = 1;
  const maxExecutionDepth = 10;
github endless-nameless-inc / cheshire / server.js View on Github external
startTestnet() {
    log('> Starting testnet...')

    ganache.server({
      accounts: config.accounts,
      // debug: true,
      // logger: console,
      // verbose: true,
    })
      .listen(config.portTestnet, (err) => {
        if (err) {
          log('Error starting Ganache:', err)
          process.exit(1)
        }
      })
  },
github specron / framework / packages / specron-sandbox / src / core / sandbox.ts View on Github external
public static createProvider(options?: SandboxOptions) {
    const provider = ganache.provider(options);
    provider.setMaxListeners(999999); // hide MaxListenersExceededWarning produced by ganache provider.
    return provider;
  }
github Decentrix / TetriX / src / contract.js View on Github external
const fs = require('fs');
const path = require('path');
const solc = require('solc');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const chalk = require('chalk');

const provider = ganache.provider();
const web3 = new Web3(provider);
// let accounts;
// let myContract;
// let origContract;
// let newContract;

const getAccounts = () => {
  return new Promise((resolve, reject) => {
    resolve(web3.eth.getAccounts());
  });
};

const testDeploy = accounts => {
  return new Promise((resolve, reject) => {
    let contract = new web3.eth.Contract(JSON.parse(interface))
      .deploy({
github plasma-group / plasma-chain-operator / src / eth-service.js View on Github external
for (let i = 0; i < web3.eth.accounts.wallet.length; i++) {
    ganacheAccounts.push({
      balance: '0x100000000000000000000',
      secretKey: web3.eth.accounts.wallet[i].privateKey,
    })
  }
  // For all provider options, see: https://github.com/trufflesuite/ganache-cli#library
  const providerOptions = {
    accounts: ganacheAccounts,
    gasLimit: '0x7A1200',
    locked: false,
    logger: { log },
  }
  // If we are given an HttpProvider, use a ganache server instead of as a local library
  if (config.testHttpProviderPort !== undefined) {
    es.ganacheServer = ganache.server(providerOptions)
    await _startGanacheServer(es.ganacheServer, config.testHttpProviderPort)
    web3.setProvider(
      new Web3.providers.HttpProvider(
        'http://localhost:' + config.testHttpProviderPort
      )
    )
  } else {
    // No port given, so run as local library
    web3.setProvider(ganache.provider(providerOptions))
    web3.currentProvider.setMaxListeners(300) // TODO: Remove this as it is squashing errors. See https://github.com/ethereum/web3.js/issues/1648
  }
}
github ethereum-ts / TypeChain / test / integration / targets / web3-v2 / web3.ts View on Github external
export async function createNewBlockchain() {
  const web3 = new Web3(ganache.provider(), undefined, {
    transactionConfirmationBlocks: 1,
  });
  const accounts = await web3.eth.getAccounts();
  return { web3, accounts };
}
github trufflesuite / truffle-debugger / test / evm.js View on Github external
before("Create Provider", async function() {
    provider = Ganache.provider({seed: "debugger", gasLimit: 7000000});
    web3 = new Web3(provider);
  });

ganache-cli

<p align="center"> <em>NOTICE</em>: <code>testrpc</code> is now <code>ganache-cli</code>. Use it just as you would <code>testrpc</code>. </p> <hr/>

MIT
Latest version published 4 years ago

Package Health Score

61 / 100
Full package analysis

Popular ganache-cli functions

Similar packages