EVM恢复的智能合约交易

时间:2019-03-30 17:37:07

标签: asynchronous solidity truffle

我知道这个问题可能更适合以太坊堆栈交换,但是那边我没有得到任何回应,我想知道这是否是一个React问题或其他问题。

我正在尝试运行3种异步方法

1:将文件推送到IPFS:


    pushToIPFS = async(e) => {
            return new Promise((resolve, reject) => {
                ipfs.add(this.state.buffer, (err, ipfsHash) => {
                    resolve(ipfsHash[0].hash);
                })
            });
        }

2:写入智能合约和区块链:


    addToBlockchain = async(_ipfsLink) => {

            return new Promise((resolve, reject) => {
                const rand = uniqueRandom(1, 10000000)
                var key = rand()

                let newDate = new Date()
                newDate = newDate.getTime()
                var _account = this.state.account[0]
                var _uid = this.state.uid

                storehash.methods.sendDocument(_ipfsLink, newDate, key, _uid).send({from: _account}) 

                resolve(key)
            })
        }

3:向Firebase数据库添加一个条目:


    createStudent = async(_key) => {
            //get student details from state variables & current user uid
            var _uid = this.state.uid
            var _studentName = this.state.StudentName
            var _studentNumber = this.state.StudentNumber
            var _courseCode = this.state.CourseCode
            var _courseName = this.state.CourseName
            var _idForBlockchain = _key

            // database.ref.students.uid.studentNumber 
            const db = firebase.database()
            db.ref().child("students").child(_uid).child(_studentNumber).set(
                {   studentName: _studentName,
                    courseCode: _courseCode,
                    courseName: _courseName,
                    blockchainKey: _idForBlockchain 
                }
            );

            alert("Student added")

        }

这些通过该函数依次调用:


    AddMyStuff = async (e) => {
            e.preventDefault()
            const ipfsHash = await this.pushToIPFS()
            //await this.createStudent()
            const _key = await this.addToBlockchain(ipfsHash)
            await this.createStudent(_key)
        }

问题在于,已在确认Metamask(智能合约)交易之前将学生添加到数据库中。而且在执行智能合约后,所有正确的详细信息都将写入到区块链中,但控制台中会出现以下错误:

  
    

web3-core-method.umd.js:1191未捕获(已承诺)错误:EVM已还原事务:{“ transactionHash”:     “ 0xe3f411d872bb5f42bd7bd15676647f5056421c5accb5aa6fa22d75eadd09973a”,     “ transactionIndex”:0,“ blockHash”:     “ 0x749ccd76a6888b261b00d8851dca36545fde563fce4c8513407a180d6cac3a00”,     “ blockNumber”:6,“ from”:     “ 0xa5fcbc63d6bcb8e07750cb75073ec3ff7b98c4f5”,“至”:     “ 0xadb13cc1a32b64f938be7c1d3447dfcd20c09ae9”,“ gasUsed”:175983,
    “ cumulativeGasUsed”:175983,“ contractAddress”:空,“ logs”:[],     “ status”:true,“ logsBloom”:     “ 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000     “ v”:“ 0x2d46”,“ r”:     “ 0xa1dfe4e9a4ac8dbbdf49186741cd74bda4fed78b280458ed2cd7f979a3020ccd”,     “ s”:     “ 0x477fa20a2176975f3db9fb1e375fceeedb6ae0e7be35177d4908ad1744dddd1a”}         在SafeSubscriber._next(web3-core-method.umd.js:1191)         在SafeSubscriber .__ tryOrUnsub(Subscriber.js:245)         在SafeSubscriber.next(Subscriber.js:174)         在Subscriber._next(Subscriber.js:99)         在Subscriber.next(Subscriber.js:68)         在TransactionObserver.emitNext(web3-core-method.umd.js:510)         在_callee $(web3-core-method.umd.js:357)         在tryCatch(runtime.js:63)         在Generator.invoke上[作为_invoke](runtime.js:282)         在Generator.prototype。(匿名函数)[下一个](http://localhost:3000/static/js/0.chunk.js:276708:21)         在asyncGeneratorStep(asyncToGenerator.js:3)         在_next(asyncToGenerator.js:25)

  

确实很可怕,有人知道这是什么原因吗?如果这更适合以太坊堆栈交换,再次感到遗憾,但是我没有得到任何答复,我不知道还有什么尝试。预先感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

如果sendDocument是一个承诺,则可以尝试。.

  addToBlockchain = async (_ipfsLink) => {

    const rand = uniqueRandom(1, 10000000)
    var key = rand()

    let newDate = new Date()
    newDate = newDate.getTime()
    var _account = this.state.account[0]
    var _uid = this.state.uid

    await storehash.methods.sendDocument(_ipfsLink, newDate, key, _uid).send({from: _account}) 

    return key
}