Javascript SyntaxError:JSON中位置0处的意外标记u(Ropsten Testnet)
我在Ropsten Testnet上部署代码时遇到此错误 SyntaxError:JSON中位于位置0的意外标记u deploy.js:Javascript SyntaxError:JSON中位置0处的意外标记u(Ropsten Testnet),javascript,ethereum,Javascript,Ethereum,我在Ropsten Testnet上部署代码时遇到此错误 SyntaxError:JSON中位于位置0的意外标记u deploy.js: const HDWalletProvider = require("truffle-hdwallet-provider"); const Web3 = require("web3"); const { interface, bytecode } = require("./compile.js"); const provider = new HDWalletP
const HDWalletProvider = require("truffle-hdwallet-provider");
const Web3 = require("web3");
const { interface, bytecode } = require("./compile.js");
const provider = new HDWalletProvider (
"https://ropsten.infura.io/v3/b2e9ef3a616c45f3b8b9a64ed3714848"
);
const web3 = new Web3(provider);
const deploy = async ()=> {
const accounts = await web3.eth.getAccounts();
console.log(accounts);
console.log("Contract is deployed by the manager with address: ", accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data: "0x" + bytecode})
.send({gas: "2000000", from: accounts[0]})
console.log("Contract deployed to address", result.options.address);
}
deploy();
下面是compile.js:
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const helloPath = path.resolve(__dirname, 'contracts', 'Lottery.sol');
const source = fs.readFileSync(helloPath, 'UTF-8');
var input = {
language: 'Solidity',
sources: {
'Lottery.sol' : {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': [ '*' ]
}
}
}
};
module.exports = JSON.parse(solc.compile(JSON.stringify(input)));
我不知道如何解决这个问题
请帮助解决这个问题
谢谢和问候那么
接口的价值是什么?我打赌它是未定义的
我应该向您发送compile.js文件吗?我在我的问题中添加了compile.js,您可以再次看到code中的错误,我希望无论奇怪的代码做什么都会导致接口
被未定义
。我不知道“solc”是什么,所以我不知道solc.compile()
做什么,也不知道它的输出是什么样子。试着自己做一些调试,记录所涉及的各种值实际上是什么样子的。这只是编译lotteryWell的solidity文件的代码。接口
的值是什么?我打赌它是未定义的
我应该向您发送compile.js文件吗?我在我的问题中添加了compile.js,您可以再次看到code中的错误,我希望无论奇怪的代码做什么都会导致接口
被未定义
。我不知道“solc”是什么,所以我不知道solc.compile()
做什么,也不知道它的输出是什么样子。试着自己进行一些调试,记录所涉及的各种值的实际外观。这只是编译彩票的solidity文件的代码