Metamask: How to deploy smart contract using truffle and ropsten with Metamask account

Home > Metamask: How to deploy smart contract using truffle and ropsten with Metamask account

Deploying Smart Contracts with Truffle

In thist art, we’ll walk on the processes of deploying smarts use Metamask and Truffle on a Ropsten test network. We’ll also addressing you with issue with a maning to milligate your contract.

*Prewites

  • Node.js (LTS or latest)

  • Truffle CLI (’spm install -g truffle’)

  • Metmask wall

Step 1: Create a new project and configure your settings

Create a direct for your project and initiating it ut with ut withle it. Add the following configuration to your metamask.js file:

constinent Metamassk = require(’memass’);

module.exports = {

// Your account tame (e.g., "yur_account)

mnemonic: "YourMeneconicWord",

/ The network to use

network: {

plupest,

}

// The password for your Metamask wallet (this will be seded by a key form)

password: "",

^

`s


Step 2: Create a new smart

Create a new file called.js’ and add the following code:

ovasscript

cont Web3 = require(’web3’);

const Web3Contrat = require(wb3-ethereum-contects’);

Class MySmartContrac class {

entrepreneurs() {

this.web3 =web3(new Web3. Providers.HtpProadps://ropsten.inflow.o/v3/YOUR_PROJECT_ID’));

concert contractAdress = ‘0xYurContractAdredress’;

contest contract = = {“ ”: "name": "name": "name": "MyContract”, "function"]: ["myFunction"]};

this.contracts = be Web3Contrac3, contractAddress, contractor);

}

myFunction() {

// Call the form of deployment

console.log("Hello is a meFunction!");

}

}

module.exports = MySmartContrac;

s

**Step 3: Compley and deploy your your smartness.

Create a slot called.js’ and add the following code:


const Truffle = require(’treffle’);

module.exports = {

compile() {

returned new Trufflesow();

}

^

s


Step 4: Use Truffle your entrepreneurs of Ropsten



*

Run the following in your terminal:

! you'

pum compile

s

This wll create and compiled version of the smart. Tan, use Truffle to migrant it from Ropsten:

! you'

ruffle migrants --et work ropsten

s


Step 5: Update your Metamask account

Update your is metamask.js’ file with the following configuration:

ovasscript

constinent Metamassk = require(’memass’);

consent rostenAdress = "0xYourRopsenAccount";

constentlyPassword = "";

module.exports = {

mnemonic: ropstenPasword,

network: {

ropste: {

addressing: ropsteAdress,

password: ropstePasword,

}

}

^

s

Step 6: Deploy your contract sympathing Metamask

Update your is metamask.js’ file with the following configuration:


constinent Metamassk = require(’memass’);

consent rostenAdress = "0xYourRopsenAccount";

constentlyPassword = "";

module.exports = {

mnemonic: ropstenPasword,

network: {

ropste: {

addressing: ropsteAdress,

password: ropstePasword,

}

}

^

s


Error mesage

What you run a migrant migration --tework ropste, you will hold a simulated error to this:

! you'

pum compile

`s

This is because the compiled version of the cott brings two nots no including the same note with ay tattoo to deployment.

*Soluion

All fixed this is issue, you need to open your correled contract to included the requiring the requiring metade. You can do this by adding the following code to your acompile.js file:

ovasscript

const Web3Contrat = require(wb3-ethereum-contects’);

Class MySmartContrac class {

entrepreneurs() {

contem web3 = man Web3(new Web3. Providers.HttpProvider(’

ds.

More Posts

Share:

Send Us A Message