I’m encountering an issue with my getAllShipment
function in my JavaScript code. The function is intended to fetch and map shipment data from a smart contract. However, I’m seeing that only the first two console.log statements (1 and 2) are printed, and the third statement (3) isn’t reached.
const getAllShipment = async () => {
try {
console.log("1")
const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()
const contract = new ethers.Contract(ContractAddress, ContractABI, signer)
console.log("2")
const shipments = await contract.getAllTransactions()
console.log(shipments)
console.log("3")
const allShipments = shipments.map((shipment) => ({
sender: shipment.sender,
receiver: shipment.receiver,
price: ethers.utils.formatEther(shipment.price.toString()),
pickupTime: shipment.pickupTime.toNumber(),
deliveryTime: shipment.deliveryTime.toNumber(),
distance: shipment.distance.toNumber(),
isPaid: shipment.isPaid,
status: shipment.status,
}));
return allShipments;
} catch (error) {
console.log("Something went wrong", error);
}
}
Details:
- Contract Address and ABI: The
ContractAddress
andContractABI
are correctly defined and used. - Function
getAllTransactions
: The functiongetAllTransactions
is expected to return an array ofshipment
objects. - Error Handling: The catch block is in place to catch any errors, but no specific errors are logged.
Could you help me diagnose why the code isn’t reaching the third console.log
statement and how I might resolve this issue? I’ll provide the contract and full JavaScript code if needed.
ALISHA REDDY is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1