# LInea测试网奥德赛活动Lifi交互教程 **Published by:** [Web3见闻](https://paragraph.com/@jackson-you/) **Published on:** 2023-05-07 **URL:** https://paragraph.com/@jackson-you/linea-lifi ## Content 1. Lifi目前的问题 Lifi由于过量的访问导致无法实现跨链桥的访问,本教程现在通过合约调用Lifi智能合约进行交互。 2. 访问Lifi测试网 由于Lifi智能合约需要相应的参数才能够运行,我们这里需要访问一下的地址: USDT代币我们使用下面的命令在命令行中请求, 这里我们需要讲fromAddress地址换成各位的地址: curl --request GET --url 'https://staging.li.quest/v1/quote?fromChain=5&toChain=59140&fromToken=0x41e5e6045f91b61aacc99edca0967d518fb44cfb&toToken=0x7823E8DCC8bfc23EA3AC899EB86921f90e80F499&fromAddress=0x9fa45Ac2A676cdeE77df20766D4F7D2C04cc9305&fromAmount=10&slippage=0.01&allowBridges=&allowExchanges=' --header 'accept: application/json' > 1.txt 在命令行输入上面的命令后,我们保存在1.txt文件中: 图1 上面表示我们请求成功了 接下来,我们在命令行输入: open . 这个时候我们就可以打开我们的文件目录了: 图2 我们现在打开文件1.txt,可以得到如下的内容: {"type":"lifi","id":"86af425e-7927-442e-a726-c6a8a3490d06","tool":"hop","toolDetails":{"key":"hop","name":"Hop","logoURI":"https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/bridges/hop.png"},"action":{"fromToken":{"address":"0xfad6367e97217cc51b4cd838cc086831f81d38c2","symbol":"USDT","decimals":6,"chainId":5,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"fromAmount":"10","toToken":{"address":"0x1990bc6dfe2ef605bfc08f5a23564db75642ad73","symbol":"USDT","decimals":6,"chainId":59140,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"fromChainId":5,"toChainId":59140,"slippage":0.01,"fromAddress":"0x9fa45Ac2A676cdeE77df20766D4F7D2C04cc9305","toAddress":"0x9fa45Ac2A676cdeE77df20766D4F7D2C04cc9305"},"estimate":{"tool":"hop","approvalAddress":"0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE","toAmountMin":"10","toAmount":"10","fromAmount":"10","feeCosts":[{"name":"LP Fee","description":"Fee paid to the Liquidity Provider","percentage":"0","token":{"address":"0x1990bc6dfe2ef605bfc08f5a23564db75642ad73","symbol":"USDT","decimals":6,"chainId":59140,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"amount":"0","included":true},{"name":"Bonder Fee","description":"Fee paid to the Bonder","percentage":"0","token":{"address":"0x1990bc6dfe2ef605bfc08f5a23564db75642ad73","symbol":"USDT","decimals":6,"chainId":59140,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"amount":"0","included":true},{"name":"Destination Tx Fee","description":"Fee paid to account for gas costs on the destination chain","percentage":"0","token":{"address":"0x1990bc6dfe2ef605bfc08f5a23564db75642ad73","symbol":"USDT","decimals":6,"chainId":59140,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"amount":"0","included":true},{"name":"Relayer Fee","description":"Fee charged on source chain to pay for relaying","percentage":"NaN","token":{"address":"0x0000000000000000000000000000000000000000","symbol":"ETH","decimals":18,"chainId":5,"name":"ETH","coinKey":"ETH","logoURI":"","priceUSD":"0"},"amount":"10000000000000000","amountUSD":"0.00","included":false}],"gasCosts":[{"type":"SEND","price":"2629338600378","estimate":"345703","limit":"460938","amount":"1211960761111734375","amountUSD":"0.00","token":{"address":"0x0000000000000000000000000000000000000000","symbol":"ETH","decimals":18,"chainId":5,"name":"ETH","coinKey":"ETH","logoURI":"","priceUSD":"0"}}],"executionDuration":5000,"fromAmountUSD":"0.00","toAmountUSD":"0.00"},"includedSteps":[{"id":"b5007e5b-2c29-4952-9dd9-59686209f50b","type":"cross","action":{"fromChainId":5,"fromAmount":"10","fromToken":{"address":"0xfad6367e97217cc51b4cd838cc086831f81d38c2","symbol":"USDT","decimals":6,"chainId":5,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"toChainId":59140,"toToken":{"address":"0x1990bc6dfe2ef605bfc08f5a23564db75642ad73","symbol":"USDT","decimals":6,"chainId":59140,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"slippage":0.01,"destinationGasConsumption":"0","fromAddress":"0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE","toAddress":"0x9fa45Ac2A676cdeE77df20766D4F7D2C04cc9305"},"estimate":{"tool":"hop","fromAmount":"10","toAmount":"10","toAmountMin":"10","approvalAddress":"0x53B94FAf104A484ff4E7c66bFe311fd48ce3D887","executionDuration":5000,"feeCosts":[{"name":"LP Fee","description":"Fee paid to the Liquidity Provider","percentage":"0","token":{"address":"0x1990bc6dfe2ef605bfc08f5a23564db75642ad73","symbol":"USDT","decimals":6,"chainId":59140,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"amount":"0","included":true},{"name":"Bonder Fee","description":"Fee paid to the Bonder","percentage":"0","token":{"address":"0x1990bc6dfe2ef605bfc08f5a23564db75642ad73","symbol":"USDT","decimals":6,"chainId":59140,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"amount":"0","included":true},{"name":"Destination Tx Fee","description":"Fee paid to account for gas costs on the destination chain","percentage":"0","token":{"address":"0x1990bc6dfe2ef605bfc08f5a23564db75642ad73","symbol":"USDT","decimals":6,"chainId":59140,"name":"Tether USD","coinKey":"","logoURI":"","priceUSD":"0"},"amount":"0","included":true},{"name":"Relayer Fee","description":"Fee charged on source chain to pay for relaying","percentage":"NaN","token":{"address":"0x0000000000000000000000000000000000000000","symbol":"ETH","decimals":18,"chainId":5,"name":"ETH","coinKey":"ETH","logoURI":"","priceUSD":"0"},"amount":"10000000000000000","amountUSD":"0.00","included":false}],"gasCosts":[{"type":"SEND","price":"2629338600378","estimate":"215625","limit":"287500","amount":"755934847608675000","amountUSD":"0.00","token":{"address":"0x0000000000000000000000000000000000000000","symbol":"ETH","decimals":18,"chainId":5,"name":"ETH","coinKey":"ETH","logoURI":"","priceUSD":"0"}}],"toolData":{"amountOut":"10","rate":"1","priceImpact":"0","requiredLiquidity":"10","lpFees":"0","bonderFeeRelative":"0","adjustedBonderFee":"0","adjustedDestinationTxFee":"0","totalFee":"0","estimatedReceived":"10","relayFeeEth":"10000000000000000"}},"tool":"hop","toolDetails":{"key":"hop","name":"Hop","logoURI":"https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/bridges/hop.png"}}],"integrator":"lifi-staging-api","transactionRequest":{"data":"0xb3b6358700000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000645897f1000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000645897f1000000000000000000000000b47de784ab8702ec35c5eab225d6f6ce476ddd280000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000e8b0339fd1aea078bd91b389e4c43f627be74f2e9aa52ffdc0430ccc06f1c21b000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fad6367e97217cc51b4cd838cc086831f81d38c20000000000000000000000009fa45ac2a676cdee77df20766d4f7d2c04cc9305000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000e704000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003686f70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000106c6966692d73746167696e672d61706900000000000000000000000000000000","to":"0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE","value":"0x2386f26fc10000","from":"0x9fa45Ac2A676cdeE77df20766D4F7D2C04cc9305","chainId":5,"gasPrice":"0x026430cb13ba","gasLimit":"0x07088a"}} 我们将最后的data的几行复制下来: 图3 可以得到下面的内容: { "data":"0xb3b6358700000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000645897f1000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000645897f1000000000000000000000000b47de784ab8702ec35c5eab225d6f6ce476ddd280000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000e8b0339fd1aea078bd91b389e4c43f627be74f2e9aa52ffdc0430ccc06f1c21b000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fad6367e97217cc51b4cd838cc086831f81d38c20000000000000000000000009fa45ac2a676cdee77df20766d4f7d2c04cc9305000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000e704000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003686f70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000106c6966692d73746167696e672d61706900000000000000000000000000000000", "to":"0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE", "value":"0x2386f26fc10000", "from":"0x9fa45Ac2A676cdeE77df20766D4F7D2C04cc9305", "chainId":5, "gasPrice":"0x026430cb13ba", "gasLimit":"0x07088a" } 这个是我们内容必须的,我们稍后会用到。 接下来我们需要访问 https://goerli.etherscan.io/address/0xfad6367E97217cC51b4cd838Cc086831f81d38C2#writeContract 这里我们可以看到下面的内容: 然后点击“connetct to web3” 我们可以看到下面的: 然后找到这个第7个函数,在第一个位置输入 0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE 第二个位置输入10000000000000000,点击write 这里点击确认: 然后找到第3个,就是下面的函数: 第一个位置输入0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE 第二个位置输入10000000000000000 然后点击write,然后确认 选择最大,然后点击下一步: 点击批准,等待确认成功。 复制下面的代码: const ethereumButton = document.querySelector('.enableEthereumButton'); const sendEthButton = document.querySelector('.sendEthButton'); let accounts = []; // Send Ethereum to an address sendEthButton.addEventListener('click', () => { ethereum .request({ method: 'eth_sendTransaction', params: [ { "data":"0xb3b6358700000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000645897f1000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000645897f1000000000000000000000000b47de784ab8702ec35c5eab225d6f6ce476ddd280000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000e8b0339fd1aea078bd91b389e4c43f627be74f2e9aa52ffdc0430ccc06f1c21b000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fad6367e97217cc51b4cd838cc086831f81d38c20000000000000000000000009fa45ac2a676cdee77df20766d4f7d2c04cc9305000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000e704000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003686f70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000106c6966692d73746167696e672d61706900000000000000000000000000000000", "to":"0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE", "value":"0x2386f26fc10000", "from":"0x9fa45Ac2A676cdeE77df20766D4F7D2C04cc9305", "chainId":5, "gasPrice":"0x026430cb13ba", "gasLimit":"0x07088a"} , ], }) .then((txHash) => console.log(txHash)) .catch((error) => console.error(error)); }); ethereumButton.addEventListener('click', () => { getAccount(); }); async function getAccount() { accounts = await ethereum.request({ method: 'eth_requestAccounts' }); } 上面data那一部分是我们前面请求的内容,需要替换成你自己的。 然后在相同目录中写html页面,这里需要首先安装metamask的相关插件,具体内容可以查看一下的内容: https://docs.metamask.io/wallet/how-to/send-transactions/ 安装好metamask之后,可以可以写如下代码: <button class="enableEthereumButton btn">Enable Ethereum</button> <button class="sendEthButton btn">Send ETH</button> 点击Send ETH即可。 3. 联系与捐赠 如果有问题,可以联系我 https://twitter.com/jackson63891075 如果觉得我写的不错,可以打赏哟: ETH: 0x0290e9cE53972B7a9cC59cCc11224DfB16612271 BSC: 0x0290e9cE53972B7a9cC59cCc11224DfB16612271 ## Publication Information - [Web3见闻](https://paragraph.com/@jackson-you/): Publication homepage - [All Posts](https://paragraph.com/@jackson-you/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@jackson-you): Subscribe to updates - [Twitter](https://twitter.com/Web3Sight): Follow on Twitter