yuyasugano / pancake-bakery-arbitrage

A sample application invokes a flashswap in PancakeSwap and a monitoring tool in Node.js.
305 stars 194 forks source link

After following the tutorial UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'address' of undefined #5

Closed wenpanfeng closed 3 years ago

wenpanfeng commented 3 years ago

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'address' of undefined image

yuyasugano commented 3 years ago

@wenpanfeng Hi I guessed that you hadn't deployed a flash swap contract yet?? If you deployed a contract in a network then json file must have abi & networks with id in it. Please reopen this issue if needed. Thanks.

    const Flashswap = require('./build/contracts/Flashswap.json');
    const flashswap = new web3.eth.Contract(
        Flashswap.abi,
        Flashswap.networks[networkId].address
    );
bart commented 2 years ago

Encountered the same issue. truffle migrate --network mainnet deploys contracts in two steps (1_initial_migration.js and 2_deploy_contracts.js) and generates corresponding JSON files. Flashswap.json includes data in networks property but Swapcontract doesn't. Investigated it and figured out that only Flashswap is part of migration two. So Swapcontract doesn't get migrated. That's why it doesn't have any network information. Just for ya information if anyone is facing the same issue one day. Btw, thanks @yuyasugano for the great post and example!

yuyasugano commented 2 years ago

@bart Please confirm the revised code and let me know if it works. I did some online research and updated the contract and the script. Swapcontract is just a testing purpose and excluded it from migration target now.

bart commented 2 years ago

Sorry @yuyasugano I'm not working on that anymore.