Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
14 views

Garbage in string parameters of events

I have an event defined like this: event Created( address indexed target, string indexed name ); I do emit Created(..., _name); // called function with _name = "comment" which gives ...
1
vote
1answer
21 views

Bytes memory as a function parameter increase gas cost

I've a smartcontract compiled with pragma solidity ^0.4.0; version and one function receives a bytes parameters which contain a long string. In these version it doesnt need to set the parameters as "...
0
votes
1answer
29 views

Solidity. Concatenate and hash two strings

Hi all I need tho sha256 two strings. I am new to solidity. This is what I've got: function addressToString(address _addr) public pure returns(string memory) { bytes32 value = bytes32(uint256(...
0
votes
1answer
19 views

Solidity. Concatenate hash w address. TypeError: Operator + not compatible with types string memory and address payable

I am trying to do something simple: examsFinalHash = keccak256(examHash + msg.sender); but I get the following error: TypeError: Operator + not compatible with types string memory and address ...
0
votes
1answer
34 views

What's the proper way to store a long string (like a news article) in Solidity?

I'm working on Layer 2 so gas/efficiency aren't primary concerns, assuming the function can be executed by the EVM
0
votes
1answer
18 views

Storing a monero address in smart contracts?

Assuming I would have to store Monero addresses or any cryptonote based coins addresses in a smart contract, would there be any issues? Consider that those addresses are as long as this random ...
1
vote
1answer
21 views

How to verify the sha256 result of integer 5 in the Zokrates tutorial?

The Zokrates tutorial here starts with calculating the SHA256 hash of (the number) 5. The hex representation of the result is shown at the bottom here: However, I could not reproduce this on my ...
0
votes
1answer
35 views

library modifying string vs string literal

I have a library which has the following function: function strConcat( string memory _a, string memory _b ) internal pure returns (string memory) My contract implements the library ...
1
vote
2answers
43 views

How to convert string to bytes256 or arbitrary bytes?

I already know how to convert bytes32ToString and stringToBytes32: function bytes32ToString(bytes32 x) public pure returns (string memory) { bytes memory ...
0
votes
1answer
28 views

Can I use string(or any type) list as an argument of an event?

It`s my event. event Transfer(address sender, address receiver, string[] denoms, uint256[] amounts); And I view an Transfer event with watch() function, It`s the result. { address: "...
2
votes
1answer
29 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
42 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
89 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
41 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
69 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
27 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 ...
3
votes
2answers
888 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[]...
4
votes
2answers
713 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
22 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
11 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
502 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
110 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
262 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
314 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
271 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
53 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
484 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
40 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
342 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
85 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
156 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
132 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
348 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
246 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
85 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
176 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[...
1
vote
3answers
4k 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) { ...
1
vote
1answer
503 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
80 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
165 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
374 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
295 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
333 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
165 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 ...
2
votes
1answer
287 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
163 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
195 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
102 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
894 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
90 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;...