current position:Home>The send transactions' from 'field must be defined appears when calling the contract method (including parameters)!

The send transactions' from 'field must be defined appears when calling the contract method (including parameters)!

2022-02-03 22:59:15 Q & A of Denglian community

For the first time vue build Dapp project , The intention is to submit the form , Store data in blockchain through smart contract method ,

The form data structure is :

struct  CarInfo{        string  name;        string  description;        uint  reward;        uint  waitTime;        uint  longitude;        uint  latitude;    }

The corresponding method of smart contract is :

function addCarInfo(string memory _name,string memory _description,uint _reward,  uint _waitTime,uint _longitude,uint _latitude) public {        // Add data to the list         // This place should add         CarInfo memory carInfo = CarInfo(_name,_description,_reward,_waitTime,_longitude,_latitude);  //  Specify the values in the order they are defined         CarInfos[msg.sender].push(carInfo);        emit NewCarInfo();    }

vue The relevant code of is :

<template>  <div style="text-align: left">    <el-button class="add-button" type="success" @click="dialogFormVisible = true"> A new task </el-button>    <el-dialog      title=" A new task "      :visible.sync="dialogFormVisible"      @close="clear">      <el-form v-model="form" style="text-align: left" ref="dataForm">        <el-form-item label=" Task name " :label-width="formLabelWidth" prop="name">          <el-input v-model="form.name" autocomplete="off" placeholder=""></el-input>        </el-form-item>        <el-form-item label=" Task description " :label-width="formLabelWidth" prop="description">          <el-input v-model="form.description" autocomplete="off"></el-input>        </el-form-item>        <el-form-item label=" Mission rewards " :label-width="formLabelWidth" prop="reward">          <el-input-number v-model="form.reward" :min="1" :max="50" ></el-input-number>  wei        </el-form-item>        <el-form-item label=" Can wait time " :label-width="formLabelWidth" prop="waitTime">          <el-input-number v-model="form.reward" :min="1" :max="360" ></el-input-number>   minute         </el-form-item>        <el-form-item label=" longitude " :label-width="formLabelWidth" prop="longitude">          <el-input v-model="form.longitude" autocomplete="off" placeholder=""></el-input>        </el-form-item>        <el-form-item label=" latitude " :label-width="formLabelWidth" prop="latitude">          <el-input v-model="form.latitude" autocomplete="off"></el-input>        </el-form-item>      </el-form>      <div slot="footer" class="dialog-footer">        <el-button @click="dialogFormVisible = false"> take   eliminate </el-button>        <el-button type="primary" @click="onSubmit"> indeed   set </el-button>      </div>    </el-dialog>  </div></template><script>  import Web3 from "web3";  import contract from "truffle-contract";  let CarContract = require("../../build/contracts/CarContract.json");  export default {    name: 'VehicleBC',    data () {      return {        dialogFormVisible: false,        form: {          name: '',          description: '',          reward: '',          waitTime: '',          longitude: '',          latitude: '',        },        formLabelWidth: '120px',      }    },    methods: {      clear () {        this.form = {          name: '',          description: '',          reward: '',          waitTime: '',          longitude: '',          latitude: '',        }      },      onSubmit () {        this.carTask.addCarInfo(this.form.name,this.form.description,this.form.reward,this.form.waitTime,this.form.longitude,this.form.latitude).then(function (result) {            alert(result);        })      },      async initWeb3Account() {        if (window.ethereum) {          this.provider = window.ethereum;          try {            await window.ethereum.enable();          } catch (error) {              console.log("User denied account access");          }        } else if (window.web3) {          this.provider = window.web3.currentProvider;        } else {          this.provider = new Web3.providers.HttpProvider("http://127.0.0.1:7545");        }        this.web3 = new Web3(this.provider);        this.web3.eth.getAccounts().then(accs  => {          this.account = accs[0]        })      },      async initContract() {        const crowdContract = contract(CarContract)        crowdContract.setProvider(this.provider)        this.carTask = await crowdContract.deployed()      },      async getCarTaskInfo() {        this.carTask.getCarInfoLen(this.account).then(function (len) {          console.log(len + "  Notes ");        })      },    },    mounted() {    },    //  At present Vue Callback when the component is created hook  function     async created() {      //   initialization  web3 And account number       await this.initWeb3Account()      //   Initialize contract instance       await this.initContract()      //   Get the status information of the contract       await this.getCarTaskInfo()    },  }</script><style scoped>  .add-button {    margin: 18px 0 0 10px;  }</style>

Pop up form for creating a new task in the project , After filling in and submitting, there appears The send transactions "from" field must be defined! error . The whole project imitates tiny Bear How to use Vue.js Develop Ethereum DApp To learn . May I ask if there is a great God who can give you some advice ?




Take the answer 1:

addCarInfo Call to specify the signature address :

this.carTask.addCarInfo(... , {from: this.account})




copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032259125138.html

Random recommended