Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
46
votes
5answers
37k views

How to concatenate strings in solidity?

I'm trying to concatenate two strings in solidity. I tried with + or . but neither option works. There is not much documentation on string concatenation yet. Is it even possible? If not, can I ...
43
votes
2answers
36k views

Use string type or bytes32?

What are the benefits to using string datatypes over bytes32 to represent text data. It seems my contract runs into an out of gas exception when I switch the data structures from bytes32 to string.
39
votes
8answers
35k views

How to convert a bytes32 to string

How can I convert a bytes32 to a string? Does anyone has a magic function or library which does it?
36
votes
4answers
36k views

How to convert a string to bytes32?

How can I convert a string to a bytes32? Does anyone has a magic function or library which does it? For example: This works since as input I gave 32-bits. But it won't work with "> 32-bit" chars. ...
30
votes
2answers
10k views

Why do Solidity examples use bytes32 type instead of string?

In many Solidity examples I read that use strings for parameters or return values, I see they are typed as bytes32 although there's a string type. What is the real reason for that? Thanks.
26
votes
3answers
17k views

operator == not compatible with type string storage ref and literal_string

can someone help out with the stated error, i am trying to run a code to check the status of a String variable. while compiling using the online solidity compiler i am getting two errors on ...
22
votes
4answers
19k views

Convert address to string

In Solidity, how can I convert the sender address to a string? The comments in How to convert an address to bytes in Solidity? did not provide a working solution
20
votes
5answers
27k views

Conversion of uint to string

I am trying to convert uint to string in solidity. Is it possible to convert? if so how can I convert it? Convertion to base 10 is prefered, but in hexadecimal might also be helpful.
20
votes
2answers
24k views

How can I return multiple strings from a contract function?

In solidity it's obvious how to get a single string returned from a function. But, I'd like to have the smart contract return multiple string values. Is there a way to do this?
19
votes
2answers
4k views

What is the zero value for a string?

How to verify that a string, or an enum with only string properties, is initialised or not, inside of a mapping? According to the docs, it means checking that the element of the mapping is at its 0-...
18
votes
2answers
5k views

Contract reading a string returned by another contract

I have 2 contracts, Parents and Child which has a public string variable - name. contract Child { string public name; function child (string _name){ name = _name; } } Parents ...
18
votes
1answer
2k views

The Unicorn Mystery - Solidity fails to decode valid UTF-8 encoded bytes

The Ethereum Foundation has the Unicorn token to encourage donations, and the unicorn emoji is represented by three bytes. How in the world did they do that? I know that Solidity supports unicode ...
16
votes
1answer
11k views

How can you check if a `string` is empty in Solidity [duplicate]

How can you check if a type string is empty in Solidity? For instance this would work when testing if a string was initialized to have no characters: string public emptyStringTest = ''; or when you ...
15
votes
1answer
1k views

Struct not being stored in mapping when it contains more than two 'string' properties. Bug?

I am playing around with Solidity, and have encountered an extremely bemusing issue. I want to have a mapping of Address instances (postal addresses NOT the address type) Address is a custom defined ...
14
votes
6answers
10k views

How to convert string to int

