Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [string]

The tag has no usage guidance.

0
votes
1answer
24 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
30 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 ...
1
vote
1answer
82 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
28 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 ...
0
votes
2answers
91 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
42 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
58 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
60 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
226 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
148 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
62 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
60 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[...
0
votes
1answer
1k 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) { ...
0
votes
1answer
119 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
44 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
127 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
191 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
159 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
236 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
109 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 ...
1
vote
1answer
112 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 (...
0
votes
0answers
23 views

Using of Fixed-size bytes arrays for saving gas

Solidity docs says It is possible to use an array of bytes as byte[], but it is wasting a lot of space, 31 bytes every element, to be exact, when passing in calls. It is better to use bytes. ...
2
votes
1answer
126 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
0answers
95 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
49 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
512 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
64 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;...
0
votes
2answers
591 views

How to store hash of an Excel file in Blockchain? [closed]

I'm sorry if this question does not seem to be logic. I want to store hash of an Excel file in Blockchain by following function : //byte fileHash; event LogsetFileHash(byte _hashValue); ...
0
votes
0answers
16 views

How to use an event to store a buffer (payload)? [duplicate]

I want to store the following payload using an event instead of storing by string (since using string in smart contract is expensive). How can I do this by an event ? My payload is as follows : {"...
1
vote
1answer
114 views

Alternative for String type in smart contract and Solidity?

Regarding the fact using String in contract is expensive, is there any alternative type in Solidity ? The input value (Payload) I want to set is as follows : {"SQN":4,"Node_ID":"...
0
votes
1answer
130 views

Read String as bytes (Oraclize callback)

I have an Oraclize call that returns the following (a string): "00000000000000000000000000000000000000000000000000000000000003e8" Now this is 1000 (bytes32 hex) You can check here: https://www....
1
vote
1answer
30 views

(Solidity) Is using 'string' safe?

Maybe stupid question, but just want to be sure before deploying contract on main net. In my contract user can change his name(:string) to whatever he likes. Is it totally safe? I mean, is here some ...
0
votes
0answers
45 views

Adding Strings to string arrays as a form of signature

Okay so I am trying to build a contract for SCM and Logistics. I want a contract that creates an order and inside of that order you can create documents. Each document has its own struct, the idea is ...
0
votes
1answer
38 views

What's the best way of searching in a mapping of objects? [duplicate]

I need a mapping of objects like this: mapping (string => person) as clients; struct person{ string name; uint score; } let's say i have 3 persons on my table: john doe marcus ...
1
vote
2answers
959 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 ...
0
votes
0answers
202 views

Send request failed { code: -32602, message: 'invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash' }

I am new to ethereum and deploying my first contract with simple method getting following error: [2018-03-24 11:08:14.364] [ERROR] ipcProviderBackend - Send request failed { code: -32602, message: '...
1
vote
0answers
22 views

Is there a ERC or existing EIP standard or a lib for String to Bytes32 and Bytes16 conversion?

Is there a ERC or existing EIP standard or a lib for String to Bytes32 and Bytes16 conversion ?
1
vote
0answers
183 views

String returned from mapping of struct array

I want to store some details from every transaction. These are the struct and the variable: struct MoneyTransfer{ address sender; string comment; uint creationTime; uint quantity; } ...
0
votes
1answer
187 views

How long can a string be until it spills into the next word?

string is dynamic length storage. I imagine a string of length (bytes length) 1, 2 or 3 is all the same length on storage, probably one word. Which byte causes it to spill over into a second, third ...
0
votes
1answer
205 views

Issues with converting UINT to STRING - strange character [duplicate]

I am trying to use the uintToString method to convert a uint to string but I keep getting a weird square character in front of the resulting string. How do I remove this character, or better yet how ...
3
votes
1answer
1k 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"...
1
vote
1answer
136 views

string-float convertation to uint

Hi guys, i need help! Trying to make a func that converts string-presented float with 2 dec to uint * 00 etc. if _s = "970452.22" result must be "97045222" but i do something wrong (when i try to ...
0
votes
1answer
169 views

How to take a string with variable length decimal places, and convert it to a whole number uint?

I'm experimenting with writing an ethereum-usd price ticker taking data from the coinmarketcap API using Oraclize's API. I noticed that Oraclize has a function called parseInt that can be used to ...
1
vote
0answers
109 views

Convert an hexadecimal string to bytes in pure Solidity

I am using Oraclize to recover a signature from a website. When I have it, I have to check if the address who signed it is correct. To do that, I would use ECRecovery from Zeppelin. The signature ...
2
votes
1answer
235 views

Any way to convert the characters that make up bytes into a string?

For example if I have a bytes4 variable that is "0xabcd1122" is there any way to turn this into a string with a value of "abcd1122"? I am asking because I want to assign a unique identifier to a token ...
1
vote
1answer
2k views

How to store strings in an array in solidity?

I am trying to build a simple application on ethereum where strings can be added/deleted from an array and the contents of this array can be shown in a frontend UI. The basic structure of the smart ...
0
votes
1answer
710 views

string memory[3] memory is not implicitly convertible to expected type bytes32[] storage ref

I have the following (array of bytes32 types): bytes32[] public allTokenSymbols = ["0x4554480000000000000000000000000000000000000000000000000000000000", "...
2
votes
1answer
291 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
514 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
639 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:...