Closed wenpanfeng closed 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
);
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!
@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.
Sorry @yuyasugano I'm not working on that anymore.
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'address' of undefined