Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

System Error when deploying contracts via truffle, running Ganache 2.7.1 on win32 #5784

Open
Engeloid opened this issue Feb 10, 2024 · 0 comments

Comments

@Engeloid
Copy link

Hi there,

every time I deploy my contracts via truffle migrate --reset I cannot dial tcp 127.0.0.1:7545 via ethclient (go-ethereum) as Ganache encounters an error.
The Deployment actually succeeds and after I relaunch Ganache, I can interact with my just deployed contracts, however, once I redeploy them, the error occurs and I have to relaunch Ganache.

This wasn't like this before. Currently I have these migration files:

1_initial_migrations.js

const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

2_rollup.js

const MiMC = artifacts.require("MiMC");
const MerkleTree = artifacts.require("MerkleTree");
const Verifier = artifacts.require("Verifier");
const Rollup = artifacts.require("Rollup");

const BN = require('bn.js');
const fs = require('fs');
const path = require('path');

// Function to save deployment info to a separate file
function saveDeploymentInfo(contractName, instance, suffix, deployer) {
  const deploymentsDir = path.join(__dirname, '../build/contracts');
  if (!fs.existsSync(deploymentsDir)){
    fs.mkdirSync(deploymentsDir);
  }
  const filePath = path.join(deploymentsDir, `${contractName}-${suffix}.json`);
  const info = {
    address: instance.address,
    network: deployer.network,
    transactionHash: instance.transactionHash,
  };
  fs.writeFileSync(filePath, JSON.stringify(info, null, 2));
}

let number = new BN('19929288186675197851976196030644791160893678128488844394573589927998971210120');
let hexNumber = '0x' + number.toString('hex');

module.exports = function(deployer) {
  deployer.deploy(MiMC).then(function() {
    // Link MiMC to MerkleTree
    return deployer.link(MiMC, MerkleTree).then(function() {
      // Deploy MerkleTree
      return deployer.deploy(MerkleTree, 4).then(function() {
        // Link MiMC and MerkleTree to Rollup
        return deployer.link(MiMC, Rollup).then(function() {
          return deployer.link(MerkleTree, Rollup).then(function() {
            // Deploy Verifier
            return deployer.deploy(Verifier).then(function() {
              // Correctly call deploy and then use the result within the .then() promise handler
              return deployer.deploy(Rollup, Verifier.address, 4, hexNumber).then(function(rollupInstance) {
                // Pass the deployer object to the saveDeploymentInfo function
                saveDeploymentInfo('Rollup', rollupInstance, '1', deployer);
              });
            });
          });
        });
      });
    });
  });
};

3_rollup.js

const MiMC = artifacts.require("MiMC");
const MerkleTree = artifacts.require("MerkleTree");
// Assuming you have Verifier2 contract similar to Verifier
const Verifier2 = artifacts.require("Verifier2");
const Rollup = artifacts.require("Rollup");

const BN = require('bn.js');

let number = new BN('19929288186675197851976196030644791160893678128488844394573589927998971210120');
let hexNumber = '0x' + number.toString('hex');

module.exports = function(deployer) {
    deployer.then(async () => {
        await deployer.deploy(Verifier2);
        const verifier2Instance = await Verifier2.deployed();

        // Assuming the deployment of MiMC and MerkleTree has already been done in the first migration file
        // and they do not need to be redeployed or relinked for the second Rollup deployment.
        // Deploy the second Rollup with Verifier2
        await deployer.deploy(Rollup, verifier2Instance.address, 4, hexNumber);
    });
};

Before

Before I just had 1_initial_migrations and one other migration file and I could freely use truffle migrate --reset to redeploy my contracts without any errors and I could interact with them.

const MiMC = artifacts.require("MiMC");
const MerkleTree = artifacts.require("MerkleTree");
const Verifier = artifacts.require("Verifier");
const Rollup = artifacts.require("Rollup");

const BN = require('bn.js');

let number = new BN('19929288186675197851976196030644791160893678128488844394573589927998971210120');
let hexNumber = '0x' + number.toString('hex');

module.exports = function(deployer) {
  deployer.deploy(MiMC).then(function() {
    // Link MiMC to MerkleTree
    return deployer.link(MiMC, MerkleTree).then(function() {
      // Deploy MerkleTree
      return deployer.deploy(MerkleTree, 4).then(function() {
        // Link MiMC and MerkleTree to Rollup
        return deployer.link(MiMC, Rollup).then(function() {
          return deployer.link(MerkleTree, Rollup).then(function() {
            // Deploy Verifier
            return deployer.deploy(Verifier).then(function() {
              // Finally, deploy Rollup with the address of the Verifier
              return deployer.deploy(Rollup, Verifier.address, 4, hexNumber);
            });
          });
        });
      });
    });
  });
};

Error

PLATFORM: win32
GANACHE VERSION: 2.7.1

EXCEPTION:

TypeError: Cannot read property 'address' of null
    at ProjectsWatcher.handleBlock (C:\Program Files\WindowsApps\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\app\resources\static\node\truffle-integration\projectsWatcher.js:208:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Subscription.<anonymous> (C:\Program Files\WindowsApps\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\app\resources\static\node\truffle-integration\projectsWatcher.js:57:9)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant