Loading...
Polygon is a protocol and a framework for building and connecting Ethereum-compatible blockchain networks. Aggregating scalable solutions on Ethereum supporting a multi-chain Ethereum ecosystem.
visit ploygon here.
A is a framework to deploy Smart Contracts on EVM compatible blockchains.
It is suggested to install nodejs with nvm on ubuntu OS in order to avoid any permissions error. Install nodejs from here.
after installing nodejs install truffle globally with this command:
npm install -g truffle
In order to deploy Smart Contract some gas fee is required which can be provided with the wallet having sufficient balance. Generally wallets like metamask, coinbase are accessible on client side , but for server side interaction HDWalletprovider will do the work.
From client side the wallet itself can act as bridge to connect the particular blockchains, but if you want to connect your apppilcation to blockchain from server side, rpc provider is required. there are may providers including the block explorers itself. You can get free provider like infura. create project id and get api key. If infura does't work you can get their free rpc providers
https://rpc-mainnet.matic.network : for mainnet
https://rpc-mumbai.matic.today : for mumbai testnet
The most easy way to add account in HDWalletprovider is providing mnemonic phrase. you can get it from metamask.
Instead of building truffle from scratch , unboxing sample project and cusmizing it is lot easier.
truffle unbox metacoin
this will generate 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.
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 maticmainnet_rpc_url = 'https://polygon-mainnet.infura.io/v3/your_api_key'
const maticmumbai_rpc_url = 'https://polygon-mainnet.infura.io/v3/your_api_key'
module.exports = {
networks: {
ganache: {
host: "localhost",
port: 7545,
network_id: "*",
},
maticmainnet: {
provider: function() {
return new HDWalletProvider(mnemonic, maticmainnet_rpc_url);
},
network_id: '137',
},
maticmumbai: {
provider: function() {
return new HDWalletProvider(mnemonic, maticmumbai_rpc_url);
},
network_id: '80001',
}
} ,
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 maticmainnet // replace maticmainnet with your network name as defined in truffle-confiig file
This was one for the method to deploy smart contract though, there are two more methods by directly using remix IDE and second one is using Hardhat.