forked from Dapp-Learning-DAO/Dapp-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: rzry <[email protected]>
- Loading branch information
Showing
11 changed files
with
17 additions
and
448 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-1.18 MB
basic/75-golang-dapp/fxbl/2022-04-12_16-51-41_2022-04-124.51.34.png
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,13 @@ | |
#+end_src | ||
|
||
* 高屋建瓴 | ||
#+DOWNLOADED: file:/Users/rzry/Downloads/height.png @ 2022-04-12 16:21:40 | ||
[[file:gwjl/2022-04-12_16-21-40_height.png]] | ||
|
||
#+begin_src | ||
1. 获取到合约Abi/合约源码,如果是多文件扁平化处理 | ||
2. 使用solc abigen等工具生成go代码 | ||
3. 开发者调用代码 于链交互 | ||
#+end_src | ||
|
||
|
||
* 分星掰两 | ||
|
||
|
@@ -29,39 +34,34 @@ | |
我们直接使用uniswap的router02以及factory 就可以了,具体的代码github里面就有,也可以直接复制下面的代码 | ||
https://cronoscan.com/address/0x145677fc4d9b8f19b5d56d1820c48e0443049a30#contracts | ||
#+end_src | ||
#+DOWNLOADED: file:/Users/rzry/Desktop/截屏2022-04-12 下午4.35.30.png @ 2022-04-12 16:35:52 | ||
[[file:fxbl/2022-04-12_16-35-52_2022-04-124.35.30.png]] | ||
|
||
#+begin_src | ||
一个小技巧,很多链这个没法复制,可以点击More Options --> Compare 来复制. | ||
保存到truffle的一个文件夹. | ||
关于truffle的使用,就不啰嗦了,可以翻看具体之前项目内的文档. | ||
一些工具的推荐,solc-select(pip install),可以切换solc的版本 | ||
#+end_src | ||
#+DOWNLOADED: file:/Users/rzry/Desktop/截屏2022-04-12 下午4.39.07.png @ 2022-04-12 16:39:19 | ||
[[file:fxbl/2022-04-12_16-39-19_2022-04-124.39.07.png]] | ||
#+begin_src | ||
在 contracts 文件夹 touch uniswap.sol | ||
copy 代码进去. 修改默认的truffle-config.js版本. | ||
执行 solcjs --bin uniswap.sol | ||
如果你顺利的话应该能碰到这种版本错误的问题 | ||
#+end_src | ||
#+DOWNLOADED: file:/Users/rzry/Desktop/截屏2022-04-12 下午4.46.03.png @ 2022-04-12 16:47:21 | ||
[[file:fxbl/2022-04-12_16-47-21_2022-04-124.46.03.png]] | ||
|
||
#+begin_src | ||
这个问题,你首先要确定你的npm 读的是那个 solc ,然后才能解决. | ||
如果未在truffle项目内 npm init -f .那直接删除掉全局的npm内的solc | ||
再使用npm install -g [email protected]就可以了. | ||
当然solc-select也可以. | ||
下图为演示步骤 | ||
下为演示步骤 | ||
rm -rf /usr/local/lib/node_modules/solc | ||
sudo npm install -g [email protected] | ||
#+end_src | ||
#+DOWNLOADED: file:/Users/rzry/Desktop/截屏2022-04-12 下午4.48.53.png @ 2022-04-12 16:50:03 | ||
[[file:fxbl/2022-04-12_16-50-03_2022-04-124.48.53.png]] | ||
|
||
#+begin_src | ||
再运行图中命令,即可生成 bin 文件 . 同理生成 abi 文件 | ||
再运行命令,即可生成 bin 文件 . 同理生成 abi 文件 | ||
solcjs --bin uniswap.sol | ||
solcjs --abi uniswap.sol | ||
#+end_src | ||
#+DOWNLOADED: file:/Users/rzry/Desktop/截屏2022-04-12 下午4.51.34.png @ 2022-04-12 16:51:41 | ||
[[file:fxbl/2022-04-12_16-51-41_2022-04-124.51.34.png]] | ||
|
||
#+begin_src | ||
接下来使用abigen 即可生成 go 文件 . | ||
abigen --bin=uniswap_sol_IMeerkatRouter02.bin \ | ||
|
@@ -70,8 +70,7 @@ | |
那这个文件就是go 来链接链上Router合约,以及调用Router合约方法的文件 | ||
同理生成factory合约文件... | ||
#+end_src | ||
#+DOWNLOADED: file:/Users/rzry/Desktop/截屏2022-04-12 下午4.53.18.png @ 2022-04-12 16:54:31 | ||
[[file:fxbl/2022-04-12_16-54-31_2022-04-124.53.18.png]] | ||
|
||
- 使用go来与合约交互 | ||
#+begin_src | ||
使用一个现有的很简单的项目来讲解,此项目可以在github.com/rzry/flashDeal 找到源码 | ||
|
@@ -338,9 +337,4 @@ | |
比如三明治机器人,闪电贷机器人,抢购Nft,等等都可以操作. | ||
但是链下数据对比链上,以及每条链内存池,以及上链时间的变化都各有千秋. | ||
路漫漫其修远兮.吾将上下而求索. | ||
|
||
附一张成功的图 | ||
#+end_src | ||
|
||
#+DOWNLOADED: file:/Users/rzry/Desktop/截屏2022-04-12 下午5.44.36.png @ 2022-04-12 17:44:48 | ||
[[file:hjbf/2022-04-12_17-44-48_2022-04-125.44.36.png]] |
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-1.45 MB
basic/75-golang-dapp/hjbf/2022-04-12_17-44-48_2022-04-125.44.36.png
Binary file not shown.