Now that we done with the migration configuration, you will now be able to be deploy the smart contracts to public blockchains like Wethio
##### Start the migration
1. Have the compiled smart contract ready
2. Start the migration to the Wethio Testnet in the terminal
3. truffle migrate --network wethiotestnet
Once done, you will have the transaction ID and the contract address.
What to do when you see the following errors?
Error 1: smart contract creation cost is under allowance
Edit truffle.js and add more gas/gasPrice to deploy
Error 2: insufficient funds for gas * price + value.
Add more funds to your wallet to deploy, go to Faucet and get more tokens
You can check the transaction status of the deployment on WeSight. You can check details of the transaction by searching for the Transaction ID for your new contract.
And it’s done. You’ve successfully deployed your contract to Wethio using Truffle.
#### Testing the smart contract
Write tests in the **test/** directory and execute with truffle test to test your smart contracts.
#### Build a Web3 Frontend to Interact with Smart Contract
Take the smart contract you created and deployed on Wethio blockchain to the public by creating a UI. Through this UI people will be able to use the shop
The **pet-shop** Truffle Box has the code for front-end included in the src/ directory
1. Open **/src/js/app.js** in text editor
2. Analyze the file. The object, load, and the function all are in there. The **global** App object to manage our application, load the data in **init()**, call the function **initWeb3()**. The web3 JavaScript library interacts with the Ethereum blockchain and can retrieve user accounts, send transactions, interact with smart contracts, and do much more
$.getJSON('../pets.json', function(data) {
var petsRow = $('#petsRow');
var petTemplate = $('#petTemplate');
for (i = 0; i < data.length; i ++) {
petTemplate.find('.panel-title').text(data[i].name);
petTemplate.find('img').attr('src', data[i].picture);
petTemplate.find('.pet-breed').text(data[i].breed);
petTemplate.find('.pet-age').text(data[i].age);
petTemplate.find('.pet-location').text(data[i].location);
petTemplate.find('.btn-adopt').attr('data-id', data[i].id);
petsRow.append(petTemplate.html());
return await App.initWeb3();
}, initWeb3: async function() {
// Modern dapp browsers...
App.web3Provider = window.ethereum;
// Request account access
await window.ethereum.enable();
// User denied account access...
console.error("User denied account access")
// Legacy dapp browsers...
App.web3Provider = window.web3.currentProvider;
// If no injected web3 instance is detected, fall back to Ganache
App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
web3 = new Web3(App.web3Provider);
return App.initContract();
}, initContract: function() {
$.getJSON('Adoption.json', function(data) {
// Get the necessary contract artifact file and instantiate it with truffle-contract
var AdoptionArtifact = data;
App.contracts.Adoption = TruffleContract(AdoptionArtifact); // Set the provider for our contract
App.contracts.Adoption.setProvider(App.web3Provider); // Use our contract to retrieve and mark the adopted pets
return App.markAdopted();
//---- return App.bindEvents();
}, bindEvents: function() {
$(document).on('click', '.btn-adopt', App.handleAdopt);
}, markAdopted: function(adopters, account) {
App.contracts.Adoption.deployed().then(function(instance) {
adoptionInstance = instance; return adoptionInstance.getAdopters.call();
}).then(function(adopters) {
for (i = 0; i < adopters.length; i++) {
if (adopters[i] !== '0x0000000000000000000000000000000000000000') {
$('.panel-pet').eq(i).find('button').text('Success').attr('disabled', true);
console.log(err.message);
}, handleAdopt: function(event) {
event.preventDefault(); var petId = parseInt($(event.target).data('id')); //----
var adoptionInstance; web3.eth.getAccounts(function(error, accounts) {
} var account = accounts[0]; App.contracts.Adoption.deployed().then(function(instance) {
adoptionInstance = instance; // Execute adopt as a transaction by sending account
return adoptionInstance.adopt(petId, {from: account});
}).then(function(result) {
return App.markAdopted();
console.log(err.message);
$(window).load(function() {