'Got Error when submitting an array of striing arrays in a function in Solidity
Got this error message in Remix IDE : transact to Countriesy.storeABatchOfCountries errored: Error encoding arguments: SyntaxError: JSON.parse: unexpected character at line 1 column 39 of the JSON data
My Function is supposed to take an array of 10 array of 6 string and store them inside the countriesMap mapping.
Here is the function code :
//Function to store a batch of a maximum 10 countries in the Contract at the same time...
function storeABatchOfCountries(string[6][10] calldata countriesData)
external
isOwner
{
uint8 _countryCounter;
for (uint256 i = 0; i < countriesData.length; i++) {
countriesMap[countriesData[i][5]] = Country(
countriesData[i][0],
countriesData[i][1],
countriesData[i][2],
countriesData[i][3],
countriesData[i][4],
countriesData[i][5],
true
);
_countryCounter++;
}
numberOfCountries = _countryCounter;
}
And Here is the data I'm submitting to it:
[
["+376", "Europe", "Andorra", "Euro", unicode"🇦🇩", "AD"],
["+971", "Asia", "United Arab Emirates", "Dirham", unicode"🇦🇪", "AE"],
["+93", "Asia", "Afghanistan", "Afghani", unicode"🇦🇫", "AF"],
[
"+1268",
"North America",
"Antigua and Barbuda",
"Dollar",
unicode"🇦🇬",
"AG"
],
["+1264", "North America", "Anguilla", "Dollar", unicode"🇦🇮", "AI"],
["+355", "Europe", "Albania", "Lek", unicode"🇦🇱", "AL"],
["+374", "Asia", "Armenia", "Dram", unicode"🇦🇲", "AM"],
[
"+599",
"North America",
"Netherlands Antilles",
"Guilder",
unicode"🇧🇶",
"AN"
],
["+244", "Africa", "Angola", "Kwanza", unicode"🇦🇴", "AO"],
["+672", "Antarctica", "Antarctica", "", unicode"🇦🇶", "AQ"]
]
Solution 1:[1]
Remove unicode keyword from list items like unicode"??". Json parser can't encode unicode word. It works only inside solidity code.
As an example consider following contract:
contract Flags {
string public flag = unicode"??";
function setFlag(string memory _flag) public {
flag = _flag;
}
}
and following test case in brownie:
from brownie import accounts, Flags
def test_unicode_string_setup():
contract = Flags.deploy({'from': accounts[0]})
assert contract.flag() == "??"
# no unicode keyword
contract.setFlag("??", {'from': accounts[0]})
assert contract.flag() == "??"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kj-crypto |
