Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4
votes
1answer
3k 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....
4
votes
1answer
530 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-...
2
votes
2answers
467 views

blockHash compression problem inside a contract, block.blockhash(blockNumber) returns “0x” or random hash value

Related to following answer: function block_hash_validation(uint blockNumber, bytes32 blockHash) constant returns(bool isValid) { return (block.blockhash(blockNumber) == blockHash); } When ...
37
votes
2answers
29k 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.
3
votes
3answers
3k 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
459 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....
13
votes
1answer
9k 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 ...
12
votes
6answers
7k 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....
5
votes
1answer
104 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, ...
3
votes
1answer
466 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":"...
10
votes
2answers
4k 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 ...
8
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 ...
0
votes
1answer
458 views

Saving String with Decimal Number from JSON as Number(Uint) without Losing Decimals

Hey Im trying to use an exchange rate gathered from json as a string to create a uint variable similar to the rate, but I need a way to capture the information after the decimal. For instance I want "...
7
votes
3answers
306 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) {...
29
votes
4answers
27k 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. ...
8
votes
1answer
10k 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 ...
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 ...
5
votes
1answer
1k 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/...
19
votes
4answers
13k 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
1
vote
0answers
126 views

Serpent function to compare strings

I would like to write a simple Serpent function that involves string comparison, but even the simplest example I can think of does not work as I would like. This post gets me part of the way . . . ...
2
votes
0answers
329 views

Constant function returns empty (string)?

I have the following code: web3 var fromAddr = u.addr; var contractAddr = this.addr; var abi = this.abi; var contract = web3.eth.contract(abi).at(contractAddr); console.log(...
6
votes
3answers
4k 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 ...
2
votes
1answer
596 views

Convert (negative) int to string

How do I convert an "int" type value (including negative integers) to a "string" type value in Solidity? I suppose I could convert it into a bytes32, and then convert it to a string, but I feel that ...
7
votes
1answer
6k 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?
19
votes
4answers
21k 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.
5
votes
1answer
1k 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 ...
18
votes
2answers
3k 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-...
21
votes
3answers
13k 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 ...
30
votes
2answers
9k 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.
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 ...
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; /* ...
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?
31
votes
5answers
27k 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?
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 ...
13
votes
2answers
4k 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(...
9
votes
2answers
6k 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 ...
15
votes
1answer
983 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 ...
40
votes
5answers
25k 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 ...
19
votes
2answers
18k 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?

1 2
3