Questions tagged [string]

The tag has no usage guidance.

41 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
3answers
1k 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 ...
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
1answer
205 views

Calling a string variable

Update2: Ismael highlighted that upgrading drizzle and Web3 were crucial. I was using drizzle 1.3 and Web3 1.0. So, using the same Solidity code, I can now read a string array into a webpage, using ...
2
votes
0answers
295 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
128 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 ...
2
votes
0answers
598 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?
2
votes
0answers
336 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(...
1
vote
1answer
24 views

How to concatenate an address to a string in solidity

I am trying to find the correct way to concatenate an Ethereum address to a string in Solidity v0.6.7 I tried the following but it did not seem to work : function append(string a, address b) ...
1
vote
0answers
6 views

Check string similarity percentage

How can I efficiently check the similarity of two strings? Or better yet, if I have an array of strings, I want to check that the given string is less than e.g. 80 % similar to any of the other ...
1
vote
2answers
199 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 ...
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 ...
1
vote
0answers
397 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
276 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
0answers
300 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; } ...
1
vote
0answers
162 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 ...
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 . . . ...
0
votes
0answers
6 views

solidity convertion uint256 and address to string

Is there a way to easily convert uint256 and address types to string so that we can get a human readable value?
0
votes
0answers
11 views

Invalid string crashes Remix IDE

If I have an empty function that accepts a string memory input, and if I pass invalid strings like: " "a """ the Remix IDE crashes. Is this just an issue with Remix? If not, ...
0
votes
0answers
12 views

Any known hacks by storing string with non-alphanumeric values?

I was checking out hashmasks smart contracts, and they have the following rules for names: No name can be identical There is a limit of 25 symbols (including spaces) Uniqueness is case insensitive (i....
0
votes
0answers
16 views

Solidity: How to represent bytes32 as string

This may be simple in other languages but I can't figure out how to do it in Solidity. I have a bytes32 like this 0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712. I don't want to ...
0
votes
0answers
25 views

Concatenating strings overwriting a variable

I'm building a SC with many strings and concatenations. Is there any way to overwrite a string and, moreover, not using an auxiliary method? Something like: // SPDX-License-Identifier: MIT pragma ...
0
votes
0answers
33 views

VM error: invalid opcode. invalid opcode The execution might have thrown

I am trying to take in a 512 character long string and extract the first 312 characters from the string. This is my test on a small scale, tryign to extract 12 characters out from a 30 character long ...
0
votes
2answers
16 views

How to ensure that a string parameter to a function is not empty?

Lets say that I have a function which needs two string parameter , function data(string memory _firstname, string memory _lastname) public { buyer[msg.sender] = Buyer(_firstname, _lastname); } Now, I ...
0
votes
2answers
80 views

how to set a require for a string to not be null

I want to write a require condition for string that string variable could not be null. How to write because string is not taking the != operator function createOrder(address _seller, string memory ...
0
votes
0answers
26 views

String to float maintaining decimal places

I've seen some thread already however I haven't found anywhere a way of converting a string number to float number and maintaining the decimals. ie "27.546" to 27.546
0
votes
0answers
11 views

How can I generate hash of string received from function argument

I want to generate hash of string received through function argument. Sha256 require bytes in argument. How can I convert and then save hash in _hash variable. struct ORGANIZATION{ bytes32 hash; ...
0
votes
0answers
18 views

How much is the biggest BytesX type in solidity? (Bytes32?)

I'm trying to keep it simple while returning and array of strings. I want to return a fixed bytesX array with small text. How much is the possible X in the BytesX type? In Remix it seems to be Bytes32....
0
votes
0answers
101 views

join an array of strings and map, filter, reduce functions in solidity

I want to concatenate an array of strings into a single string using solidity, just like the array join function in javascript and python. Also I want to do map/filter/reduce functions in an array. Is ...
0
votes
0answers
23 views

Making sure a string (input/output) is less then 64 characters

I'm working though some basic solidity tutorials using remix. I'm having trouble with the concept that there is no way to edit a string built into the language. In other programing languages I would ...
0
votes
0answers
40 views

Splice an Address

So in javascript I can take a string such as yourString[7] and get the 8th character within that string returned to me in string format. I want to take the last character in an Ethereum address, be an ...
0
votes
0answers
23 views

Compare strings

I want to compare two strings but, by using: require(keccak256(abi.encodePacked(_car))==keccak256(abi.encodePacked(car))); I get the following error: InternalCompilerError: Unknown ...
0
votes
1answer
151 views

Convert a string in scientific notation to a number

my smart contract uses an Oracle to retrieve the price. The price is returned as a string in scientific notation, for example, "3e-8". How I can convert this to number (uint)? The token has ...
0
votes
0answers
28 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
0answers
279 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
58 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
0answers
41 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 ...
0
votes
0answers
58 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
1answer
188 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
0answers
135 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
0answers
417 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: '...
0
votes
2answers
649 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 ...