Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
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 { ...
1
vote
3answers
896 views

Compare last 2 digits of block hash

I am having trouble doing some string comparison against the last 2 digits of a block hash in solidity. I'm also a little bit confused about how to work with a single character, as it appears that a ...
3
votes
1answer
819 views

Simplest way to use a variable in an Oraclize query?

I have a variable number in my Solidity contract which changes and I need to incorporate this into an oraclize query. My oraclize query looks like the following: oraclize_query(60, "URL", "json(https:...
0
votes
1answer
3k views

Build a hash from a string and a number uint256 on Solidity

A Smart Contract needs to check the uniqueness of a number inside a serie. The serie is specified by a string, and the number by a uint256 type. Is there any easy way on Solidity to compute a hash ...
2
votes
2answers
1k views

What is best what to store a string's compressed version on a smart-contract?

Storing string is expensive on smart-contracts and charge us expensive fees even if we want to store them in Events. Instead I want to store each string's decoded version in a smart-contract in order ...
0
votes
2answers
641 views

Events with string argument not working (not indexed)

I am trying to listen to an event on rinkeby test which I run locally. Every thing works fine when my argument is int such as event EventTester(int values); When I change the event argument to string ...
2
votes
0answers
591 views

Can I store data in an ERC20 token?

Can i store data, e.g. a string inside a token? If so, this data will follow the token around if I transfer it to someones wallet?
0
votes
2answers
2k views

Declare string inside function

I tried to declare string inside my function but it doesn't work. How to declare string inside function?
3
votes
2answers
2k 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
2answers
497 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 ...
0
votes
1answer
632 views

Solidity string slice error

I am using a string utility library for Solidity with the aim of splitting a string on a specific delimiter. I followed the instructions from the library: var s = someString.toSlice(); var foo = s....
1
vote
1answer
97 views

How to download array of strings

EOS requires token holders to generate public keys and register them, by using their "register" function in their smart contract. Here's the function (copied from Etherscan): mapping (address => ...
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 ...
1
vote
1answer
50 views

Dealing with mapping(string => string[])

I have a contract with different categories. We can assume them to be the following here: Cities Countries Counties Suppose I want to add a new city to the category cities. I'm assuming this has to ...
0
votes
2answers
632 views

Why is string getter returning an empty response?

This is a sequence of another question I asked. I have the following contract contract User { string publicKey; function setPublicKey(string _publicKey) onlyOwner { ...
-1
votes
2answers
322 views

Solidity return type string showing inaccessible

Smart contract pragma solidity ^0.4.11; contract PassData{ PassData passData; string s; function PassData(){ s="come"; } function getData() returns(string){ ...
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 ...
2
votes
2answers
295 views

Wrong order when calling a function to return a string

I have an array of strings in my Contract.sol: string[] messages; function getMessage(uint i) constant returns (string) { require(messages.length > i); return messages[i]; } In my app....
3
votes
1answer
2k views

How to return string over 32 characters from bytes32[] array?

I have a bytes32[] array. I convert strings to bytes32 before they are added to the array as follows: function stringToBytes32(string memory source) returns (bytes32 result) { assembly { ...
2
votes
1answer
246 views

Parsing contract endpoint output

A contract endpoint on Ropsten returns a set like this: (uint256 _assetId, address _assetOwner, address _issuer, string _content, uint256 _sellPrice, uint256 _status) The endpoint is getAssetById at ...
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 ...
3
votes
1answer
2k views

Is there a limit on no of the parameters that can be passed to a function? [duplicate]

I have created a smart contract function in ethereum. I am unable to use more than four parameters to the function. If a I create a function with more than 4 parameters and call the it by passing ...
3
votes
0answers
229 views

Checking if an address is encoded on the end of a bytes array

I have a bytes array. Within the last 20 bytes, there is an address stored. I am trying to compare the address at the end of this array to the address of a msg.sender, and am wondering if there is a ...
2
votes
2answers
677 views

Using strings as indices in Solidity

Can I use strings as identifiers in a Solidity mapping? I want something like this: contract C { mapping(string => mapping(address => uint)) public balances; string[] public tokennames;...
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 ...
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 ...
1
vote
1answer
421 views

How to build an address book for Ethereum addresses?

I would like a simple address book referencing a user name to an ethereum address like, mapping (string => address) addressOf; Unfortunately I can't access that mapping as a public call, as ...
1
vote
1answer
731 views

Empty string value returned when returns variable is not named in declaration

I'm trying to implement a simple "pop" function in solidity, and I am getting very different behaviour with string values depending on whether or not I name the returns value in the function ...
4
votes
1answer
6k 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?
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]; ...
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....
4
votes
1answer
539 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
549 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 ...
43
votes
2answers
35k 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
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
472 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....
15
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 ...
13
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....
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, ...
3
votes
1answer
508 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":"...
11
votes
2answers
6k 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
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
472 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
320 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) {...
36
votes
4answers
35k 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. ...
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 ...
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
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/...
21
votes
4answers
18k 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
128 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 . . . ...