# 【科学家养成日记#12】挽救被黑钱包里面的剩余资产

By [Ericet](https://paragraph.com/@ericet) · 2022-02-21

---

今天看到Matters上一篇帖子说自己的钱包被黑，账号上的币被转走，钱包里剩下一些NFT，问大家是否有办法转走?

一般钱包被黑，大几率是黑客掌握了钱包的私钥，所以如果你把ETH转进去作为转走剩余资产的GAS，很大可能转进去就被黑客程序自动转走

要想把剩余资产转走，就需要用到Flashbot，在同一个区块里面完成转币进去，同时转资产去另外一个钱包的操作。

![](https://storage.googleapis.com/papyrus_images/ec91003c44484c73786f0b80ad241cfc68df2aaae075cc646d884f46fe2eab8f.png)

怎么用Flashbot挽救钱包里面的NFT呢?
-----------------------

这里要用到脚哥script money的flashbot工具（[https://github.com/script-money/ens-claim-flashbot-example](https://github.com/script-money/ens-claim-flashbot-example) ）

源代码里面授权ERC721那部分有个小bug，所以就用我fork的代码进行NFT转移

### 设置

    git clone https://github.com/ericet/ens-claim-flashbot-example.git
    cp .env.example .env
    yarn install
    

打开.env文件，添加所需信息

![](https://storage.googleapis.com/papyrus_images/e923fa3e1dcc81fdc7938e7daf8460e0efa49409deeedb505a5ad87fd6d2775f.png)

### NFT授权

添加好后，保存并打开/src/index.ts，修改ERC721的合约地址（需要转移的NFT的合约地址）

![](https://storage.googleapis.com/papyrus_images/840cd3c2b5572d5f1c4daddbb670c9620c90394892b941b0620335c0118c9cb7.png)

修改后，运行

`yarn start`

程序就会给将给要执行转移的钱包NFT授权

![](https://storage.googleapis.com/papyrus_images/63c5e9c83e7cfceff5f383c9979cde1e9286800895aee1bda245da6e45d9c738.png)

### 转移NFT

注释掉NFT授权那段(75-76), 取消注释NFT转移那段(80-82), 并且修改一下NFT\_ADDRESS那里的NFT合约地址(需要转移的NFT的合约地址)和TOKENIDS（NFT的ID）

![](https://storage.googleapis.com/papyrus_images/c1c793918ea07ec6c8b8e8cb5330027f1503470417cc085b9b9df36cd854186a.png)

修改好后，运行

`yarn run`

等待交易成功，你的

![](https://storage.googleapis.com/papyrus_images/adc1963c43bbaf611d204a4417a29be160044ba9bcc4586f859633280b836474.png)

最终链上的记录:

![](https://storage.googleapis.com/papyrus_images/ea4e39d7e9af248580b0265a55b65bfb684e6ff36947a1934b7a65abacd14aa7.png)

可以看到3个操作是在同一个区块里面完成的，这样如果钱包被黑客监控，他们也不可能在同一个区块里把你的币劫走

上面只介绍了转移NFT，程序还支持转移代币，领取空投并转移，等等

想了解的可以看看index.ts里面的注释

源代码来自脚哥的github: [https://github.com/script-money/ens-claim-flashbot-example](https://github.com/script-money/ens-claim-flashbot-example)

研究一下是否能改成页面操作，降低一下门槛

---

*Originally published on [Ericet](https://paragraph.com/@ericet/12)*
