I am following the Amazon clone video. Everything is working well. Iâm trying to add a transaction hash field to the custom âTransactionâ table. Currently for the table it is pulling the address âCustomerâ directly from Moralis. My other three fields, âDeliveryâ, âbook.nameâ, âbook.priceâ, are all custom fields not related to moralis api (i guess book.price is related somewhat).
I know the transaction hash is automatically saved for all transactions. I can see it in the âBscTransactionsâ table in the moralis dashboard. I feel like I shouldnât have to run a query for something that is already being pulled by default and for something that just instantaneously happened.
Here is the full code:
import {Select, Button, Modal, Input} from 'antd'
import {ShoppingCartOutlined} from "@ant-design/icons";
import { useState } from 'react';
import { useMoralis } from 'react-moralis';
const {Option} = Select;
function Purchase({book}) {
const [isModalVisible, setIsModalVisible] = useState(false);
const [delivery, setDelivery] = useState("");
const {Moralis, Native, account, chainId} = useMoralis();
const handleOk = async () => {
//Get token price on PancakeSwap v2 BSC
const options = {
address: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
chain: "bsc",
exchange: "PancakeSwapv2",
};
const price = await Moralis.Web3API.token.getTokenPrice(options);
const priceBNB = book.price / price.usdPrice;
// Send Matic to book store owenr address
const options1 = {
type: "native",
amount: Moralis.Units.ETH(priceBNB),
receiver: "0xf435247364F38e7f182372fbfF58E50f0A90E88F"
}
let result = await Moralis.transfer(options1);
//Save Transaction Details to DB
const Transaction = Moralis.Object.extend("Transaction");
const transaction = new Transaction();
transaction.set("Customer", account);
transaction.set("Delivery", delivery);
transaction.set("Product", book.name);
transaction.set("Spent", book.price);
transaction.save()
setIsModalVisible(false);
}