How do i convert a string into a int? here is my code: pragma solidity ^0.4.6; contract MyContract { string public a; /* Constructor */ function MyContract() { a = "0....
13
votes
2answers
6k views

Convert with JS a Solidity bytes32 to a Solidity string

I have functions which are forced to return a bytes32 object, but then in my webapp I need to reconvert them to a classic string. How can I do that?
13
votes
2answers
5k views

Is it impossible to use an array of strings as the argument to solidity function?

If I try to define a function using an array of strings as an argument, solc gives me the following error: Error: Internal type is not allowed for public or external functions. function test(...
11
votes
2answers
7k views

Solidity concatenate uint into a string?

How would I concatenate an integer into a string using solidity? For instance, say I have the following: uint myInteger = 12 How can I create the following string "My integer is: 12" with 12 being ...
10
votes
3answers
11k views

Is it possible to check string variable's length inside the contract?

I want to sent a string as an argument to a function. But some user may enter maybe 100 size string or even larger. [Q] Inside the function is it possible to check the size of the string and return ...
10
votes
1answer
12k views

How to get string from hex on Smart Contracts results [duplicate]

On a Smart Contract called "mem" there is a function called "get()" that returns a bytes32 that is supposed to be a string. How can I decode the string? The result is an hex value. I have tried ...
10
votes
1answer
4k views

Error when using string type as a mapping key

The following code doesn't compile, because compiler needs a mapping key to be of fixed-size type in order to create accessor for a public mapping. I'm using here string type. My strings are 24 byte ...
9
votes
1answer
8k views

How many letters can bytes32 keep?

I would like to add strings into bytes32. What is the maximum number of letters bytes32 can have?
9
votes
2answers
7k views

How to concatenate a bytes32[] array to a string?

I am passing an array of bytes32 to my function. This array can contain numbers or hashes etc. to identify an object. In a new use case I want to pass a URL to this function by splitting the URL into ...
8
votes
2answers
3k views

Clarification of “256 bit word” semantics

EVM has "256bit words". Some cases treat strings shorter than 32 bytes (256 bits) as left-justified ascii (packed into the most significant bytes of the word). Does this mean that the word value of ...
7
votes
3answers
321 views

What is used for default string value in mapping?

For example, I have a contract like this: contract example { mapping (uint => string) map; function example () { map[123] = "123"; } function return1 () returns (string) {...
7
votes
2answers
4k views

Solidity: Initialize struct containing string array

I do not seem to be able to initialize a struct containing a string array. This is what I tried: contract testStruct { struct stru{ string[] s; } stru myStru; /* ...
6
votes
3answers
6k views

Indexed Event with string not getting logged

I am facing a strange issue in my solidity smart contract using events. I created the event in 2 ways as below:- 1. event Event1(string assetName, address toAdd); 2. event Event1(string indexed ...
6
votes
1answer
2k views

How to store and load an IPFS hash as bytes32 in contract written in Solidity [duplicate]

An IPFS hash can be expressed in hexadecimal which is 34 bytes long. Afaik it is most efficient to store fixed length values in a Ethereum contract, thus a maximum of 32 bytes (bytes32). Because the ...
5
votes
3answers
5k 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
3k 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); } //...
5
votes
1answer
2k views

How to join strings with numbers in Solidity

I'd like to format url with number parameters as following: http://someurl.com/?param1=100&param2=200 The problem is, it's always truncated after first number parameter e.g: http://someurl.com/...
5
votes
1answer
4k views

Solidity function that accepts mapping as input

Is it possible for Solidity to accept mappings as input parameter in a function? I've been trying to create a function with a second parameter mapping (string => string) aMapping, pragma solidity ^0....
5
votes
1answer
112 views

What does string mean in patricia tree wiki

What does string mean in patricia tree wiki specifically here Merkle Patricia trees provide a cryptographically authenticated data structure that can be used to store all (key, value) bindings, ...
5
votes
1answer
2k views

How do you get a string value from msg.data in the fallback function?

Im trying to do what The DAO did and do something when a sender sent money to my contract address. But im not sure how to. The something I want to do is to just create a new user in a mapping with the ...
5
votes
2answers
2k views

Array of Strings in Solidity

I am storing addresses on the blockchain for IPFS objects, and the addresses are more than 32 bytes. I was using bytes32 for testing but I have truncation. I am seeking a method to read data from the ...
4
votes
3answers
8k 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) { ...
4
votes
1answer
5k views

Ethereum Address string size

Question: How many (or up to how many) characters does a Ethereum address have? Elaborating: I have been looking online for an answer but it seemed harder to find than I expected. I am working on ...
4
votes
2answers
2k views

Solidity return string not hex?

Currently I'm using ether.camp to create a contract. At this stage it simply gets and stores some values. However when I try and get the values they are in bytes/hex even though the return type is ...
4
votes
1answer
7k views

How to convert a string to bytes32 array?

I have known how to convert a string to bytes32. But if the string length is longer than 32, the rest of the string will be truncated. So how to convert a string to bytes32[] array?
4
votes
1answer
541 views

How do I execute a transaction with string parameters using JSON-RPC

My contract has a method with this signature: register(byte32 documentHash, string owner, string url) I read this documents (https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#function-...
3
votes
2answers
5k 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 ...
3
votes
2answers
3k views

How to put a variable inside a string in solidity

Does anyone know how to do this, I want to put a variable inside a string: currently using: oraclizeID = oraclize_query("URL","json(https://opensky-network.org/api/states/all?icao24=a4dad4).states[...
3
votes
1answer
478 views

Inside `geth` how could I convert abi object into a string?

Inside geth how could I convert abi object into a string? I want to convert it into string to apply str.replace(/[\r\n]/g, ''); to remove new lines and make it more compact. myContractCompiled.Array....
3
votes
1answer
389 views

How to copy a string field from one contract to another?

I want one contract to be able to copy fields from another. contract Klendathu { string public bugs; function Klendathu(string _bugs) public { bugs = _bugs; } } contract RogerYoung { ...
3
votes
2answers
504 views

Convertion from bytes 8,16,32 to String

I know it has been asked a lot of times but the newest post about this I could find was about 1 year old. To me it seems quite possible that things have changed since then. So my question: Is there an ...
3
votes
1answer
715 views

Return string (64 chars) to another contract in solidity

I have two contracts : contract Child { mapping(string => string) private strings; function GetString(string key) public constant returns(string value) { return strings[key]; ...
3
votes
3answers
4k views

Keccak256(parameter) How to pass a string to be hashed?

I'm trying to do something that in theory is very simple: I want to pass a string like "hello" to a function and then compute the sha3/keccak256 hash. I think the problem is that if the parameter is a ...
3
votes
1answer
512 views

How to explain string serialization when invoking contract method?

On Ropsten testnet I have deployed a contract like this: // creation of contract object var aContract = web3.eth.contract([{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"...
3
votes
1answer
219 views

In solidity, how to copy a string or pass it by value?

In this example I only modify string a, but both a and b are changed. It seems like the string wasn't copied. I only want to change a. How do you copy a string and how do you pass a string by value to ...
3
votes
1answer
4k views

Solidity convert hex string to bytes

I try to convert hex string to bytes. function MyContract() public { string memory str = "A76A95918C39eE40d4a43CFAF19C35050E32E271"; array1 = bytes(str); bytes memory str1 = hex"...