Loading...
You should have nodeJS installed then install truffle with this command:
npm install -g truffle
If you want to set-up from scratch you can directly use truffle init command otherwise get sample project and edit it further.
to get simple project use this command :
truffle unbox metacoin
Now you will get some project folders called contracts, migrations, test and truffle-config file. change your contract files and content , also do the respective changes in migrations file also.
We will need a wallet provider to deploy contract. Install with following command:
npm install --save truffle-hdwallet-provider
Along with wallet provider we will also need RPC provider. The most popular RPC provider is Infura.
The most popular ethereum wallet is Metamask.
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*" // Match any network id
}
},
compilers: {
solc: {
version: "^0.8.0"
}
}
};
const HDWalletProvider = require("@truffle/hdwallet-provider")
const mnemonic = 'your_mnemonic'
const rpc_url = 'https://ropsten.infura.io/v3/your_api_key'
module.exports = {
networks: {
ganache: {
host: "localhost",
port: 7545,
network_id: "*",
},
ropsten: {
provider: function() {
return new HDWalletProvider(mnemonic, rpc_url);
},
network_id: '3',
}
} ,
compilers : {
solc :{
version : '^0.4.23'
}
}
};
thats it. then use the command for compile and deploy your contract. you can also set the compiler version for solidity.
truffle compile
truffle deploy --network ropsten // replace ropsten with your network name as defined in truffle-confiig file
Testnet | ChainID/NetworkID |
Mainnet | 1 |
Ropsten | 3 |
Rinkeby | 4 |
Kovan | 42 |
Goerli | 5 |
Also don't forget to use RPC url's for respective networks you gt from infura..