Solidity error: Unexpected token h in JSON at position
Solidity error: Unexpected token h in JSON at position
嘿,我正在开发一个简单的 solidity 智能合约,但我遇到了一个问题。每次我尝试 运行 setWord 函数时,我都会收到错误 "transact to HelloWorldContract.setWord errored: Error encoding arguments: SyntaxError: Unexpected token h in JSON at position 2" 可能是什么问题?
pragma solidity ^0.4.0;
contract HelloWorldContract{
string word = "Hello World";
address issuer;
function HelloWorldContract(){
issuer = msg.sender;
}
function getWord() constant returns(string) {
return word;
}
function setWord(string newWord) returns(string) {
if(issuer != msg.sender){
return "this is not the creator!";
}
else{
word = newWord;
return "this is the creator!";
}
}
}
您需要在双引号中传递参数字符串 - "helloWorld" 而不仅仅是 helloWorld.
我猜你正在使用 Remix IDE.
不要忘记在您传递的参数周围添加双引号:
嘿,我正在开发一个简单的 solidity 智能合约,但我遇到了一个问题。每次我尝试 运行 setWord 函数时,我都会收到错误 "transact to HelloWorldContract.setWord errored: Error encoding arguments: SyntaxError: Unexpected token h in JSON at position 2" 可能是什么问题?
pragma solidity ^0.4.0;
contract HelloWorldContract{
string word = "Hello World";
address issuer;
function HelloWorldContract(){
issuer = msg.sender;
}
function getWord() constant returns(string) {
return word;
}
function setWord(string newWord) returns(string) {
if(issuer != msg.sender){
return "this is not the creator!";
}
else{
word = newWord;
return "this is the creator!";
}
}
}
您需要在双引号中传递参数字符串 - "helloWorld" 而不仅仅是 helloWorld.
我猜你正在使用 Remix IDE.
不要忘记在您传递的参数周围添加双引号: