快速入门

本文将简要介绍配置开发环境,及编写和部署合约的流程。

开发环境准备

如需接入安顺链,可直接接入官方节点或参考全节点接入教程。

IDE

示例中我们使用 Hardhat 进行开发演示。请参考 Hardhat 的详细使用教程arrow-up-right

Hardat 配置

hardhat.config.js中配置本地或远程 network,填入url、chainId 和部署账户地址。

require("@nomiclabs/hardhat-waffle");

task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

module.exports = {
  solidity: "0.8.4",
  networks: {
    local: {
      url: "http://127.0.0.1:8545/",
      chainId: 1088,
      accounts: [""]  //fill in your account address
    }
  }
};

编写合约

这里我们使用 Hardhat 的示例合约Greeter.sol

编写部署脚本

编写部署脚本 sample-script.js。

运行脚本部署合约

运行之前请先确认部署账户中有足够的 Gas 燃料。

调用成功后可以看到合约地址的打印。

示例源码

Last updated