Compiling and Migrating
Compilation
- In a terminal, make sure you are in the root of the directory that contains the flutter and truffle project, Run the following command:
truffle compile
You should see output similar to the following:
Migration
You’ll see one JavaScript file already in the migrations/ directory: 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.
Let’s create our own migration script :
- Create a new file named 2_deploy_contracts.js in the migrations/ directory.
- Add the following content to the 2_deploy_contracts.js file:
Javascript
const Population = artifacts.require( "Population" ); module.exports = function (deployer) { deployer.deploy(Population); }; |
- Before we can migrate our contract to the blockchain, we need to have a blockchain running. For this article, we’re going to use Ganache, a personal blockchain for Ethereum development you can use to deploy contracts, develop applications, and run tests. If you haven’t already, download Ganache and double-click the icon to launch the application. This will generate a blockchain running locally on port 7545.
- Add the following content to the truffle-config.js file:
Javascript
module.exports = { networks: { development: { host: "127.0.0.1" , // Localhost (default: none) port: 7545, // Standard Ethereum port (default: none) network_id: "*" , // Any network (default: none) }, }, contracts_build_directory: "./src/artifacts/" , // Configure your compilers compilers: { solc: { // See the solidity docs for advice // about optimization and evmVersion optimizer: { enabled: false , runs: 200 }, evmVersion: "byzantium" } } }; |
- Migrating the contract to the blockchain, run:
truffle migrate
- Take a look into the Ganache, the first account originally had 100 ether, it is now lower, due to the transaction costs of migration.
Flutter and Blockchain – Population Dapp
Before checking out this article, Do take a look at Flutter and Blockchain – Hello World Dapp. This tutorial will take you through the process of building your mobile dapp – Population on Blockchain!
This tutorial is meant for those with a basic knowledge of Ethereum and smart contracts, who have some knowledge of the Flutter framework but are new to mobile dapps.
In this tutorial we will be covering:
- Setting up the development environment
- Creating a Truffle Project
- Writing the Smart Contract
- Compiling and Migrating the Smart Contract
- Testing the Smart Contract
- Contract linking with Flutter
- Creating a UI to interact with the smart contract
- Interacting with the complete Dapp
Description
Population on blockchain is a simple decentralized application, which will allow you to store a specific country population on the blockchain, you can increment as well as decrement the population based on the current condition of the country.
Output: