- Author:Lee Ting Ting
- 這邊以 pancakeswap 上從 WBNB 換成 CAKE為例
前言 - 如何讓 Fork 跟 DEX 互動?
參加 DeFi Portfolio 比賽的學員使用 Tenderly Fork 區塊鏈,連接上 Metamask 後發現許多 DEX 連接 Metamask 時只會連接主網、無法連接 Fork 網。
本教學文章教大家如何讓繞過 DEX 前端網頁的阻擋,讓 Fork 能夠跟 DEX 進行交易。
步驟
-
用正常前端跟合約互動,從 Metamask 紀錄找出要互動的合約地址
- 0x10ED43C718714eb63d5aA57B78B54704E256024E
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
發交易後從 block explorer 上拿到資料,並複製 Input 欄位(註:需 git clone 下來並修改 rpc url)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 將 data 貼到解碼 Tx data 的工具,右邊就是解碼完的資料
- 補充:為何要這麼麻煩從這邊撈資料?因為 Metamask 上看不到這個 data
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 如果你是用 Tenderly 產生 forked rpc url 的話,可以從他 dashboard 裡找到一樣的 data 資料
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 剛解碼完的 input 那邊共有三個地址,第三個是我們發交易的地址,第一個是 WBNB 代幣合約,第二個是 CAKE 代幣合約(從 BSCscan 上貼地址找到)
- 由此可推論這欄位意思是從 WBNB 換成 CAKE
- 因此,如果我們想反過來,從 CAKE 換成 WBNB,需要顛倒這個 array 裡的參數順序
- 接著看 input 的第一個 hex number 0x90fe74b63161effb 是什麼,轉換完再除以 10^18 是 10.44,也就代表我們該交易完後收到了 10.44 CAKE
- 再來看 input 的第二個 hex number 0x627a044a,換算完是 1652163658,從下面的 names 對應到最後一個參數代表 deadline,可以知道他是 unix timestamp,也就是 2022-05-10 14:20,而從交易紀錄可知,交易的發送時間是 14:01,也就是超過這個時間交易還沒被確認的話,這筆買賣會無效
- 最上面的 method swapExactETHForTokens 代表我們是想執行換幣的動作
- 了解這些之後,就能自己做交易 input data 了!首先找到這個 encode data 網站
- 輸入以下參數,將 CAKE 換成 WBNB,產生以下 data 後複製
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 到 Metamask 上 transfer 到這個合約地址,並貼上剛剛的字串到 hex data 欄位
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 按下 Next 就能成功發送交易換幣成功!
- 把一樣的 input hex data 貼上 Tenderly 做 Simulation 能更看清楚這之中發生了什麼事
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 按上圖輸入好後按下一步,如果之後有交易失敗,也能用這個方式 Debug
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 這樣就成功把 CAKE 換回成 WBNB 了!
補充
更簡單的方式是用 Tenderly 發交易,他會幫你 encode input parameter,輸入完一樣按送出就可以了,記得右邊 from 要貼上自己送出交易的地址,不然預設會從 0x0 空地址送出
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →