I am a beginner in Dapp and don't know about web3.js. I complie myslef contracts with Truffle. I did write the following contract:
pragma solidity ^0.5.12;
contract TEST{
bytes public name="Yerevan is love";
function fname() public view returns(string memory){
return string(name);
}
}
and i want to see the "Yerevan is love" by alert() dialogbox in JavaScript code. Truffle provided the following .js file to interface between browser and smart contract:
App = {
web3Provider: null,
contracts: {},
init: async function() {
// Load pets.
$.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() {
/*
* Replace me...
*/
return App.initContract();
},
initContract: function() {
/*
* Replace me...
*/
return App.bindEvents();
},
bindEvents: function() {
$(document).on('click', '.btn-adopt', App.handleAdopt);
},
markAdopted: function(adopters, account) {
/*
* Replace me...
*/
},
handleAdopt: function(event) {
event.preventDefault();
var petId = parseInt($(event.target).data('id'));
/*
* Replace me...
*/
}
};
$(function() {
$(window).load(function() {
App.init();
});
});
I can see "Yerevan is love" in truffle console but i want do this in browser. I don't know about working with the above codes.