Deploying Smart Contracts with Truffle
In thist art, .
* Prewites
- Node.js (LTS or Latest)
- Truffle Cli (‘SPM Install -G Truffle’)
- Metmask Wall
Step 1: Create a New Project and Configure Your Settings
. Add the following configuration to your metamask.js file:
`Ovasscript
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-Constects');
Class Mysmartcontrac Class {
entrepreneurs () {
this.web3 = web3 (new web3. providers.htpproadps: //ropsten.inflow.o/v3/your_project_id '));
Concert contractaress = '0xyurcontractadredress';
contest contract = = {"": "name": "name": "mycontract", "function"]: ["Myfunction"]};
this.contracts = be web3contrac3, contractarress, 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:
Ovasscript
Const Truffle = Require ('Trefer');
module.exports = {
compile () {
returned new trufflesow ();
}
^
s
Step 4: Use Truffle Your Entrepreneurs of Ropsten *
Run the following in your terminal:
! you ‘
Five Compile
`s
This wll create and compiled version of the smart. Tan, use truffle to migrant it from ropsten:
! you ‘
Ruffle Migrants – -EET Ropsten
`s
Step 5: Update Your Metamask Account
Update your is metamask.js' file with the following configuration:
Ovasscript
constinent metamassk = require ('memask');
consent roostenadress = "0xyourropsenaccount";
constitutlypassword = "
module.exports = {
Mnemonic: Ropstepassword,
Network: {
Ropste: {
Addressing: Ropsteadress,
Password: Ropstepasword,
}
}
^
s
Step 6: Deploy Your Contract Sympathing Metamask
Update your is metamask.js' file with the following configuration:
Ovasscript
constinent metamassk = require ('memass');
consent roostenadress = "0xyourropsenaccount";
constitutlypassword = "
module.exports = {
Mnemonic: RopstenPasword,
Network: {
Ropste: {
Addressing: Ropsteadress,
Password: Ropstepasword,
}
}
^
s
Error Mesage
Run a migrant migration -Tework Ropste, you will hold a simulated error to this:
! you ‘
Five Compile
`s
This is because the compiled version of the cott brings two nots no including the same note with a tattoo to deployment.
* Soluion
All fixed this is issue, you need to open your correled contract to include the requiring metade. File:
` Ovasscript
Const Web3contrat = Require (WB3-Ethereum-Constects’);
Class Mysmartcontrac Class {
Entrepreneurs () {
Contem Web3 = Man Web3 (New Web3. Providers.httpprovider (‘
ds.