Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
851 B
1
Indexable
Never


const [transactions, setTransactions] = useState([])
.
.
.


const getAllTransactions = async (web3) => {
      if (web3 && account.data !== null) {
        try {
          const txList = await contract.methods.getAllTransactions().call()
           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*1000).toLocaleDateString(),
              keyword: transaction.keyword
            }))
            console.log(structuredTransactions)
            setTransactions(structuredTransactions) 
        } catch (error) {
          console.log("No Transactions")
        }
      }
    }