I know it sounds like a basic question (it should be), despite that I could not find any clear reference to that in polygon's (Matic) docs on how does payable(address).call
works
pragma solidity ^0.7.6;
contract MyFirstPolygonContract {
string private name;
uint private amount;
function sendFunds(address receiver) external payable {
payable(receiver).call{value: msg.value}('');
}
//set
function setName(string memory newName) public {
name = newName;
}
//get
function getName () public view returns (string memory) {
return name;
}
//set
function setAmount(uint newAmount) public {
amount = newAmount;
}
//get
function getAmount() public view returns (uint) {
return amount;
}
}
I deployed this contract into Matic Mainnet in order to test sendFunds
and quantify the amounts. I tried sending funds between two of my accounts sender_addr
, recv_addr
.
On Remix, I have chosen to send 1 ether on this contract (deployed on Matic). One Matic Token has been deducted from sender_addr
. But the recv_addr
received none !! It's been about 24 hours now. The transaction is not even shown on polygon scan !
It's worth noting that function sendFunds
worked as expected on Mumbai testnet though.
EDITED:
The contracts are deployed in different networks having the same address
0x3918AaECf75aD253E0098fD0ee5C11d854BE9de6
I did that exact transaction on the testnet 0.1 MATIC
https://explorer-mumbai.maticvigil.com/address/0x3918AaECf75aD253E0098fD0ee5C11d854BE9de6/transactions (this was successful)
While I did those two transactions added 1.001 MATIC
on the matic mainnet
https://polygonscan.com/address/0x3918aaecf75ad253e0098fd0ee5c11d854be9de6 (failed to send to recv_addr
)
Best Answer
The issue is that your contract is not deployed on Mainnet.
It is deployed on Testnet, but on Mainnet there is no contract code associated with the address.
You should try to deploy it again on Mainnet. As you know, if you use the same address and same nonce as on testnet, you should have the same address for your Mainnet contract.
If you want to receive the MATIC that you sent to the address back, you should add a
withdraw
function to your contract that transfers all the contract balance tomsg.sender
. Otherwise, this MATIC will be lost forever.EDIT: I think that this is your contract on Mainnet. The address is not the same as on Testnet, althought they both start by 0x39! You called the wrong address on Mainnet.