简体   繁体   English

Solidity Js,在函数获取时,我得到一个错误,因为“TypeError:数据位置必须是”memory“或”calldata”,用于函数中的返回参数

[英]Solidity Js, on function get i get an error as "TypeError: Data location must be "memory" or "calldata" for return parameter in function

` `

//SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract MyContract{

string value;
constructor() public   {
    value = "MyValue";
}
function get() public returns(string)  {
    return value;
}

function set(string memory _value) public  {
    value = _value;
}


}`

on function get i get an error as TypeError: Data location must be "memory" or "calldata" for return parameter in function, but none was given.在函数 get 我得到一个错误,因为 TypeError: Data location must be "memory" or "calldata" for return parameter in function,但没有给出。 i couldnt solve it because the "value" variable is already identified it doesn neew to be memoried我无法解决它,因为“值”变量已经被识别,它不需要被记忆

string is a reference type, so you need to specify its data location . string是引用类型,所以需要指定它的数据位置 In this case, the value is loaded from storage to memory, and then returned from the memory .在这种情况下,值从存储加载到内存,然后从memory中返回。

function get() public returns(string memory)  {
    return value;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何摆脱这个JS错误:TypeError:$(...)。validate不是一个函数 - How do I get rid of this JS error: TypeError: $(…).validate is not a function 反应为什么我在调用作为参数传递的 function 时收到错误“Uncaught TypeError: createTask is not a function”? - REACT Why do I get the error "Uncaught TypeError: createTask is not a function" when calling a function passed as a parameter? 智能合约:如何在 React 中获得 Solidity function 的回报? - Smart contract: How to get return of Solidity function in React? 为什么收到错误消息:Uncaught TypeError:无法处理绑定“ text:function(){return $ data.tracks.items [0] .id}”…? - Why do I get the error message : Uncaught TypeError: Unable to process binding “text: function (){return $data.tracks.items[0].id }”…? 在 React js 中出现此错误的原因是什么 - TypeError: this.state.data.map is not a function - what's the reason to get this error in React js - TypeError: this.state.data.map is not a function 我收到这个错误! [函数外的'return'语句] - I get this error! [ 'return' statement outside of function ] 为什么我在返回函数中收到此错误? - Why do I get this error in the return function? 为什么会收到TypeError:this.getToken不是函数-React JS - Why do I get a TypeError: this.getToken is not a function - React JS 使用 react.js 时出现此错误:TypeError: field.resolve is not a function - I get this error when using react.js yup: TypeError: field.resolve is not a function 未捕获的TypeError:data.push不是函数。 我怎样才能解决这个推送错误? - Uncaught TypeError: data.push is not a function. How can I get around this push error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM