Skip to content

Instantly share code, notes, and snippets.

@anupam-io
Last active January 5, 2021 10:00
Show Gist options
  • Save anupam-io/13fd3c87ffe1f5d0506130faa00c4368 to your computer and use it in GitHub Desktop.
Save anupam-io/13fd3c87ffe1f5d0506130faa00c4368 to your computer and use it in GitHub Desktop.
Deploy scripts for solidity with web3 and wallet/ganache
const Web3 = require('web3');
const compiledContract = require('./../build/MyContract.json');
const rpcEndpoint = 'rpc-END-POINT';
// you will get from ganache-GUI
// Setting up the provider
const provider = new Web3.providers.HttpProvider(rpcEndpoint);
const web3 = new Web3(provider);
const minGas = 1000000;
const deploy = async()=>{
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account ', accounts[0]);
const res = await new web3.eth.Contract(compiledContract.abi)
.deploy({ data: compiledContract.evm.bytecode.object })
.send({ from: accounts[0], gas: minGas });
console.log("Successfully deployed at: ", res.options.address);
return process.exit(1);
};
deploy();
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const compiledContract = require('./../build/MyContract.json');
const seedPhrase = 'YOUR-SEED-PHRASE';
// a group of words that allow access to a cryptocurrency wallet
const rpcEndpoint = 'rpc-END-POINT';
// an endpint for connecting your web3 instance wallet and the blockchain node
// Setting up the provider
const provider = new HDWalletProvider(seedPhrase, rpcEndpoint);
const web3 = new Web3(provider);
const minGas = 1000000;
const deploy = async()=>{
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account ', accounts[0]);
const res = await new web3.eth.Contract(compiledContract.abi)
.deploy({ data: compiledContract.evm.bytecode.object })
.send({ from: accounts[0], gas: minGas });
console.log("Successfully deployed at: ", res.options.address);
return process.exit(1);
};
deploy();
@anupam-io
Copy link
Author

Do checkout solcTemplate.

@anupam-io
Copy link
Author

How to use?

  • Configure the compiledContract path correctly.
  • Set rpcEndPoint and seedPhrase appropriately.
  • node deploy_wallet.js

@anupam-io
Copy link
Author

Compatible with:

  • solc: 0.8.0
  • truffle-hdwallet-provider: 9.0.1
  • web3: 1.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment