0

我在@degr8sid 帖子中尝试了如下代码:

const Mam = require('./lib/mam.client.js');
const IOTA = require('iota.lib.js');
const moment = require('moment');
const iota = new IOTA({ provider: 'https://nodes.devnet.iota.org'});
const { asciiToTrytes, trytesToAscii } = require('@iota/converter')
const mode = 'restricted'
const secretKey = 'VERYSECRETKEY'
const provider = 'https://nodes.devnet.iota.org'

const mamExplorerLink = `https://mam-explorer.firebaseapp.com/?provider=${encodeURIComponent(provider)}&mode=${mode}&key=${secretKey.padEnd(81, '9')}&root=`

let numberofSteps;
let kilometersWalked;

// Initialise MAM State
let mamState = Mam.init(provider)

// Set channel mode
mamState = Mam.changeMode(mamState, mode, secretKey)

// Publish data to the tangle
const publish = async packet => {
        // Create MAM Payload - STRING OF TRYTES
        const trytes = asciiToTrytes(JSON.stringify(packet))
        const message = Mam.create(mamState, trytes)
         // Save new mamState
        mamState = message.state
         // Attach the payload
        await Mam.attach(message.payload, message.address)    
        console.log('Published', packet, '\n');
        console.log (message.root);
        return message.root
    }

const publishAll = async () => {
    const root = await publish({
        numberofSteps: Math.floor((Math.random()*89)+10),
        kilometersWalked: (numberofSteps/1312.335),
        message: 'Message from Alice',
        timestamp: (new Date()).toLocaleString()
      })

      await publish({
        numberofSteps: Math.floor((Math.random()*89)+10),
        kilometersWalked: Math.floor(990/9),
        message: 'Message from Alice',
        timestamp: (new Date()).toLocaleString()
      })

      await publish({
        numberofSteps: Math.floor((Math.random()*89)+10),
        kilometersWalked: Math.floor(990/9),
        message: 'Message from Alice',
        timestamp: (new Date()).toLocaleString()
      })

      return root
}

publishAll()

我收到此异常:无法附加消息,TypeError:无法读取未定义的属性(读取'sendTransfer'),TypeError:无法读取未定义的属性(读取'sendTransfer'),位于_callee5$(/home/pi/New /lib/mam.client.js:23390:46).... 之后,我得到了正确的数据

有人会帮我吗?非常感谢!

4

0 回答 0