首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何使用信托基金在ThunderCore上部署合同?

我如何使用信托基金在ThunderCore上部署合同?
EN

Stack Overflow用户
提问于 2020-04-21 05:55:29
回答 1查看 514关注 0票数 1

我如何使用信托基金在ThunderCore上部署合同?这和用松露涂在百合花上一样吗?如何设置配置?是否有任何文件或资源可供参考?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-21 06:55:17

将您的信托项目设置为:

  1. 使用@truffle/hdwallet-provider并将其指向https://mainnet-rpc.thundercore.com
  2. byzantium设置为Solidity编译器的目标EVM版本
    • 见下面evnVersion中的truffle-config.js
    • ThunderCore自2020年4月起支持byzantium

自包含项目模板

package.json

代码语言:javascript
复制
{
  "name": "field-support",
  "version": "0.0.1",
  "main": "trufflej-config.js",
  "license": "LicenseRef-COPYING",
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "json5": "^2.1.0",
    "truffle": "^5.1.22",
    "@truffle/hdwallet-provider": "^1.0.34"
  },
  "scripts": {
    "test": "truffle test",
    "migrate": "truffle migrate",
    "deploy": "truffle migrate",
    "compile": "truffle compile",
    "build": "truffle build",
    "lint": "solium -d contracts && eslint ."
  },
  "keywords": [
    "smart contract"
  ],
  "author": ""
}

truffle-config.js

代码语言:javascript
复制
const HDWalletProvider = require("@truffle/hdwallet-provider");

const fs = require("fs");

const MAINNET_PROVIDER = "https://mainnet-rpc.thundercore.com";

let privateKeys = null;
let mnemonic = null;
try {
  privateKeys = fs
    .readFileSync(".private-keys", { encoding: "ascii" })
    .split("\n")
    .filter(x => x.length > 0);
} catch (err) {
  if (err.code !== "ENOENT") {
    throw err;
  }
}

if (!privateKeys) {
  try {
    mnemonic = fs.readFileSync(".mnemonic", { encoding: "ascii" }).trim();
  } catch (err) {
    if (err.code !== "ENOENT") {
      throw err;
    }
  }
}

module.exports = {
  networks: {
    // For `truffle develop`
    development: {
      host: "127.0.0.1", // Localhost (default: none)
      port: 9545, // Standard Ethereum port (default: none)
      network_id: "*" // Any network (default: none)
    },
    "thunder-mainnet": {
      provider: () => {
        if (privateKeys === null && mnemonic === null) {
          throw new Error("Please create a .private-keys or .mnemonic file");
        }

        return privateKeys
          ? new HDWalletProvider(
              privateKeys,
              MAINNET_PROVIDER,
              0, // <- change address_index if you want to use non-first address
              privateKeys.length
            )
          : new HDWalletProvider(
              mnemonic,
              MAINNET_PROVIDER,
              0 // <- change address_index if you want to use non-first address
            );
      },
      network_id: "108"
    }
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.5.9", // Fetch exact version from solc-bin (default: truffle's version)
      settings: {
        // see the solidity docs for advice about optimization and evmversion
        optimizer: {
          enabled: true,
          runs: 200
        },
        evmVersion: "byzantium" // Current evm on ThunderCore fixed at "byzantium"
      }
    }
  }
};

contracts/SimplStorage.sol

代码语言:javascript
复制
pragma solidity ^0.5;

contract SimpleStorage {
  uint storedData;

  function set(uint x) public {
    storedData = x;
  }

  function get() public view returns (uint) {
    return storedData;
  }
}

migrations/2_deploy.js

代码语言:javascript
复制
const SimpleStorage = artifacts.require('SimpleStorage');

module.exports = function(deployer) {
  deployer.deploy(SimpleStorage);
};

样本会话

  1. 创建在Metamask的钱包
  2. 通过ThunderCore Mainnet水龙头获取雷电令牌(TT)
  3. 导出私钥并将其保存到.private-keys文件
  4. 运行truffle migrate --network thunder-mainnet
代码语言:javascript
复制
$ truffle migrate --network thunder-mainnet

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'thunder-mainnet'
> Network id:      108
> Block gas limit: 0x5f5e100


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0x4d943a338d683d7ba0dc4937417b4b795b4791849b4695aeddb8811bdb265183
   > Blocks: 5            Seconds: 6
   > contract address:    0xFAc8a9a57cb2C70059D603f393F4A4f830C43a34
(...)

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00554924 ETH


2_deploy.js
===========

   Deploying 'SimpleStorage'
   -------------------------
   > transaction hash:    0x8a6063fa9dd74935e0db262a03ffee38181e383e3d73dd408cc76730e79ac135
   > Blocks: 5            Seconds: 6
   > contract address:    0x75F89Ba793DDFFCA4b604Ae8B28E8DfD8Dbbe14a
(...)

您可以在这里回购的simple-storage分支中找到代码field-support

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61336822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档