I am building an app where I'd like a purchaser to be able to seek a refund from the contract. Essentially I am trying to transfer eth from a contract to a wallet. When I get to the point of issuing a refund, the transaction in MetaMask shows that my wallet is transferring to the contract, not vice versa as I'd like. I'm using web3 and solidity. Here is my js function that is called from the account seeking refund:
window.resellTicket = async function () {
// send a refund from contract to reseller
try {
// Call resell method from contract
const resell = TicketEvent.methods.resellTicket();
await resell.send({'value': web3.utils.toHex(web3.utils.toWei('.1234', "ether"))});
} catch (err) {
console.log(err);
}
load();
}
The resellTicket method in my contract:
function resellTicket() public payable {
msg.sender.transfer(ticketPrice);
isHoldingValidTicket[msg.sender] = false;
increaseInventory();
}
I've also tried hard coding the contract address as from: contract_address
in my resellTicket js function in which case I get this error: Error: Returned error: Error: WalletMiddleware - Invalid "from" address.
I'm totally stuck here, any guidance would be appreciated!