I use Truffle and Ganache and I want to test some contracts that use the ERC820 Registry. I'm new to Truffle (and JavaScript in general) and I'm struggling to follow the instructions described in EIP-820 to get the registry deployed.

I have a 1_initial_migration.js and a 2_deploy_contracts.js file in my migrations folder. That look like:

var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {


var Registry = artifacts.require("./ERC820Registry.sol");
var Token = artifacts.require("./Token.sol");

module.exports = function (deployer) {

This obviously deploys the ERC820 to another address than 0x820b586C8C28125366C998641B09DCbE7d4cBF06.

How would I have to change my deployment file for it to be able to deploy the ERC820 Registry to its correct address?

  • What do you mean by deploy to its correct address????? Either this contract is not yet deployed, in which case it can be deployed at any address with no impact on its behavior whatsoever, or it is already deployed at the address that you've mentioned, in which case you don't need to deploy it at all. – goodvibration Dec 4 '18 at 16:52
  • @goodvibration Were you able to look at the section of EIP-820 that I linked? It describes a way of making sure the ERC820 contract is always deployed to the same address; 0x820b586C8C28125366C998641B09DCbE7d4cBF06. It is true that the behaviour does not change if it would be deployed to another address, but other contracts using the registry are counting on it being at address 0x820b586C8C28125366C998641B09DCbE7d4cBF06. – Maarten Dhondt Dec 4 '18 at 17:24
  • In that case, as I mentioned above, you don't need to deploy it at all. And you can do something like var registry = await Registry.at("0x820b586C8C28125366C998641B09DCbE7d4cBF06"); in order to get a handle to it. – goodvibration Dec 4 '18 at 17:28
  • @goodvibration I'll most definitely try that out. But I assume it'll only work as a Javascript handle? I mean if my smart contract has a line like this: ERC820Registry constant ERC820REGISTRY = ERC820Registry(0x820b586C8C28125366C998641B09DCbE7d4cBF06);, will that work if the contract is not actually deployed? (that example line is a copy of how the ERC820 reference implementation uses it at https://github.com/jbaylina/ERC820/blob/master/contracts/ERC820Client.sol) – Maarten Dhondt Dec 4 '18 at 18:02
  • will that work if the contract is not actually deployed - Of course not, but based on everything else that you've described here, it IS deployed at that specific address (how else would other contracts using the registry be counting on it being at that address?). – goodvibration Dec 4 '18 at 18:13

I'll tell you what (continuing our discussion in the comment-thread).

I've found Truffle's deployment-syntax to be very cumbersome, and ended up implementing my own deployment code (though I still run it via truffle deploy or truffle migrate).

Here is an example:

let ARG1 = process.argv[4];
let ARG2 = process.argv[5];
let ARG3 = process.argv[6];

async function deploy(contractName, contractArgs) {
    let handle = await artifacts.require(contractName).new(...contractArgs);
    console.log(`${contractName} contract deployed at address ${handle.address}`);
    return handle;

async function deployed(contractName, contractAddr) {
    let handle = await artifacts.require(contractName).at(contractAddr);
    console.log(`${contractName} contract deployed at address ${handle.address}`);
    return handle;

async function execute() {
    let contract0 = await deploy("Contract0", []);
    let contract1 = await deploy("Contract1", [ARG1]);
    let contract2 = await deploy("Contract2", [ARG2, contract1.address]);
    let contract3 = await deployed("Contract3", ARG3);

module.exports = function(deployer, network, accounts) {
    if (network == "production")
        deployer.then(async function() {await execute();});

Then your can run your migration by calling (from command-line):

truffle deploy --network=production 123 456 0x820b586C8C28125366C998641B09DCbE7d4cBF06

Of course, you'll need to add the production network in your truffle-config.js file, for example:

networks: {
    development: {
        host:       "",
        port:       8545,
        network_id: "*",
        gasPrice:   0x1,
        gas:        0x1fffffffffffff
    production: {
        host:       ...,
        port:       ...,
        network_id: ...,
        gasPrice:   100000000000,
        gas:        6721975
| improve this answer | |

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.