0

I'm always getting this error without understanding why.

TypeError: Cannot read property 'toTrytes' of undefined

Code:

// Require the use of IOTA library
const Iota = require('@iota/core')

// Create a new instance of the IOTA class object.
// Use 'provider' variable to specify which Full Node to talk to
const iota = Iota.composeAPI({
  provider: 'https://nodes.devnet.iota.org:443'
})

// Call the 'getNodeInfo call to check that the node is working
iota.getNodeInfo()
    .then(info => console.log(info))
    .catch(err => {})

//Actual Transaction
const address =
  'HELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDD'
const seed =
  'PUEOTSEITFEVEWCWBTSIZM9NKRGJEIMXTULBACGFRQK9IMGICLBKW9TTEVSDQMGWKBXPVCBMMCXWMNPDX'
const message = iota.utils.toTrytes('Hello World!')

const transfers = [
  {
    value: 0,
    address: address,
    message: message
  }
]

iota
  .prepareTransfers(seed, transfers)
  .then(trytes => iota.sendTrytes(trytes, 3, 9))
  .then(bundle => {
    console.log(bundle)
  })
  .catch(err => {
    // catch any errors
  })
2
  • Could you also post the stacktrace from the error? Commented Feb 2, 2020 at 8:36
  • I’m voting to close this question because it is about the legacy-network and it is a good idea to keep only Shimmer/ShimmerEVM and latest IOTA Chrysalis questions Commented Apr 24, 2023 at 14:03

2 Answers 2

1

UPDATE 2021

Please be aware that IOTA has changed at architectural level.

Read about it in the official documentation: https://docs.iota.org/

1
  • 1
    no more trytes!
    – Tsangares
    Commented Jun 28, 2021 at 4:16
0

Maybe this will work:

const Converter = require('@iota/converter') const message = Converter.asciiToTrytes('MAYBE LIKE THAT')

Not the answer you're looking for? Browse other questions tagged or ask your own question.