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

Distribution of intelligent contracts with metamask and truffle

In this article, we will pass through the process of distribution of intelligent contracts using Metamask and Tartules on a Ropsten test network. We will also respond to a problem you could meet when you try to migrate the contract.

Prerequisites

  • Node.js (LTS or last)

  • Truffle CLI (NPM Install -G Tartuffle)

  • Metamask wallet

Step 1: Create a new project and configure your settings

Create a new directory for your project and initialize it with scam init. Add the following configuration to theMetamask.js:

Javascript

Const Metamask = Requirement (‘Metamask’);

Module.exports = {

// Name of your account (e.g. “Your_ACCount”)

Mnemonic: “Yourmnemonic Word”,

// the network you want to use

net: {

ropsten,

},

// the password for your Metamask portfolio (this will be used as a key to the contract)

Password: ““,

};

`

Step 2: Create a new intelligent contract

Create a new file calledcontracttt.jsand add the following code:

Javascript

Const Web3 = Requirements (‘Web3’);

Const Web3Conttract = Requirements (‘Web3-Ethereum-Contrati’);

Class MySmartContratTCT {

CONSTRUTOR () {

This.web3 = New Web3 (New Web3.providers.httpprovider (‘

Const contracttress = ‘0xyurconttractAddress’;

Const Contrattabi = {" Version ":" 1 "," Name ":" Mycontratct "," Functions ": [" Myfunction "]};

This.Contracts = New Web3Ch3Contract (This.web3, Contraptddress, Contractabi);

}

Myfunction () {

// call the function you want to distribute

Console.log (“Hello from Myfunction!”);

}

}

Module.exports = MySmartContratCT;

`

Step 3: fill in and distribute your intelligent contract

Create a new file calledcompile.jsand add the following code:

Javascript

Const Tartufo = Requirements (‘Truffle’);

Module.exports = {

compiles () {

return a new Trufflesolid ();

},

};

`

Step 4: Use the truffle to migrate the contract from Ropsten

Execute the following command in your terminal:

Bash

Npm run compile

`

This will create a compiled version of your intelligent contract. Then, use the truffle to migrate it from Ropsten:

Bash

Truffle Migrate -Network Ropsten

`

Step 5: Update your Metamask account

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

Update yourMetamask.jswith the following configuration file:

Javascript

Const Metamask = Requirement (‘Metamask’);

Const ropstenaddress = “0xyurropstenacount”;

Const ropswssword = ““;

Module.exports = {

Mnemonic: ropStenpassword,

net: {

Ropsten: {

Address: ropstenaddress,

Password: ropStenpassword,

},

},

};

`

Step 6: distribute the contract using Metamask

Update yourMetamask.jswith the following configuration file:

Javascript

Const Metamask = Requirement (‘Metamask’);

Const ropstenaddress = “0xyurropstenacount”;

Const ropswssword = ““;

Module.exports = {

Mnemonic: ropStenpassword,

net: {

Ropsten: {

Address: ropstenaddress,

Password: ropStenpassword,

},

},

};

`

Error message

When performingtruffle migra -Network ropsten, you should get a mistake similar to this:

Bash

Npm run compile

`

This is because the compiled version of the contract does not include any metadata required by the truffle for distribution.

Solution

To terminate this problem, it is necessary to update the completed contract to include the requested metadata. You can do it by adding the following code to your filecompile.js’:

`Javascript

Const Web3Conttract = Requirements (‘Web3-Ethereum-Contrati’);

Class MySmartContratTrat {

CONSTRUTOR () {

Const Web3 = New Web3 (New Web3.providers.httpprovider (‘

This.

ETHEREUM THERE WEALTH DISTRIBUTION

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir