npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@evmchain/contract-deployer

v1.6.4

Published

Deploy smartcontracts

Downloads

26

Readme

How to use

Deploy with Truffle

File structure

├── contracts
│   ├── MyProxy.sol
│   └── MyProxyAdmin.sol
├── migrations
│   └── 1_deploy.js
├── network
│   └── testnet.json
├── package.json
├── truffle-config.js

Add network in truffle-config.js file

const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {
  networks: {
    "testnet": {
      provider: new HDWalletProvider('MNEMONIC', 'https://goerli.infura.io/v3/', 0, 1, true, "m/44'/60'/0'/0/", 5);,
      network_id: "*",
    }
  }
}

Update package.json

"scripts": {
  "deploy:testnet": "truffle migrate --network testnet --reset --f 1 --to 1",
}

Add deploy script in 1_deploy.js

const Web3                        = require('web3');
const ContractDeployerWithTruffle = require('@evmchain/contract-deployer/src/truffle');
const { networks }                = require('../truffle-config.js')

module.exports = async function (deployer, network, accounts) {
  const { provider } = (networks[network] || {})
  const web3         = new Web3(provider);

  const deployConfig = {
    dataFilename  : `./network/${network}.json`,
    deployData    : require(`../network/${network}.json`),
    proxyAdminName: "MyProxyAdmin", // You can change to the name of your proxy admin contract (Make sure 'isAdminOf' function is supported).
    proxyName     : "MyProxy" // You can change to the name of your proxy contract.
  }

  const contractDeployer = new ContractDeployerWithTruffle({artifacts, deployer});
  contractDeployer.setWeb3(web3);
  contractDeployer.setConfig(deployConfig);

  // Initialize
  await contractDeployer.init();
  // Start deploy 
  await contractDeployer.deployAllManifests({
    args: {
      MyGame: { 
        initArgs: [
          "config:usdc.address", 
          "address:MyToken"
        ] 
      } // See the format of params below
    }
  });

  await contractDeployer.grantRoles();
}

Create testnet.json file

Run deploy

npm run deploy:testnet

Deploy with Hardhat

File structure

├── contracts
│   ├── MyProxy.sol
│   └── MyProxyAdmin.sol
├── scripts
│   └── deploy.js
├── network
│   └── testnet.json
├── package.json
├── hardhat.config.js

Add network in hardhat.config.js file

require('dotenv').config()
require("@nomicfoundation/hardhat-toolbox");
require('@nomiclabs/hardhat-ethers')
require('@nomiclabs/hardhat-etherscan')
require('@nomiclabs/hardhat-web3')

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: {
    version: '0.8.7',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
  networks: {
    "testnet": {
      url: "http://127.0.0.1:8545/",
      accounts: ['YOUR-PRIVATE-KEY']
    }
  }
};

Update package.json

"scripts": {
  "deploy:testnet": "npx hardhat run scripts/deploy.js --network testnet",
}

Add deploy script in deploy.js

const hre                             = require("hardhat");
const { ethers }                      = hre
const { web3 }                        = require('hardhat')
const { ContractDeployerWithHardhat } = require('@evmchain/contract-deployer');

async function main() {
  network = hre.network.name
  
  const deployConfig = {
    dataFilename  : `./network/${network}.json`,
    deployData    : require(`../network/${network}.json`),
    proxyAdminName: "MyProxyAdmin", // You can change to the name of your proxy admin contract (Make sure 'isAdminOf' function is supported).
    proxyName     : "MyProxy" // You can change to the name of your proxy contract.
  }

  const contractDeployer = new ContractDeployerWithHardhat();
  contractDeployer.setConfig(deployConfig);

  // Init
  await contractDeployer.init();
  // Deploy contract
  await contractDeployer.deployAllManifests({
    args: {
      MyGame: { 
        initArgs: [
          "config:usdc.address", 
          "address:MyToken"
        ] 
      } // See the format of params below
    }
  });

  // Grant roles
  await contractDeployer.grantRoles();
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Create testnet.json file

Run deploy

npm run deploy:testnet

Configuring network file

{
    "contracts": {
        "MyProxyAdmin": "",
        "MyToken": "",
        "MyGame": {
            "proxy": "",
            "impl": ""
        }
    },
    "mapping": {},
    "roles": {
        "MyGame": {
            "OPERATOR_ROLE": [
                "0x7be0B9AEc2e1963C997dee5692a4B44584470A10",
                "0xb26f0A1dd9c3971A7C5cd67f48C5059A0e1cdA80",
                "0x549A523C18F9CFF9Cf50F2f3317abAd479B8f416"
            ],
            "-OPERATOR_ROLE": [
                "0x692e2a431f051885f3badecf10c0562d1d195974"
            ]
        }
    },
    "config": {
        "usdc.address": "0x80c3a8Bfc9713DB8C3B7562B542745fCf224246a"
    }
}
  • Revoke role by adding minus symbol before the role name

Configuring deployment manifest

  await contractDeployer.deployAllManifests({
    args: {
      MyGame: { 
        initArgs: [
          "config:usdc.address", 
          "address:MyToken"
        ] 
      } // See the format of params below
    }
  })
  • Params:
    • implArgs: parameters to pass to contructor
    • initArgs: parameters to init proxy
  • Format values:
    • config:usdc.address get from config
    • address:MyToken address of MyToken
    • ether:1 convert to wei
    • keccak: get keccak value
  • Support libraries
  await contractDeployer.deployAllManifests({
    args: {
      MyGame: { 
        initArgs: [
          "config:usdc.address", 
          "address:MyToken"
        ],
        libs: ["MyLibrary"]
      } // See the format of params below
    }
  })
(*) Need to add MyLibrary to json file before the smart contract `MyGame`