Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum 使用Web3和Truffle HDWalletProvider在Infura(Kovan Testnet)上部署智能合约_Ethereum_Smartcontracts_Web3 - Fatal编程技术网

Ethereum 使用Web3和Truffle HDWalletProvider在Infura(Kovan Testnet)上部署智能合约

Ethereum 使用Web3和Truffle HDWalletProvider在Infura(Kovan Testnet)上部署智能合约,ethereum,smartcontracts,web3,Ethereum,Smartcontracts,Web3,不管是好是坏,我正在学习2018年末的教程,以帮助我了解如何在Kovan testnet上部署智能合约。我知道版本控制可能是个问题,所以在我展示deploy.js之前,这里是我的package.json: My.env: deploy.js: 编译工作正常,但部署时出现以下错误: UnhandledPromiseRejectionWarning: Error: Insufficient funds. The account you tried to send transaction from d

不管是好是坏,我正在学习2018年末的教程,以帮助我了解如何在Kovan testnet上部署智能合约。我知道版本控制可能是个问题,所以在我展示deploy.js之前,这里是我的package.json:

My.env:

deploy.js:

编译工作正常,但部署时出现以下错误:

UnhandledPromiseRejectionWarning: Error: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 10000000000000000 and got: 0.
    at /Users/richardjarram/code/catonmat/udemy-solidity/solidity_sandbox/node_modules/web3-provider-engine/subproviders/web3.js:15:44
    at XMLHttpRequest.request.onreadystatechange (/Users/richardjarram/code/catonmat/udemy-solidity/solidity_sandbox/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/httpprovider.js:118:13)
我的科万钱包里肯定有1个ETH。有趣的是:当我用以下代码查询我的钱包时,我得到以下输出:

const balance = await web3.eth.getBalance('0x...............actualaccount');
console.log(balance)
// => 1000000000000 etc.
但是,当我从我的助记符短语查询Web3提供者生成的accounts变量时,我得到了一个完全不同的帐户:

const provider = new HDWalletProvider(
  process.env.WALLET_SEED,
  process.env.INFURA_ENDPOINT
);
const web3 = new Web3(provider);

const accounts = await web3.eth.getAccounts();
console.log(accounts)
// [ '0x..............XYZ']
当我检查web3为我构建的账户中的资金时,我确认余额确实为0:

const balance = await web3.eth.getBalance('0x...............XYZ');
console.log(balance)
// => 0
但是,当我将我的实际钱包地址硬编码到部署脚本中时,它会告诉我该帐户不存在

const result = await new web3.eth.Contract(JSON.parse(interface))
 .deploy({ data: bytecode, arguments: ['Hi there!']})
 .send({ gas: '1000000', from: '0x.................actualaccount' });

在您的truffle-config.js中,您定义要使用add'from:'0x…'的网络,确保从您知道有余额的帐户部署合同。

我建议不要将答案用短语表示为问题。这有可能让他们被标记为不是答案。
const provider = new HDWalletProvider(
  process.env.WALLET_SEED,
  process.env.INFURA_ENDPOINT
);
const web3 = new Web3(provider);

const accounts = await web3.eth.getAccounts();
console.log(accounts)
// [ '0x..............XYZ']
const balance = await web3.eth.getBalance('0x...............XYZ');
console.log(balance)
// => 0
const result = await new web3.eth.Contract(JSON.parse(interface))
 .deploy({ data: bytecode, arguments: ['Hi there!']})
 .send({ gas: '1000000', from: '0x.................actualaccount' });
(node:93528) UnhandledPromiseRejectionWarning: Error: Unknown address - unable to sign transaction for this address: "0x.....................actualaddress"
    at /Users/richardjarram/code/catonmat/udemy-solidity/solidity_sandbox/node_modules/web3-provider-engine/subproviders/hooked-wallet.js:185:35
    at /Users/richardjarram/code/catonmat/udemy-solidity/solidity_sandbox/node_modules/web3-provider-engine/subproviders/hooked-wallet.js:207:5