1

I have a requirement where we are building a platform that receives funds on Ethereum L1 and sends that fund back to the same address on polygon L2. I know bridges are there to transfer funds from l1 to l2 but they don't want it. I have tried sending weth in a smart contract which I have deployed on polygon but it doesn't work below is the code. What I have done is define the interface of the Ethereum contract on polygon and declare some methods of eth contract. Any hint would be appreciated. Thanks

Code:

pragma solidity ^0.8.0;


interface EthToken{
    function approve()external returns(bool);
    function transferFrom()external returns(bool);
    function name()external returns(string memory);
    function totalSupply()external returns(uint256);
    function transfer(address add, uint256 amount) external returns(bool);
}


contract getFunds{


    EthToken token = EthToken(0xA6FA4fB5f76172d178d61B04b0ecd319C5d1C0aa);

// we write out all the global variables.
    address payable public requester;
    address[] public senders;

function generateRequest() public {
    requester = payable(msg.sender);
}

function transferEth(address add)public returns(bool){
    token.transfer(add, 1000000 wei);
    return true;
}

function name()public returns(string memory){
    return token.name();
}

function totalSupply() public returns(uint256){
    uint256 supply = token.totalSupply();
    return supply;
}

function getContractBalance()public view returns(uint256){
    return address(this).balance;
}
function donate() public payable {
// we ensure that there is a minimum value of wei that can be sent
    require(msg.value > 100000 gwei); 
    senders.push(msg.sender);
}
function makePayment() public{
    require(requester == msg.sender);
    requester.transfer(address(this).balance);
    senders = new address[](0);
}
function getSenders() public view returns(address[] memory){
    return senders;
  }
}```
1

3 Answers 3

1

It's not quite possible in solidity, but you can always use 3rd party centralized way of doing it

You can read event on the frontend whenever funds are transferred and then you can basically send funds to another wallet just by signing the transaction from wallet on the frontend automatically

1

Each blockchain (Ethereum and Polygon for example) have their own storages, and cannot be accessed one with other. Its only possible to manage with 3rd party backends that could monitor both blockchains and make corresponding transactions (for example - bridges). Future-more, WETH on Ethereum its not the same WETH that exist in Polygon. This is 2 different tokens in 2 different blockchains. They will be fungible only if you have ability to exchange one to another in 1:1 ratio (for example - over bridge).

1
  • So is there no way to transfer weth on polygon to polygon. Conceptually, there should be a way, because if we have weth on polygon then there must be its erc20 contract living on polygon if that is the case then we should be able to define its interface in our custom contract and use its methods to transfer funds as I have used that approach in my contract above but unfortunately, that doesn't work. IDK what is it that I'm missing?
    – Naveed Ali
    Jun 15, 2022 at 5:44
0

We must understand some basics here.

Each blockchain have their CORE TOKEN. That token used inside blockchain to pay gas fee for transactions. In polygon BC that token is MATIC, in ethereum - ETH, in tron - TRX, in BSC - BNB etc. But because some of this blockchains is direct clones of ethereum BC - they all inside solidity code call their token as ETH.

For example, if you will run requester.transfer(address(this).balance) on polygon blockchain - you will transfer all MATIC balance of this contract to requester. If you want transfer WETH (wrapped ethereum token on Polygon), you need to use ERC20 contract WETH, that was created on Polygon, and developers of Polygon makes some work (makes token pegged) to give us ability for swap their token to original WETH on ethereum BC 1:1.

Some deeper about your question.

If you want transfer WETH tokens, you cant use address.transfer(amount) because this is method for core token (ETH in ethereun, MATIC in polygon). Instead you need call WETHcontract.transfer(address, amount)

https://polygonscan.com/address/0x7ceb23fd6bc0add59e62ac25578270cff1b9f619 This is WETH on POLYGON. whis token is not the same as WETH on ethereum https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

BUT, we could assume that this is "same" token, because some bridges give us ability to exchange polygon WETH for ethereum WETH in 1:1 ratio.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.