Skip to content

Instantly share code, notes, and snippets.

@andrejrakic
Last active November 4, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrejrakic/24e0f202f7338a6eec38635ec9cab5e1 to your computer and use it in GitHub Desktop.
Save andrejrakic/24e0f202f7338a6eec38635ec9cab5e1 to your computer and use it in GitHub Desktop.
Node js script for Deployment to Moonbase testnet.
const Web3 = require('web3');
const { bytecode, abi } = require('./truffle/build/contracts/<CONTRACT_NAME>.json');
// Initialization
const web3 = new Web3('https://rpc.testnet.moonbeam.network');
const walletPrivateKey = <PRIVATE_KEY>;
const walletAddress = <WALLET_ADDRESS>;
// Deploy contract
const deploy = async () => {
console.log('⏳ Attempting to deploy from account:', walletAddress);
const contract = new web3.eth.Contract(abi);
const contractTx = contract.deploy({
data: bytecode,
// arguments: [], // if constructor needs arguments put it in array here like this [5, '0x...', 'Hello World']
});
const createTransaction = await web3.eth.accounts.signTransaction(
{
from: walletAddress,
data: contractTx.encodeABI(),
gas: '4294967295',
},
walletPrivateKey
);
const createReceipt = await web3.eth.sendSignedTransaction(
createTransaction.rawTransaction
);
console.info(`- Amount of Gas Used: ${createReceipt.gasUsed}`);
console.info(`- More transaction details at: http://8.9.36.141:4000/tx/${createReceipt.transactionHash}`);
console.log('✅ Contract deployed at address', createReceipt.contractAddress);
};
deploy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment