无法使用 Truffle、Infura 和 Node 部署到 Rinkeby

问题描述

我正在尝试使用 Node 和 Truffle 将合约部署到 Rinkeby,但我在下面遇到一个冗长的错误

我尝试了多个不同的 Infura API 密钥,但没有奏效。我正在使用 VPN,但已将其关闭,但也无法解决问题。

截断错误

    Attempting to deploy from account 'MYACCOUNT#'
    [object Object]
    [object Object]

    //... error body is too long to fit

    ^
    RuntimeError: abort([object Object]).Build with - s ASSERTIONS = 1
for more info.
at process.abort(/Users/ntg / Desktop / InBox / node_modules / solc / soljson.js: 1: 13939)
at process.emit(events.js: 314: 20)
at process.emit(/Users/ntg / Desktop / InBox / node_modules / source - map - support / source - map - support.js: 495: 21)
at processpromiseRejections(internal / process / promises.js: 245: 33)
at processticksAndRejections(internal / process / task_queues.js: 94: 32)
at runNextTicks(internal / process / task_queues.js: 62: 3)
at listOnTimeout(internal / timers.js: 520: 9)
at processtimers(internal / timers.js: 494: 7)

Package.JSON

{
  "name": "inBox","version": "1.0.0","description": "","main": "index.js","scripts": {
    "test": "mocha"
  },"author": "","license": "ISC","dependencies": {
    "@truffle/hdwallet-provider": "^1.2.1","ganache-cli": "^6.12.1","mocha": "^8.2.1","solc": "^0.8.0","web3": "^1.3.1"
  }
}

Deploy.js

    const HDWalletProvider = require("@truffle/hdwallet-provider");
    const Web3 = require('web3');
    const {abi,bytecode} = require('./compile');
    
    const provider = new HDWalletProvider(
        'my mnemonic phrase','https://rinkeby.infura.io/v3/myKey'
    );
    
    // instantiate with hdwallet
    const web3 = new Web3(provider);
    
    
    const deploy = async () => {
    
          // get list of all accounts
          const accounts = await web3.eth.getAccounts();
    
          console.log('Attempting to deploy from account',accounts[0]);
    
          const result = await new web3.eth.Contract(abi)
         .deploy({data: '0x' + bytecode,arguments: ['Hi there!']}) 
         .send({from: accounts[0]}); 
    
         console.log('Contract deployed to',result.options.address);
    };


deploy();

编译.js

const path = require('path');
const fs = require('fs');
const solc = require('solc');

const inBoxPath = path.resolve(__dirname,'contracts','inBox.sol');

const source = fs.readFileSync(inBoxPath,'utf-8');

var input = {
    language: 'solidity',sources: {
        'inBox.sol' : {
            content: source
        }
    },settings: {
        outputSelection: {
            '*': {
                '*': [ '*' ]
            }
        }
    }
};


// parses solidity to English and strings 
var output = JSON.parse(solc.compile(JSON.stringify(input)));

var outputContracts = output.contracts['inBox.sol']['InBox']

// spits out ABI interface
exports.abi = outputContracts.abi;

// exports bytecode from smart contract
exports.bytecode = outputContracts.evm.bytecode.object;

合同 - inBox.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

contract InBox {
    string public message;

    constructor (string memory initialMessage) {
        message = initialMessage;
    }

    function setMessage(string memory newMessage) public {
        message = newMessage;
    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)