【问题标题】:Node error when I deployed smart contract - Web3.js部署智能合约时出现节点错误 - Web3.js
【发布时间】:2020-01-28 04:42:38
【问题描述】:

我在将智能合约部署到我的私有链时收到此错误。

Error: Node error: {"code":-32000,"message":"unknown account"}

这是我的 web3.js 代码。

 const bytecode = "0x608060405234801561001057600080fd5b506040516020806101018339810180604052602081101561003057600080fd5b8101908080519060200190929190505050806000819055505060aa806100576000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c8063c412eaba146037578063ca6158cb146053575b600080fd5b603d606f565b6040518082815260200191505060405180910390f35b60596078565b6040518082815260200191505060405180910390f35b60008054905090565b6000548156fea165627a7a7230582042b7071573f040950b28decc097069f3f208055692800cf2260019f40904af610029"
    var itemContract = new this.props.web3.eth.Contract([{"constant":true,"inputs":[],"name":"getItem","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"itemId","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"id","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);

itemContract.deploy({
  data: bytecode,
  arguments:[1]
})
.send({
  from: decryptEtherAccount.address,
  gas: 0,
  gasPrice: '0',
}).on('error', (error) => {
    console.log("Error: ", error);
}).on('transactionHash', (transactionHash) => {
    console.log("TxHash: ", transactionHash);
}).on('receipt', (receipt) => {
  console.log("Address: ", receipt.contractAddress)
}).then((newContractInstance) => {
    console.log(newContractInstance);   
}).catch(function(error) {
    console.log(error);
});

请您告诉我为什么会出现此错误?

【问题讨论】:

  • 您可以使用remix.ethereum.org 或 Truffle 进行部署吗?
  • @ZulhilmiZainudin 谢谢!但是,在这种情况下,我想在不使用 truffle 或 remix 的情况下部署合约。
  • 你能console.logdecryptEtherAccount.address看看账号是否正确。为什么将gasgasPrice 设置为0
  • 首先,我认为你需要一些gas来进行合约部署。其次,您是在使用本地区块链(ganache)还是您正在使用的任何东西 - 我认为您没有获得有效/正确的地址,即“来自帐户”。

标签: ethereum solidity web3


【解决方案1】:

在使用地址发送交易之前,请确保您已将其添加到您的 web3 钱包中。

指南:https://web3js.readthedocs.io/en/v1.2.0/web3-eth-accounts.html#wallet-add

【讨论】:

    猜你喜欢
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 2021-10-27
    • 1970-01-01
    • 2018-01-22
    • 2019-06-15
    • 2019-01-24
    相关资源
    最近更新 更多