Estoy trabajando en un contrato inteligente. Cuando intento servir mi contrato inteligente a través del servidor lite, veo el siguiente error en la consola del navegador
Aquí mi código fuente de app.js: https://pastebin.com/UjFuYCyQ
He intentado instalar TruffleContract por separado pero no tuve suerte.
Código de la aplicación.js:
App = {
web3Provider: null,
contracts: {},
account: 0x0,
init: function() {
return App.initWeb3();
},
initWeb3: function() {
if (typeof web3 !== 'undefined') {
App.web3Provider = web3.currentProvider;
} else {
App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
}
web3 = new Web3(App.web3Provider);
App.displayAccountInfo();
return App.initContract();
},
displayAccountInfo: function(){
web3.eth.getCoinbase(function(err, account){
if(err === null){
App.account = account;
$('#accountId').text(account);
}
});
return App.initContract();
},
initContract: function() {
$.getJSON('Voting.json', function(votingArtifact) {
App.contracts.Voting = TruffleContract(votingArtifact);
App.contracts.Voting.setProvider(App.web3Provider);
return App.reloadVoters();
});
},
reloadVoters: function() {
App.displayAccountInfo();
}
};
$(function() {
$(window).load(function() {
App.init();
});
});
Parece javascript simple, para acceder TruffleContract
, debe agregar un script en html<script src="{uri_truffle_contract.js}"></script>
Si desea agregar a través del paquete npm, debe agregar var contract = require("truffle-contract");
encima de su javascript. En este caso, debe hacerlo browserify
antes de ejecutarlo en un navegador.
Simplemente ejecute npm i @truffle/contract
esto instalará el paquete correcto. trufle-contract ahora se renombra a @truffle/contract. Consulte los documentos de npm
buena vibración
Faisal Memón
Badr Bellaj
Faisal Memón
npm install trufle-contract
en la raíz del proyecto, pero sigo enfrentando lo mismo.