WEB3.JS - 返回错误:处理事务时出现 VM 异常:还原

时间:2021-05-29 18:03:46

标签: javascript solidity web3js

const Web3 = require('web3');
const fs = require('fs')
const web3 = new Web3("ws://localhost:7545");


const contract_address = "0x7484d32e891817702c5d7c764dBF7e592000b415"; 


async function web3Contract() {
    const contract_abi = fs.readFileSync('./build/contracts/Bottle.json', 'utf8')
    const abi = JSON.parse(contract_abi).abi;
    // console.log(abi);
    const Bottle = await new web3.eth.Contract(abi, contract_address);
    const accounts = await web3.eth.getAccounts();
    Bottle.methods.setName("Palm").send({from:accounts[0]});
    const greeting = await Bottle.methods.getGreeting().call();

    console.log(greeting);
}

async function run() {
    try {
        await web3Contract();
    } catch (err) {
        console.log('Your error is this - ' , err);
    } finally {
        console.log('finally');
    }
}

run();
pragma solidity >=0.5.16 <0.9.0;

contract Bottle {
    // setName and getGreeting. — set name is to set the name inside the smart contract 
   //  and store it on the blockchain, and getGreeting should say “Hello Name” where name is what’s stored on the blockchain.
    string newName;

   function setName(string memory _name) public returns(string memory) {
      newName = _name;
      return newName;
   }

    function getGreeting() view public returns(string memory){
        return newName;
    }

}

我收到此错误“错误:返回错误:处理事务时出现 VM 异常:还原”。

我正在使用 truffle 迁移时提供的合约地址。我也在使用 ganache,它显示这些交易正在进行。我也是 console.log(abi) 并且它正确显示了 abi。 不知道如何解决这个问题。

console.log(abi) 值是这个 - https://gyazo.com/73f4668d687a512e63c7fdf195460ea6

ganache 服务器也是这个 https://gyazo.com/f47eeaec32e4fbd25a33d37ba5867620

0 个答案:

没有答案