diff --git a/templates/portal_invoice_detail.html b/templates/portal_invoice_detail.html
index f907265..2191a1d 100644
--- a/templates/portal_invoice_detail.html
+++ b/templates/portal_invoice_detail.html
@@ -537,19 +537,32 @@ Reference: ${invoiceRef}`;
const decimals = Number(walletButton.dataset.decimals || "18");
const tokenContract = walletButton.dataset.tokenContract || "";
- await window.ethereum.request({ method: "eth_requestAccounts" });
+ const accounts = await window.ethereum.request({ method: "eth_requestAccounts" });
+ const from = Array.isArray(accounts) && accounts.length ? accounts[0] : "";
+ if (!from) {
+ throw new Error("Wallet did not return an account address.");
+ }
+
await switchChain(chainId);
let txHash;
if (assetType === "native") {
txHash = await window.ethereum.request({
method: "eth_sendTransaction",
- params: [{ to: to, value: toHexBigIntFromDecimal(amount, decimals) }]
+ params: [{
+ from: from,
+ to: to,
+ value: toHexBigIntFromDecimal(amount, decimals)
+ }]
});
} else {
txHash = await window.ethereum.request({
method: "eth_sendTransaction",
- params: [{ to: tokenContract, data: erc20TransferData(to, amount, decimals) }]
+ params: [{
+ from: from,
+ to: tokenContract,
+ data: erc20TransferData(to, amount, decimals)
+ }]
});
}