Click to adopt an error invalid address (app. Js: 109)
The code is as follows:
App={
Web3Provider: null,
Contracts: {},
Init: function () {
//the Load pets.
$. GetJSON ('../pets. Json ', function (data) {
Var petsRow=$(' # petsRow ');
Var petTemplate=$(' # petTemplate ');
for (i=0; i
PetTemplate. Find (' img). Attr (' SRC 'data [I] picture);
PetTemplate. Find (' pet - breed '). The text (data [I] breed);
PetTemplate. Find (' pet - age '). The text (data [I] age);
PetTemplate. Find (' pet - the location '). The text (data [I] the location).
PetTemplate. Find (' BTN - adopt '). The attr (' data - id 'data [I] id);
PetsRow. Append (petTemplate. HTML ());
}
});
Return the App. InitWeb3 ();
},
InitWeb3: function () {
/*
* the Replace me...
*/
//Is there an injected web3 instance?
If (typeof web3! Undefined==' ') {
App. Web3Provider=web3. CurrentProvider;
} else {
//If no injected web3 instance is detected, fall back to Ganache
App. Web3Provider=new Web3. Will. HttpProvider (' http://192.168.0.129:7545 ');
}
Web3=new web3 (App. Web3Provider);
Return the App. InitContract ();
},
InitContract: function () {
/*
* the Replace me...
*/
//load the Adoption. Json, preserved the Adoption of ABI (interface) information (address) and deployment of network information, it generated when compiling contracts ABI, when deploying additional network information
$. GetJSON (' Adoption. Json, function (data) {
//Adoption. The json data to create an interactive TruffleContract contract instance,
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 the App. MarkAdopted ();
});
Return the App. BindEvents ();
},
BindEvents: function () {
The $(document) on (' click ', 'BTN - adopt', App. HandleAdopt);
},
MarkAdopted: function (adopters, account) {
/*
* the Replace me...
*/
Var adoptionInstance;
App. Contracts. Adoption. The deployed (). Then (function (instance) {
AdoptionInstance=instance;
//call getAdopters (), use the call read without consuming gas
Call (); return adoptionInstance. GetAdopters.
{}). Then (function (adopters)
for (i=0; i
$(' panel - pet '). Eq. (I) find (' button). The text (' Success '). Attr (" disabled ", true);
}
}
{}). The catch (function (err)
The console. The log (err. Message);
});
},
HandleAdopt: function (event) {
event.preventDefault();
Var petId=parseInt ($(event. The target). The data (" id "));
Var adoptionInstance;
//get the user account
Web3. Eth. GetAccounts (function (error, accounts) {
If (error) {
console.log(error);
}
Var account=accounts [3].
App. Contracts. Adoption. The deployed (). Then (function (instance) {
AdoptionInstance=instance;
//send transaction adopt a pet
Return adoptionInstance. Adopt (petId, {the from: account});
{}). Then (function (result)
Return the App. MarkAdopted ();
{}). The catch (function (err)
The console. The log (err. Message);
});
});
/*
* the Replace me...
*/
}
};
$(function () {
$(window). The load (the function () {
App. The init ();
});
});