Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
761 B
3
Indexable
Never
const getAllTransactions = async (web3) => {
      if (web3) {
        try {
          const txList = await contract.methods.getAllTransactions().call() // --> calling struct in smart contract
              const structuredTransactions = txList.map((transaction) => ({
              addressFrom: transaction.sender,
              addressTo: transaction.receiver,
              amount: parseInt(transaction.amount) / (10 ** 18),
              message: transaction.message,
              timestamp: new Date(transaction.timestamp.toNumber() * 1000).toLocaleString(),
              keyword: transaction.keyword
            }))
          console.log(structuredTransactions)
        } catch (error) {
          console.log("No Transactions");
        }
      }
    }