0
votes

For better or worse, I'm following a tutorial from late 2018 to help me understand how to deploy a smart contract on Kovan testnet. I'm aware versioning might be an issue, so before I show the deploy.js here is my package.json:

"dependencies": {
    "ganache-cli": "^6.10.2",
    "mocha": "^4.1.0",
    "solc": "^0.4.25",
    "truffle-hdwallet-provider": "0.0.3",
    "web3": "^1.0.0-beta.26"
  },

My .env:

WALLET_SEED="some 12 word seed phrase"
INFURA_ENDPOINT="https://kovan.infura.io/v3/PROJECT_ID"

The deploy.js:

const dotenv = require("dotenv").config();
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');

const provider = new HDWalletProvider(
  process.env.WALLET_SEED,
  process.env.INFURA_ENDPOINT
);
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: '1000000', from: accounts[0] });

  console.log('Contract deployed to: ', result.options.address);
}

deploy();

The compile works correctly, but when I deploy I get the following error:

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)

I definitely have 1 ETH in my Kovan wallet. The interesting thing is this: When I query my wallet in the following code I get the following output:

const balance = await web3.eth.getBalance('0x...............actualaccount');
console.log(balance)
// => 1000000000000 etc.

But when i query the accounts variable generated by the Web3 provider from my mnemonic phrase I get a completely different account:

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']

When I check the funds in the account that web3 constructs for me, I confirm that the balance is indeed 0:

const balance = await web3.eth.getBalance('0x...............XYZ');
console.log(balance)
// => 0

But when I hard-code my actual wallet address into the deploy script as such, it tells me the account does not exist!

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
1

1 Answers

-1
votes

In your truffle-config.js where you define the networks to use add 'from: '0x...', ensuring that the contract deploys from the account that you know has the balance.