Problem
Whenever I call the paytest function (please see code snippet below) from javascript (please see code snippet below) i receive the below posted error message. Whether i use address.send, address.transfer or address.call, doesnt matter.Nothing works. I have plenty of test ETH on all accounts.
I use hardhat for my local blockchain.
Please help me. i am getting insane.
Solidity Code
contract DC is ERC1155, Ownable {
function paytest (address receiver, uint256 amount) public payable{
(bool success, bytes memory _data) = payable(receiver).call{value:amount}("");
require (success, "transaction failed");
data=_data;
}
event Log(string fun, address sender, uint value, bytes data);
fallback() external payable {
emit Log("fallback", msg.sender, msg.value, msg.data);
}
receive() external payable {
emit Log("receive", msg.sender,msg.value, "");
}
Javascript File
async function main () { // boiletplate function
const address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'; // actual contract address
const DC = await ethers.getContractFactory('DC');
const dc = await DC.attach(address);
const [owner, addr1, addr2] = await ethers.getSigners();
await dc.connect(addr1).paytest(address,ethers.utils.parseEther("1.0"));
Error message console
C:\Users\Admin\hhtest>npx hardhat run --network localhost ./scripts/index.js
ProviderError: Error: VM Exception while processing transaction: reverted with reason string 'transaction failed'
at HttpProvider.request (C:\Users\Admin\hhtest\node_modules\hardhat\src\internal\core\providers\http.ts:78:19)
at GanacheGasMultiplierProvider.request (C:\Users\Admin\hhtest\node_modules\hardhat\src\internal\core\providers\gas-providers.ts:312:34)
at processTicksAndRejections (node:internal/process/task_queues:96:5)