当前位置: 首页 > 知识库问答 >
问题:

币安智能链部署合约面临错误

栾烨华
2023-03-14

我正在尝试在Binance智能链网络上部署测试契约。我正在使用metamask和truffle来创建和测试合同。我的文件夹结构如下所示

const HDWalletProvider = require('truffle-hdwallet-provider-privkey');
    const privateKeys = process.env.PRIVATE_KEYS || ""
    
    module.exports = {
      networks: {
        development: {
          host: "127.0.0.1",
          port: 7545,
          network_id: "*"
        },
        binancetestnet: {
          provider: function() {
            return new HDWalletProvider(
              privateKeys.split(','), // Array of account private keys
              `https://data-seed-prebsc-1-s1.binance.org:8545/${process.env.INFURA_API_KEY}`// Url to an Ethereum Node
            )
          },
          gas: 5000000,
          gasPrice: 25000000000,
          network_id: 97
        }
      },
    
      // Set default mocha options here, use special reporters etc.
      mocha: {
        // timeout: 100000
      },
    
      // Configure your compilers
      compilers: {
        solc: {
           version: "0.7.3",    // Fetch exact version from solc-bin (default: truffle's version)
          // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
          // settings: {          // See the solidity docs for advice about optimization and evmVersion
          //  optimizer: {
          //    enabled: false,
          //    runs: 200
          //  },
          //  evmVersion: "byzantium"
          // }
        }
      }
    };

块菌部署错误

Macbook-Air Oracle % truffle migrate --reset --network binancetestnet
Error: Cannot find module 'truffle-hdwallet-provider-privkey'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/macbbok/Desktop/Oracle/truffle-config.js:1:26)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at Object.require (internal/modules/cjs/helpers.js:25:18)
    at Function.load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/index.js:161:1)
    at Function.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/index.js:150:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:199:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)
    at Object.module.exports (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/cli.js:56:1)
    at __webpack_require__ (/usr/local/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:19:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:83:1
    at Object.<anonymous> (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:89:10)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Truffle v5.1.54 (core: 5.1.54)
Node v10.16.3

我已经附上了所有我面临的错误代码。有人能帮我吗?我还安装了高清钱包提供商。块菌编译成功。

共有2个答案

计泉
2023-03-14

我遇到了类似的问题,并找到了使用私钥而不是助记符的解决方案:

在您的. env中:

API_URL = "https://ropsten.infura.io/v3/your project id" # note: put your node url here
PRIVATE_KEY = "your account private key"

在你的块菌配置中。js公司:

module.exports= {
....
rospten: {
  provider: () => new HDWalletProvider(
    process.env.PRIVATE_KEY,
    process.env.API_URL), 
    network_id: 3,
    gas: 1000000,
    gasPrice: 20000000000,
    confirmations: 2,
    timeoutBlocks: 200000,
 }
....
}
方波娃
2023-03-14

安装Truffle HD wallet后,提供商现在面临

MacBook-Air Test % truffle migrate --reset --network binancetestnet

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

Error: Could not create addresses from your mnemonic or private key(s). Please check that your inputs are correct.
    at new HDWalletProvider (/Users/macbook/Desktop/Test/node_modules/@truffle/hdwallet-provider/src/index.ts:124:13)
    at Object.provider (/Users/macbook/Desktop/Test/truffle-config.js:12:16)
    at Object.getProvider (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:20:1)
    at Object.create (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:13:1)
    at TruffleConfig.get [as provider] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/configDefaults.js:200:1)
    at Object.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:19:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:206:1
Truffle v5.1.54 (core: 5.1.54)
Node v14.15.4

我的块菌。js代码

const HDWalletProvider = require('@truffle/hdwallet-provider');
const privateKeys = process.env.PRIVATE_KEYS || ""
module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    },
    binancetestnet: {
      provider: function() {
        return new HDWalletProvider(
          privateKeys.split(','), // Array of account private keys
          `https://data-seed-prebsc-1-s1.binance.org:8545/${process.env.INFURA_API_KEY}`// Url to an Ethereum Node
        )
      },
      gas: 5000000,
      gasPrice: 25000000000,
      network_id: 97
    }
  },

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

  // Configure your compilers
  compilers: {
    solc: {
       version: "0.7.3",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  }
};

我的. env文件

ETHERSCAN_API_KEY=https://data-seed-prebsc-1-s1.binance.org:8545/
INFURA_API_KEY=https://data-seed-prebsc-1-s1.binance.org:8545/
PRIVATE_KEYS="9xxxxx3fb486a57ad13e6db71xxxxx456e4128d51ecxxxxxxxd"
DEV_ADDRESS="0xxxxxxe80e3a43EBCab9A6CeC9d9e2a49100AxxxC"
 类似资料:
  • 部署智能合约及与智能合约交互 如果你想避免使用智能合约的底层实现细节,web3j提供solidity的智能合约的封装包,使你能够通过web3j生成的包装对象直接与智能合约的所有方法进行交互。 另外,如果你希望发送常规交易或希望在与智能合约的交互中有更多的控制权,请参阅web3j教程:java使用web3j开发以太坊智能合约交易,这里讲到了创建智能合约,与智能合约进行交易,查询智能合约的状态等内容。

  • 构建与部署智能合约 智能合约的构建和部署发生在deploy方法中: YourSmartContract contract = YourSmartContract.deploy( <web3j>, <credentials>, GAS_PRICE, GAS_LIMIT, [<initialValue>,] <param1>, ..., <paramN>

  • 【功能简介】 子链合约定义了用户DAPP所需的子链控制功能和业务逻辑功能。子链控制功能包括: 1.所采用的协议、子链的SCS个数、子链刷新周期、子链每个区块的报酬和每个TX的报酬 2.SCS参与子链的调用过程,以及子链的刷新过程 3.子链的资金控制 子链的业务逻辑定义SCS节点运行的业务流程。这个业务逻辑可以是基于solidity的binary代码,也可以是任意语言的script或者bin代码,只

  • 嗨,我已经编写了一个简单的智能合约,将erc20令牌从用户转移到智能合约,并从智能合约转移到用户。我在调用transferFrom函数之前批准了它,但事务失败。我试过只打电话给approve,而不打电话给transferFrom。它很管用。我正在林克比测试网上测试。 我在测试注入了web3的混音。我得到的错误是 此外,我在 rinkeby 测试网上的测试钱包中有令牌,我正在使用注入的 remix

  • 我的目标是创建一个智能合约,用户可以使用该合约存入erc20并提取erc20代币。我尝试使用token transfer实现此功能,transferfrom函数尝试将令牌发送到合约地址。但它显示了一些错误。我尝试了互联网上所有可能的解决方案,但没有运气。请帮助我######################################## 在此输入图像描述 在此输入图像描述 当我试图转移使用保存

  • 我用块菌测试合同有困难。我安装了最新版本的truffle以及TestRPC。 据我所知,最新版本的truffle附带了一个用于测试SmartContracts的客户端,因此不再需要TestRPC。 我有一个简单的合同,我的迁移是这样的: 当我运行松露开发时,我看到创建了10个测试帐户。 账户: (0)0x627306090abab3a6e1400e9345bc60c78a8bef57 (1) 0x