- paste your contract address to variable
libraryContractAddress
on line 5 in utils.js.
-> insert this statements inside mounted()
method in index.vue
// init contract object
await setLibraryContract();
// fetch all books
const books = await fetchAllBooks();
this.posts = books;
- set contract Object inside 'setLibraryContract()' method in [utils.js]
bookRentContract = await window.tronWeb.contract().at(libraryContractAddress);
postBook
- copy below code insidepostAd
inbookForm.vue
// convert price from TRX to SUN
postBookInfo(this.title,this.description,tronWeb.toSun(this.price));
-> copy below code inside postBookInfo
in utils.js
const result = await bookRentContract.addBook(name,description,price).send({
feeLimit:100_000_000,
callValue:0,
shouldPollResponse:true
});
borrowBook
- copy below code insidebook()
indetailsModal.vue
// get Start date
const startDay = this.getDayOfYear(this.startDate)
// get End date
const endDay = this.getDayOfYear(this.endDate)
// price calculation
const totalPrice =tronWeb.toSun(this.bookData.price) * (endDay - startDay)
// call borrowBook function of contract
borrowBook(this.bookData.id, startDay, endDay, totalPrice)
-> copy below code inside borrowBook
in utils.js
const result = await bookRentContract.borrowBook(spaceId,checkInDate,checkOutDate).send({
feeLimit:100_000_000,
callValue:totalPrice,
shouldPollResponse:true
});
- fetch all properties
-> insert inside fetchAllBooks()
method in utils.js
const bookId = await bookRentContract.bookId().call();
//iterate from 0 till bookId
for (let i = 0; i < bookId; i++){
const book = await bookRentContract.books(i).call()
if(book.name!="") // filter the deleted books
{
books.push(
{id: i,name: book.name,description: book.description,price: tronWeb.fromSun(book.price)}
)
}
}
return books