我有这样的问题。我是以太坊固态开发的新手,我创建了一个小型智能合约。
这是我的合同。
pragma solidity ^0.4.17;
contract Inbox{
string public message;
function Inbox(string initialMessage) public{
message = initialMessage;
}
function setMessage(string newMessage) public {
message= newMessage;
}
}
使用Nodejs将其部署到以太坊rinkeby测试网络中。我已经将JavaScript文件创建为compile.js和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,'utf8');
module.exports = solc.compile(source,1).contracts[':Inbox'];
这是我的deploy.js文件
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const provider = new HDWalletProvider(
'my newmonic',
'https://rinkeby.infura.io/v3/mykey'
);
const web3 = new Web3(provider);
const deploy = async ()=>{
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account', accounts[0] );
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!']})
.send({ gas: '700000', from: accounts[0]});
console.log('Contract deployed to', result.options.address);
};
deploy();
当我点击节点deploy.js时,它给了我这样的错误。
Attempting to deploy from account #myaccount
(node:15348) UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit.
at Object.callback (C:\Users\tharindusa\Desktop\inbox\node_modules\web3-core-method\src\index.js:334:46)
at sendTxCallback (C:\Users\tharindusa\Desktop\inbox\node_modules\web3-core-method\src\index.js:487:29)
at C:\Users\tharindusa\Desktop\inbox\node_modules\web3-core-requestmanager\src\index.js:147:9
at C:\Users\tharindusa\Desktop\inbox\node_modules\web3-provider-engine\index.js:152:9
at C:\Users\tharindusa\Desktop\inbox\node_modules\async\internal\once.js:12:16
at replenish (C:\Users\tharindusa\Desktop\inbox\node_modules\async\internal\eachOfLimit.js:61:25)
at C:\Users\tharindusa\Desktop\inbox\node_modules\async\internal\eachOfLimit.js:71:9
at eachLimit (C:\Users\tharindusa\Desktop\inbox\node_modules\async\eachLimit.js:43:36)
at C:\Users\tharindusa\Desktop\inbox\node_modules\async\internal\doLimit.js:9:16
at end (C:\Users\tharindusa\Desktop\inbox\node_modules\web3-provider-engine\index.js:127:5)
at C:\Users\tharindusa\Desktop\inbox\node_modules\web3-provider-engine\subproviders\provider.js:20:5
at XMLHttpRequest.request.onreadystatechange (C:\Users\tharindusa\Desktop\inbox\node_modules\truffle-hdwallet-provider\node_modules\web3\lib\web3\httpprovider.js:118:13)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\tharindusa\Desktop\inbox\node_modules\xhr2\lib\xhr2.js:64:18)
at XMLHttpRequest._setReadyState (C:\Users\tharindusa\Desktop\inbox\node_modules\xhr2\lib\xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (C:\Users\tharindusa\Desktop\inbox\node_modules\xhr2\lib\xhr2.js:509:12)
at IncomingMessage.<anonymous> (C:\Users\tharindusa\Desktop\inbox\node_modules\xhr2\lib\xhr2.js:469:24)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:15348) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15348) [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.
我进行了大量搜索以找到解决此问题的方法。但是我找不到适合该问题的解决方案。