Solidity

無法獲取智能合約的部署地址

  • September 8, 2021

錯誤:在 PipeConnectWrap.afterConnect 處連接 ECONNREFUSED /home/sanya/.ethereum/geth.ipc

$$ as oncomplete $$(net.js:1106:14) errno: ‘ECONNREFUSED’, 程式碼: ‘ECONNREFUSED’, 系統呼叫: ‘connect’, 地址: ‘/home/sanya/.ethereum/geth.ipc’ } (node:3593) UnhandledPromiseRejectionWarning:錯誤:在 PipeConnectWrap.afterConnect 處連接 ECONNREFUSED /home/sanya/.ethereum/geth.ipc$$ as oncomplete $$(net.js: 1106: 14) (節點:3593)UnhandledPromiseRejectionWarning:未處理的承諾拒絕。此錯誤源於在沒有 catch 塊的情況下拋出非同步函式內部,或拒絕未使用 .catch() 處理的承諾。(拒絕編號:1)

(節點:3593)

$$ DEP0018 $$DeprecationWarning:不推薦使用未處理的承諾拒絕。將來,未處理的 Promise 拒絕將使用非零退出程式碼終止 Node.js 程序。

部署程式碼是 -

const solc = require('solc');

const net = require('net');

let fs = require("fs");

let Web3 = require('web3');

const web3 = new Web3('/home/sanya/.ethereum/geth.ipc', net, {});

let source = fs.readFileSync('../ethereum/node01/contracts/KYC.sol');

console.log(source.toString());

let helloCompiled = solc.compile(source.toString(), 1).contracts[':KYC'];

var password = "apple";

try {
   web3.eth.personal.unlockAccount("0x49f513854af455f45044b12869ebb1dec9db3073", password, 600)

}

catch (e) {

   console.log(e);

   return;
}

let Hello = new web3.eth.Contract(JSON.parse(helloCompiled.interface),

   null, {

   data: '0x' + helloCompiled.bytecode

});

console.log("abi" + helloCompiled.interface)

console.log("abi" + typeof (helloCompiled.interface))

console.log("bin" + helloCompiled.bytecode)

console.log("bin" + typeof (helloCompiled.bytecode))

let helloInstance;

Hello.deploy().send({

   from: '0x49f513854af455f45044b12869ebb1dec9db3073',

   gas: '4700000'

}).then((instance) => {

   console.log("Contract mined at " + instance.options.address);

   helloInstance = instance;


})

   .catch(function (error) {

       console.log(error)

   });

我改變了路徑,它奏效了

locate geth.ipc

/opt/project/ethereum/geth.ipc

您的 geth 實例似乎有問題。確保它具有最新版本的區塊鏈下載它,重新啟動它並讓我們知道您是否仍然有錯誤。如果沒有,我建議您使用 infura 來部署您的合約,因為您不必管理自己的節點。

引用自:https://ethereum.stackexchange.com/questions/77491