6

调用swapExactTokensForTokens如何节约gas

 2 years ago
source link: https://learnblockchain.cn/question/2999
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

调用swapExactTokensForTokens如何节约gas | 登链社区 | 技术问答

调用swapExactTokensForTokens如何节约gas

function buy(uint amountIn,uint amountOut,address token_address) external isOwner{   
        address[] memory path = new address[](2);
        path[0] = address(0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd); 
        path[1] = address(token_address);         
        Irouter(0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3).swapExactTokensForTokens(amountIn,amountOut,path,address(this),block.timestamp+15);    
    }

这是我写的购买token的函数,调用时要花费13万gas,但我观察到像1inch的交换只花费了11万gas,还有的合约只花费10万gas左右,这里还有更底层节约gas的相关方法吗,他们是如何实现节约gas的?比如调用pair合约的swap方法实现?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK