【发布时间】:2020-07-29 16:16:32
【问题描述】:
我正在尝试向 Ganache 部署一个简单的合约,如下所示:
const fs = require('fs');
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8545');
const bytecode = fs.readFileSync('./build/FirstContract.bin');
const abi = JSON.parse(fs.readFileSync('./build/FirstContract.abi'));
(async function () {
const ganacheAccounts = await web3.eth.getAccounts();
const myWalletAddress = ganacheAccounts[0];
const myContract = new web3.eth.Contract(abi);
myContract.deploy({
data: bytecode
}).send({
from: myWalletAddress,
gas: 5000000
}).then((deployment) => {
console.log('FirstContract was successfully deployed!');
console.log('FirstContract can be interfaced with at this address:');
console.log(deployment.options.address);
}).catch((err) => {
console.error(err);
});
})();
编译.sol文件没有任何错误后,我尝试使用“node deploy.js”部署代码,最终得到以下错误:
(node:25233) UnhandledPromiseRejectionWarning: TypeError: this._deployData.startsWith is not a function
at Object._encodeMethodABI (/opt/bak/eth/node_modules/web3-eth-contract/src/index.js:539:30)
at Object._processExecuteArguments (/opt/bak/eth/node_modules/web3-eth-contract/src/index.js:858:39)
at Object._executeMethod (/opt/bak/eth/node_modules/web3-eth-contract/src/index.js:883:54)
at /opt/bak/eth/deploy.js:19:6
....
(node:25233) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
提前感谢您的帮助。
s1b
【问题讨论】:
标签: javascript solidity smartcontracts