religion-counter / onlyone

DeFi future without taxes
78 stars 44 forks source link

TypeError: Cannot read properties of undefined (reading 'address') #13

Open MichaelJacksonCoin opened 2 years ago

MichaelJacksonCoin commented 2 years ago

Hello hope you are good ?

i run npm install

i creat a files .json like this : [{"address":"0x551c1F831533/////55FB6fa3ef86","privateKey":"a7fda8be82590279/////////412a96e8c85"}]

i run node buy-onlyone-pancakeswap.js and get this error : console.log(Buying ONLYONE for ${originalAmountToBuyWith} BNB from pancakeswap for address ${targetAccount.address}); ^ TypeError: Cannot read properties of undefined (reading 'address')

religion-counter commented 2 years ago

Hi Michael, This means that targetAccount is undefined. In the script the file target accounts are specified in a file named: SPECIFY_ACCOUNTS_YOU_WANT_TO_BUY_FOR_HERE.json Is the json file that you made named the same? You can try debugging and see whether the json is parsed correctly.

Web3dGuy commented 2 years ago

so i did the same as "MichaelJacksonCoin", the json array structure is good, and the filename.json has no typos, if i change the file name i get file not found so that shows that its reading the file. but no matter what even if i bring the array into the script, i get this error.

console.log(Buying ONLYONE for ${originalAmountToBuyWith} BNB from pancakeswap for address ${targetAccount.address}); ^

TypeError: Cannot read properties of undefined (reading 'address')

running this script like this :

node script.js

religion-counter commented 2 years ago

Hi @blazedforever , Here is the code that parses the targetAccount:

var targetAccounts = JSON.parse(fs.readFileSync('SPECIFY_ACCOUNTS_YOU_WANT_TO_BUY_FOR_HERE.json', 'utf-8'));

var targetIndex = Number(process.argv.splice(2)[0]);
var targetAccount = targetAccounts[targetIndex];

console.log(`Buying ONLYONE for ${originalAmountToBuyWith} BNB from pancakeswap for address ${targetAccount.address}`);

You are getting the TypeError because targetAccount is undefined. Note Number(process.argv.splice(2)[0]);. With what arguments are you running the script? You need to specify the target index as argument to the script like: node script.js 0