Questions tagged [string]

The tag has no usage guidance.

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

Passing a hash value to function

I'm trying to authenticate users by comparing the hashes created by backend server and contract. Seems like "byte32" values cannot be coerced into strings. So, instead I'm converting it into ...
0
votes
1answer
20 views

Explicit type conversion not allowed from “string memory” to “uint256”

I'm using an oracle to get results from a custom api. The result is in string by default. I want to convert it to uint256, so that I can perform basic arithmetic functions. Here's my code: function ...
1
vote
1answer
46 views

In Solidity, Is there any situation, when string is necessary?

In Solidity, Is there any situation, when string is necessary? Please can u explain when I should use string instead of bytes or bytesN? Thanks!
0
votes
0answers
16 views

How can I return string array in solidity?

This is my struct: struct Token { address tokenAddress; uint256 minAmount; bool emergencyUnlock; TokenStatus status; string name; uint256 decimal; string thumbnailUrl; } ...
0
votes
0answers
22 views

Gas-efficient string concatenation

My use-case requires that I feed my contract with a long string (Base64 data), which requires to split it and send it over several transactions so as to not reach gas limit. Then the contract rebuilds ...
0
votes
1answer
14 views

Read and write private variable from child contract

I have a contract MyContract is ERC721. MyContract needs to concatenate a string with an existing token URI using this function: string(abi.encodePacked(_tokenURIs[_tokenId], _URI)); Problem is all ...
1
vote
1answer
24 views

How to save long textual data on blockchain? [closed]

I need to write blogs and save them on blockchain. What are efficient possibilities to store such data on blockchain? Thanks for reading the question, already appreciate your time.
0
votes
1answer
21 views

Where does the length parameter end and the actual string start in an abi encoded string?

Assuming I decided to ABI encode a very long string (for the purpose of this question I just picked an arbitrary 5-paragraph lorem ipsum text generate by https://www.lipsum.com/feed/html) and get out ...
0
votes
0answers
22 views

How to convert an address in string with correct case (upper or lower) of each symbol in Solidity? [duplicate]

Is there any recommended way to convert an address into string? Also it will be great if there is possible to safe the characters cases
0
votes
1answer
27 views

Why does declaring returns type bytes memory give a compiler error?

If we have the following code: pragma solidity >= 0.5; contract stringsContract { function takesTwo(string memory str, uint idx) public pure returns (bytes memory) { bytes memory ...
1
vote
1answer
28 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
43 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
100 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
25 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
52 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
24 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
58 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
39 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
81 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
32 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
57 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
71 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/...
3
votes
1answer
444 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
57 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
159 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
33 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
2k 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[]...
5
votes
2answers
1k 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
23 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
1answer
735 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 ...
3
votes
1answer
187 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
548 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
425 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
407 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
71 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
745 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
50 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
434 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
111 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
202 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
198 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
431 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
264 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
108 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 ...
1
vote
1answer
251 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
5k 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
792 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
96 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
173 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
491 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, ...