# 中文圈首发：Fuel合约部署教程

By [Bitbigcat](https://paragraph.com/@bitbigcat) · 2023-04-19

---

首先，

1.需要准备一个Ubuntu的服务器或者虚拟机来进行，服务器随便是什么配置都行，最低档的都可以操作。

2.服务器需要有一个SSH登陆工具，如果你有虚拟机就不用这一步了，我自己是用的VPS+SSH登陆的方式来进行，因为我是Windows系统，我推荐用Termius这个工具来进行ssh登陆。

3.需要准备Fuel钱包并领水，记得把助记词备份好，一会儿要用。

钱包下载（现在解压包然后谷歌浏览器选开发者模式，在扩展程序中打开解压的文件夹）：

[https://wallet.fuel.network/docs/install/](https://wallet.fuel.network/docs/install/)

领水地址：

[https://faucet-beta-3.fuel.network/](https://faucet-beta-3.fuel.network/)

SSH登录工具Termius下载链接（这个工具复制和粘贴都需要按住Ctrl+shift+C或者Ctrl+shift+V）：

[https://termius.com/free-ssh-client-for-windows](https://termius.com/free-ssh-client-for-windows)

准备好这些工具后，我们登陆Termius：

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

输入完成之后，双击Hosts里面的项目，就可以正式连接了（如果是新配置的服务器，需要等待一会儿才能链接）：

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

如果出现以下界面，那我们就成功连接上服务器了：

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

**一.下面我们开始对服务器进行一些必要的升级：**

1.更新VPS，输入以下代码

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

2.更新服务器，输入以下代码：

    sudo apt update
    

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

3.再输入以下代码，如果中间出现询问Y/N，就输入Y：

    sudo apt-get install screen
    
    sudo apt-get install git-all
    

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

如果中间出现粉红色的界面，直接按回车跳过：

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

**二、开始安装Fuel的语言工具Rust。**

1.安装rust工具，输入以下代码，中间出现选项，输入1：

    curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
    

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

2.配置必要文件，输入以下代码：

    source "$HOME/.cargo/env"
    

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

3.更新Rust工具，输入以下代码：

    rustup update stable
    
    rustup default stable
    

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

4.安装Fuel脚本，输入以下代码，并在Y/N选项中，输入Y确认：

    curl --proto '=https' --tlsv1.2 -sSf https://install.fuel.network/fuelup-init.sh | sh
    

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

5.配置PATH，输入以下代码：

    export PATH="$HOME/.fuelup/bin:$PATH"
    
    source /root/.bashrc
    

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

6.现在我们输入以下代码看看fuel是否正确安装了，如果跟我一样就是正确了：

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

7.创建fuel合约文件夹，输入以下代码：

    mkdir fuel-project
    
    cd fuel-project
    

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

8.创建合约模版，输入以下代码：

    forc new counter-contract
    

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

9.安装VIM编辑合约，输入以下代码：

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

10.继续输入以下代码后会显示：

    vim counter-contract/src/main.sw
    

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

**11.把上面的合约替换为下面的合约：**

**注意：**

按键盘上的 i 键，将VIM切换为插入模式

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

按键盘上的 w键，将VIM切换为选择模式

删除所有的合约。

然后复制下面合约，把上面合约的替换掉：

    contract;
    
    storage {
        counter: u64 = 0,
    }
    
    abi Counter {
        #[storage(read, write)]
        fn increment();
    
        #[storage(read)]
        fn count() -> u64;
    }
    
    impl Counter for Contract {
        #[storage(read)]
        fn count() -> u64 {
            storage.counter
        }
    
        #[storage(read, write)]
        fn increment() {
            storage.counter = storage.counter + 1;
        }
    }
    

这是全部删除后，重新输入的合约模版：

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

然后按 ESC 键退出插入模式

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

然后按键盘上的 shift+ ：这个键（L旁边的键），输入w之后，按回车保存更改。

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

然后再按键盘上的 shift + ：这个键，输入q之后退出：

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

然后我们就正常回到服务器页面了：

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

12.开始编译合约，输入以下代码：

    cd counter-contract 
    
    forc build
    

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

13.接着导入我们Fuel的钱包了，需要准备好之前备份的助记词，而且钱包里至少有水，接着输入导入钱包的代码：

    forc-wallet import 
    

助记词复制进去是不会显示的，所以粘贴一次等待一下就可以按回车了：

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

接着创建一个密码，也不会显示，所以要手动输入下：

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

然后会让你确认一下密码，就再次输入一次：

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

14.开始部署合约，输入以下代码：

    forc deploy --node-url beta-3.fuel.network/graphql --gas-price 1 --random-salt
    

输入完成之后，显示以下界面，然后我们去Fuel钱包复制钱包地址：

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

这是我的钱包地址，Feul开头的，在Fuel钱包里能够找到，然后按回车：

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

**之后会显示让你签名，这一步很重要了：**

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

**把这个sign的ID复制下来，然后我们重新打开一个Termius的窗口：**

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

复制后的窗口是这样的：

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

**我们在新窗口输入以下代码，需要tx-id后面的替换为你刚刚复制的sign签名那个ID：**

    forc wallet sign --account 0 tx-id XXXXXXXXXXXXXXXXXX
    

这个XXXXX就是你刚刚另外一个窗口复制的那个Sign id的签名，比如我的是这样的：

forc wallet sign --account 0 tx-id a7381b503ded69ce8912282075effb50ac70293509cfb563f15b672c6f664bf1

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

按回车后输入密码：

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

然后就得到了签名的新id：

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

然后我们把这个新的id复制下来，返回原来的那个窗口粘贴下来：

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

然后再按回车进行签名，我们就成功部署了合约：

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

只要看到那个deployed in block 后面的就是成功部署了合约了。

15.查看合约是否部署成功：

找到之前sign的那个id：

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

然后打开Fuel的区块链浏览器：

[https://fuellabs.github.io/block-explorer-v2/beta-3/#/](https://fuellabs.github.io/block-explorer-v2/beta-3/#/)

要在sign的id前面加一个：0x

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

然后查询就可以看到，我们成功部署了：

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

**做到这里你就成功完成了Fuel的合约部署了，是不是很简单呢？**

你也可以在Fuel钱包的交易历史记录里，看到部署的合约记录：

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

下面是我的推特，记得关注：

[https://twitter.com/WilliamHill888](https://twitter.com/WilliamHill888)

---

*Originally published on [Bitbigcat](https://paragraph.com/@bitbigcat/fuel)*
