humanwhoexplores / smart-contracts

this repo contains my workbook for practicing smart contracts
0 stars 0 forks source link

How can i deploy a contract on Rinkeby Network #9

Closed humanwhoexplores closed 3 years ago

humanwhoexplores commented 3 years ago
Screenshot 2021-09-24 at 10 36 58 AM
humanwhoexplores commented 3 years ago

Now : to deploy the code I need a Test Ether account :- Bro : i can't use my primary account so i will make a new Metamask Account and play with it.

humanwhoexplores commented 3 years ago

Added deploy.js in this commit https://github.com/humanwhoexplores/smart-contracts/commit/ba86e11888e8add4eeec4d65bf8c6bb0e1c8d41d

humanwhoexplores commented 3 years ago

the code that deploys the contract

`const HDWalletProvider = require("truffle-hdwallet-provider"); const Web3 = require("web3"); const { interface, bytecode } = require("./compile");

var mnemonic = 'MNEMONIC PLEASE; var infura_provider_url = 'https://rinkeby.infura.io/v3/7985ca9520d8459b9XXXXXXXXXXXXXX';

const provider = new HDWalletProvider( mnemonic, infura_provider_url);

const web3 = new Web3(provider);

const deploy = async () => { const accounts = await web3.eth.getAccounts();

console.log("All the accounts we got are ", accounts); console.log("Attempting to deploy from account", accounts[0]);

let balance = await web3.eth.getBalance(accounts[0]); console.log("The balance is ", balance);

const result = await new web3.eth.Contract(JSON.parse(interface)) .deploy({ data: bytecode, arguments: ["Hi there!"] }) .send({ gas: "1000000", from: accounts[0] });

console.log("Contract deployed to", result.options.address); }; deploy(); `

humanwhoexplores commented 3 years ago

The mnemonic is of my Test MetaMask Account infura_provider_url :- endpoint of my infura api project

humanwhoexplores commented 3 years ago

─$ node deploy.js All the accounts we got are [ '0x27E03B595852f40253Af8f9905ecDe40552b5496' ] Attempting to deploy from account 0x27E03B595852f40253Af8f9905ecDe40552b5496 The balance is 18489104207993164656 Contract deployed to 0x847611615F036877fad9B17446D90004FB7F6B92

humanwhoexplores commented 3 years ago

Link to Rinkeby Etherscan https://rinkeby.etherscan.io/tx/0x22854d36702bb8da4135c8cad4ad7bab74bc666153287abb4ed7ac1f3d2ad13c