smartcontractkit / truffle-starter-kit

An example smart contract utilizing Chainlink
MIT License
266 stars 99 forks source link

fund-contract.js hangs on attempting to fund contracts #3

Closed PatrickAlphaC closed 4 years ago

PatrickAlphaC commented 4 years ago

Issue

In fund-contract.js when running npx truffle exec scripts/fund-contract.js --network live after successfully migrating(deploying) the default contract MyContract.sol, the contract will hang at const token = await LinkToken.at(tokenAddress); due to what is believed to be metamask changes. See the truffle issue for more information.

Steps to Reproduce

Set up a new Chainlinked project, you can follow the documentation to do this here

mkdir MyChainlinkedProject
cd MyChainlinkedProject/
truffle unbox smartcontractkit/box

Due to the issue with truffle & metamask (mentioned above) you will have to changed one package in package.json:

"@truffle/hdwallet-provider": "^1.0.30", -> "@truffle/hdwallet-provider": "next", then run: npm install

Then proceed to set your RPC_URL to interact with the ropsten chain and your MNEMONIC (seed phrase) from your metamask account.

export RPC_URL=asdfasfas
export MNEMONIC='cat dog frog......'

Run the migration script to deploy 'MyContract.sol'

npm run migrate:live

After it is deployed, just run

npx truffle exec scripts/fund-contract.js --network live

After some testing, the output will hang on the fund-contracts file on this line:

const token = await LinkToken.at(tokenAddress);

I was able to get it past this line by adding some pieces of code and a try catch to see the error:

module.exports = async (callback) => {
  try {
    const mc = await MyContract.deployed();
    const tokenAddress = await mc.getChainlinkToken();
    LinkToken.setProvider(process.env.RPC_URL);
    const token = await LinkToken.at(tokenAddress);
    console.log("Funding contract:", mc.address);
    const tx = await token.transfer(mc.address, payment, {
      from: web3.currentProvider.addresses[0],
    });
    callback(tx.tx);
  } catch (error) {
    callback(error);
  }
};

And the error we get is:

Funding contract: 0x64738dc4359739c402fE1523Ff96308DDa47ea5C
Error: Returned error: The method eth_sendTransaction does not exist/is not available
    at module.exports (/Users/patrick/code/demos/truffle/MyChainlinkedProject/scripts/fund-contract.js:20:28)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Truffle v5.1.32 (core: 5.1.32)
Node v14.5.0

Expected Behavior

The contract that was deployed during npm run migrate:live will be funded

Actual Results

The script hangs and never completes.

Environment

PatrickAlphaC commented 4 years ago

This is fixed in the most recent PR - 96fab0ee47637a77152f402f5ea16bcaf30b5311