-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-books.js
39 lines (31 loc) · 1.3 KB
/
add-books.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const bookstore = require('./build/contracts/Bookstore.json')
const bookstoreItem = require('./build/contracts/BookstoreItem.json')
const contract = require('@truffle/contract')
const books = require('./dapp/src/data/books.json')
const bookstoreContract = contract(bookstore);
const bookstoreItemContract = contract(bookstoreItem);
bookstoreContract.setProvider(web3.currentProvider);
bookstoreItemContract.setProvider(web3.currentProvider);
module.exports = async function(callback) {
const accounts = await web3.eth.getAccounts();
const store = await bookstoreContract.deployed();
const item = await bookstoreItemContract.deployed();
//Minting the books
for (var i = 0; i < books.length; i++) {
var book = books[i];
const result = await item.mint(accounts[0], book.link, {from : accounts[0]});
console.log(`Minted ${book.title}`)
}
//Approving the book transfer
for (var i = 1; i <= books.length; i++) {
const result = await item.approve(store.address, i, {from : accounts[0]});
console.log(`Approved item ${i}`);
}
//listing items on the store
for (var i = 1; i <= books.length; i++) {
console.log(`Attempting to list item ${i} on the store`);
const result = await store.listItem(item.address, i, i*11,{from : accounts[0]});
console.log(`Success!`);
}
return
}