migrations/
directory and you will see one JavaScript file: 1_initial_migration_js
. This handles deploying the Migrations.sol
contract to observe subsequent smart contract migrations, and ensures we don't double-migrate unchanged contracts in the future.2_deploy_contracts.js
in the migrations/
directory.2_deploy_contracts.js
file:HDWalletProvider
, a separate npm package to find and sign transactions for addresses derived from a 12-word mnemonic
— in a certain blockchain. (Read more about HDWalletProvider.)truffle.js
file (truffle-config.js
on Windows). You can edit here the migration settings: networks, chain IDs, gas... The current file has only a single network defined, you can define multiple. We will add three networks to migrate our DApp: development
, tomotestnet
and tomomainnet
.RPC endpoint
, the Chain id
and the HD derivation path
.truffle.js
file with this new content:truffle.js
file using your own wallet recovery phrase. Copy the 12 words obtained previously and paste it as the value of the mnemonic
variable.tomotestnet
network will be used to deploy our smart contract. We have also added the tomomainnet
network, in case you want to deploy to TomoChain Mainnet. However, if you are familiar with Ganache, you could use the development
network to do the local test as well if you want to. Ganache is a locally running personal blockchain for Ethereum development you can use to deploy contracts, develop applications, and run tests.Warning: In production, we highly recommend storing the mnemonic in another secret file (loaded from environment variables or a secure secret management system), to reduce the risk of the mnemonic becoming known. If someone knows your mnemonic, they have all of your addresses and private keys!
dotenv
you can load an environment variable from a file .env
, — then update your truffle.js to use this secret mnemonic
.truffle compile
.30 TOMO
and the deployment has costed 5.38 TOMO
in gas fees.Note: The command to deploy to TomoChain mainnet is very similar:truffle migrate --network
tomomainnet
smart contract creation cost is under allowance
. Why? Increasing transaction fees for smart contract creation is one of the ways TomoChain offers to defend against spamming attacks. Solution: edit truffle.js
and add more gas/gasPrice to deploy.insufficient funds for gas * price + value
. Why? You don’t have enough tokens in your wallet for gas fees. Solution: you need more funds in your wallet to deploy, go to faucet and get more tokens.test/
directory and execute with truffle test
. Find more details on Truffle’s Pet Shop tutorial.