Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
14 views

Solidity: How to replace specific string position with letter?

I would like to replace a letter at a specific position of a string with another letter. function _stringReplace(string memory _string, uint256 _pos, string memory _letter) internal pure returns (...
1
vote
1answer
21 views

Assert.equals() weird behavior does not recognize (apparently) equal strings

I'm facing problems related to string comparison using Assert.equals() provided by remix_tests.sol. I made a toy contract and a related test to show what the problem is: https://gist.github.com/...
2
votes
1answer
43 views

Convert address to string after solidity 0.5.x

After solidity 0.5.x release none of conversions from address to string appear to be working. I've tested all of them on remix and got errors like converting bytes to uint or something like this. ...
0
votes
1answer
30 views

Expected ')' but got identifier if(string name != users[name]){ ^--^

pragma solidity >=0.4.0 <0.7.0; contract NewHello{ mapping(address => string) public users; // contains a name for every address function updateUser(string memory name) public { ...
1
vote
1answer
35 views

Error encoding arguments: SyntaxError: Unexpected token e in JSON at position 2 while string concatenation

I am just adding 2 strings into one string but getting below error: transact to TestStrings.testCOntract errored: Error encoding arguments: SyntaxError: Unexpected token e in JSON at position 2 ...
0
votes
0answers
24 views

Why does return address(player) return a weird string?

I am trying to get the player's address through front end and when I run through the solidity function that should return the player's address, it would return ...
1
vote
2answers
388 views

How can I return dynamic string array in Solidity?

How can I return a dynamic string array? I came across serialization and deserialization. How can I serialize and deserialize dynamic string array ? pragma solidity ^0.5.0; contract Abc{ string[]...
3
votes
2answers
400 views

Solidity! Invalid implicit conversion from string memory to bytes memory requested

pragma solidity ^0.5 contract ProofOfExistence { // ... some code here function proofFor(string memory document) public view returns(bytes32) { return sha256(document); } //...
1
vote
0answers
21 views

What's the best way to send many strings in only one call?

So I have to write on-chain about 15 string key-value pairs in one call. Of course, I took the naive approach first by putting all those strings as arguments of my contract, but then I run onto the 16 ...
0
votes
0answers
10 views

My ethereum based dapp throwing error :Unable to get UserError: ERROR: The returned value is not a convertible string:

I have setup a private ethereum network on an AWS ubuntu instance. The application has been deployed using truffle and uses metamask to approve transactions. There are two different pages one for ...
0
votes
1answer
359 views

A solidity 0.5.x function to convert adress-string to ethereum address

I'm looking for a Solidity 0.5.x compatible function to convert a string with and address like "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe" into a real address. I did use this function: function ...
2
votes
1answer
84 views

Where is string stored in solidity storage?

I'm trying to check where is stored a string in storage in Solidity. For testing this I'm using this code: pragma solidity 0.5.4; contract AssemblyString { string s; // slot 0 function set(...
0
votes
1answer
165 views

converting uint256 to string

Any idea for the simplest way to add "degrees" variable into the string like below? Looking for getString to return "today is 40 degrees outside". pragma solidity ^0.5.3; uint public ...
0
votes
1answer
235 views

keccak256 string comparison failure

When trying to compare a string from storage to a string being passed into a function (memory), I am getting the following error when attempting to convert the memory string using keccak256(). What am ...
0
votes
1answer
164 views

How to convert plain text string variable to bytes32 variable? And how to store bytes32 in one variable after converting? [duplicate]

pragma solidity ^0.4.25; contract Purchase { address public sellerAddress; constructor (address _sellerAddress) { sellerAddress = _sellerAddress; } } contract Buyer is Purchase {...
1
vote
2answers
40 views

How to store a function return in a variable?

I want to create a dynamic JSONpath in an Oraclize query. For that I wrote a function that concentrates three strings (_a = "json(http...",_b = some variable ,_c = ")].Number") to one. Calling the ...
3
votes
3answers
328 views

How to handle dynamic size string array in solidity?

I have a shop owner and a shop owner can have multiple products. I want to keep the products id in an array. Also, A public method can return all the product id list of a shop owner. I tried the ...
0
votes
0answers
37 views

How strings are stored in Solidity on a low level?

So, the question is in the title, let me describe scenario: I make raw rpc call via method eth_call to contract Token to a function name to get token name of type string. Below is my original ...
1
vote
2answers
292 views

How to concat a double quote into a string in Solidity

I am looking for a solution to concat double quotes ("") into a string in Solidity. What I need looks like this: '{"id":idHere,"Lname":lname,"Fname":fname}' All I get is sth like '{\"id\":idHere,\"...
1
vote
1answer
77 views

Parsing the WolframAlpha string result from the Oracalize __callback function into a usable format?

I need to generate 10 unique random numbers between 0 to 100 in my smart contract. For this I've decided to utilise Oracalize and one of the datasource called WolframAlpha. This is how I use it: ...
0
votes
1answer
136 views

Adding quotation marks to string before calling a function [closed]

Alright, so I'm not sure if I should be asking this here or HTML/JavaScript forums, so please do let me know if I am in the wrong place. I believe it belongs here as you all understand dApps and ...
1
vote
1answer
111 views

Enum in Solidity VS CONST

Can we convert Enum Value to string in Solidity? Which is more efficient to use in terms of GAS, ENums or CONST ?
2
votes
1answer
326 views

Make character count, count emoji's as 2

I have the following function: function getCharacterCount(string str) constant returns (uint length) { uint i=0; bytes memory string_rep = bytes(str); while (i<string_rep.length) {...
2
votes
0answers
229 views

Comparing solidity sha3 with web3 sha3 inside smart-contract

The problem is that sha3 in solidity returns bytes32 and I have a string returned from IPFS by oraclize, and if hash calculated in solidity and returned to web3js (bytes32 got interpreted as a string) ...
2
votes
0answers
80 views

What is a cheap way to store mnemonic generator list of 1024 words in smart contract?

What is the cheapest way to store a list of 1024 words for a mnemonic generator, and why? These ideas had a gas cost of 165720 GAS for a string array, and 42300 GAS for storing all the words in a ...
0
votes
1answer
128 views

Parse string into multiple variables

I'm doing oraclize calls on the json rpc of a chain to get this function: function getTransfer(uint _transferId) public view returns(uint,address,uint){ Details memory _locked = transferDetails[...
0
votes
3answers
3k views

Where can I find a string to bytes32 converter online?

So far I am using this solidity code pragma solidity 0.4.24; contract Converter{ function Converter(){ } function stringToBytes32(string memory source) returns (bytes32 result) { ...
0
votes
1answer
382 views

Solidity: extracting (slicing) characters from a string

Perhaps a double, but I couldn't find an answer here, and neither in strings library. I have a string public string = "ABCDEFG" I need to put together a function that iterates through the characters ...
0
votes
1answer
73 views

Why doesn't remix allow inputs of letters in this code?

Okay, so this code is actually designed to revert when anything but 0, 1, ...9, is entered, but let me explain. I created this code for general practice. It may not have practical use, but it's ...
0
votes
1answer
162 views

Empty string in mapping(address => string[])

I have a mapping(address => string[]). How can I check if, given an address and a position of the array string[] corresponding at that address, it exists a value in that position or not? Thank ...
0
votes
1answer
321 views

Solidity: substitute for returns (strings[])

I have a mapping mapping (address => string[]) myMap; How can I return the list of all the strings associated to a given address? I know that in Solidity one can't return an array of strings, ...
1
vote
1answer
264 views

web3.toAscii for foreign languages

I have a function that takes bytes32 _name as a parameter and store it in a struct. Let's say _name is either Chinese, Korean, or Japanese and from app.js I would convert the _name to hex to pass it ...
1
vote
0answers
320 views

When is it appropriate to use “bytes” (or bytes1 - bytes32) in Solidity?

Upon reviewing prior questions and answers, I understand that "bytes" should be used for raw byte data of arbitrary length and "string" for UTF-8 data of arbitrary length. I also understand that if I ...
1
vote
0answers
147 views

Why string is expensive?

Sometimes we need to use string instead of byte32 only because of one byte (or one character) and this increases the gas and the cost of transaction. For example, I want to store the assets state of ...
1
vote
1answer
248 views

String validation solidity: alpha numeric and length

What is best practice in solidity for testing that an input string contains only alpha numeric characters and is not longer then x amount of chars? function testStr(string str) constant returns (...
2
votes
1answer
156 views

What is the most efficient way to parse a string of integers to an array?

I perform an Oraclize query on an XML file, and receive this string in return: ["31", "25", "24"] What would be the most efficient way to parse through this string and store the numbers into a uint8 ...
1
vote
1answer
176 views

Vyper and strings

How can I manipulate strings in Vyper? In solidity I could use Nick Johnson's string library. He's using assembly to do that. But that's not possible with Vyper as far as I know.
0
votes
0answers
91 views

Dynamically-sized byte array is value type?

In the doc, it says bytes: Dynamically-sized byte array, see Arrays. Not a value-type! string: Dynamically-sized UTF-8-encoded string, see Arrays. Not a value-type! Not a value-type! If ...
0
votes
2answers
781 views

How to convert/decode Solidity bytes32 to Python string via web3.py

Inside a Solidity contract, I have this variable: zBytes32 = "HelloBytes32"; after Python web3.py retrieving that variable, zbytes32 = contractInstance.functions.getzBytes32().call() print(...
0
votes
1answer
85 views

How to handle structs within solidity any

What's the possible workaround for passing an array of strings (not supported by solidity at current time). I am using an array of struct that is state variable to a contract. pragma solidity ^0.4.23;...
0
votes
2answers
1k views

How to store hash of an Excel file in Blockchain? [closed]

I'm sorry if this question does not seem to be logic. I want to store hash of an Excel file in Blockchain by following function : //byte fileHash; event LogsetFileHash(byte _hashValue); ...
1
vote
1answer
165 views

Alternative for String type in smart contract and Solidity?

Regarding the fact using String in contract is expensive, is there any alternative type in Solidity ? The input value (Payload) I want to set is as follows : {"SQN":4,"Node_ID":"...
0
votes
1answer
229 views

Read String as bytes (Oraclize callback)

I have an Oraclize call that returns the following (a string): "00000000000000000000000000000000000000000000000000000000000003e8" Now this is 1000 (bytes32 hex) You can check here: https://www....
1
vote
1answer
45 views

(Solidity) Is using 'string' safe?

Maybe stupid question, but just want to be sure before deploying contract on main net. In my contract user can change his name(:string) to whatever he likes. Is it totally safe? I mean, is here some ...
0
votes
1answer
59 views

What's the best way of searching in a mapping of objects? [duplicate]

I need a mapping of objects like this: mapping (string => person) as clients; struct person{ string name; uint score; } let's say i have 3 persons on my table: john doe marcus ...
1
vote
2answers
2k views

Does Solidity support passing an array of strings to a contract's constructor yet?

I am going through a tutorial from 2017 that says it was updated in January of 2018. It says that currently you can not pass an array of strings directly to the constructor of a contract and that you ...
0
votes
0answers
259 views

Send request failed { code: -32602, message: 'invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash' }

I am new to ethereum and deploying my first contract with simple method getting following error: [2018-03-24 11:08:14.364] [ERROR] ipcProviderBackend - Send request failed { code: -32602, message: '...
1
vote
0answers
245 views

String returned from mapping of struct array

I want to store some details from every transaction. These are the struct and the variable: struct MoneyTransfer{ address sender; string comment; uint creationTime; uint quantity; } ...
0
votes
1answer
268 views

How long can a string be until it spills into the next word?

string is dynamic length storage. I imagine a string of length (bytes length) 1, 2 or 3 is all the same length on storage, probably one word. Which byte causes it to spill over into a second, third ...
0
votes
1answer
334 views

Issues with converting UINT to STRING - strange character [duplicate]

I am trying to use the uintToString method to convert a uint to string but I keep getting a weird square character in front of the resulting string. How do I remove this character, or better yet how ...