Questions tagged [string]

https://docs.soliditylang.org/en/v0.8.12/types.html

Filter by
Sorted by
Tagged with
0 votes
1 answer
46 views

String to Bytes Converts to Incorrect Value

I have a string array stored in memory as https://cloudflare-ipfs.com/ipfs/QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s This should convert to ...
Nat's user avatar
  • 279
0 votes
0 answers
471 views

Recover account from 64-byte string

In October 2015, I generated an account and backed up two things: the address, and a mysterious 64-byte string. I can see the correct balance on the address, so no problem here. I initially assumed ...
user79476's user avatar
1 vote
1 answer
914 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 ...
chnksi's user avatar
  • 11
3 votes
1 answer
1k 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) ...
user avatar
1 vote
0 answers
19 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 ...
user2340939's user avatar
4 votes
3 answers
6k views

String to Hex in Ethers.js

Only one question: How can I convert string to hex in ethers.js I need some alternative to web3.utils.utf8ToHex() in ethers.
RafayelKh's user avatar
1 vote
2 answers
1k 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 ...
Ashish kumar's user avatar
2 votes
3 answers
3k 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 ...
Prachi's user avatar
  • 21
5 votes
1 answer
1k views

Can I use an emoji as part of a string in Solidity?

Can I use an emoji in Solidity?
Shane Fontaine's user avatar
0 votes
0 answers
261 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
spyrAlex's user avatar
4 votes
1 answer
2k 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 ...
Skellomag's user avatar
4 votes
1 answer
3k views

What is the maximum size of string which we can store on solidity?

Is there a limit to the size of a string that we can store on the Ethereum blockchain?
Vishwas Modanwal's user avatar
2 votes
1 answer
1k 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 ...
Eric Falkenstein's user avatar
0 votes
1 answer
425 views

How do I order strings in Solidity?

I'm a newbie to smart contract development, and I'm looking to order strings using solidity, I don't care that much what kind of ordering method (alphabetical for example) is used, I just want it to ...
Mathias's user avatar
  • 103
2 votes
2 answers
5k views

Solidity Split Comma-Delimited String into Individual words

Since Solidity functions can't accept String Arrays as arguments, I'm trying instead to pass in a long comma-delimited string, and then convert it to an array of strings on the fly. I'm close - but ...
Mark55's user avatar
  • 1,011
0 votes
1 answer
1k views

How to concatenate uint to address in solidity?

I would like to concatenate an Ethereum address to an uint in Solidity. How can I do that?
Haya Raed's user avatar
  • 297
2 votes
1 answer
1k views

TypeError: Type string calldata slice is not implicitly convertible to expected type string memory

I want to slice a string and save it to a memory or storage variable. Is this possible? function test(string calldata _input) external{ string memory something = _input[1:3]; } I am ...
Felix_Maduakor's user avatar
0 votes
0 answers
78 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 ...
T. Thomas's user avatar
  • 111
0 votes
0 answers
145 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 ...
Fifth Dimension Dragon's user avatar
0 votes
0 answers
48 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 ...
martasaparicio's user avatar
0 votes
2 answers
859 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 ...
EtherPaul's user avatar
  • 256
0 votes
0 answers
314 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 ...
Vishnu Prakash's user avatar
0 votes
1 answer
667 views

Explicit type conversion not allowed from "string memory" to "uint256"

I'm using an oracle to get results from a custom api. The result is in string by default. I want to convert it to uint256, so that I can perform basic arithmetic functions. Here's my code: function ...
Vishnu Prakash's user avatar
1 vote
1 answer
131 views

In Solidity, Is there any situation, when string is necessary?

In Solidity, Is there any situation, when string is necessary? Please can u explain when I should use string instead of bytes or bytesN? Thanks!
xxs's user avatar
  • 31
1 vote
1 answer
1k 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; ...
Fariha Abbasi's user avatar
1 vote
0 answers
416 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 ...
Pm Rivière's user avatar
1 vote
1 answer
242 views

Read and write private variable from child contract

I have a contract MyContract is ERC721. MyContract needs to concatenate a string with an existing token URI using this function: string(abi.encodePacked(_tokenURIs[_tokenId], _URI)); Problem is all ...
Pm Rivière's user avatar
1 vote
1 answer
49 views

How to save long textual data on blockchain? [closed]

I need to write blogs and save them on blockchain. What are efficient possibilities to store such data on blockchain? Thanks for reading the question, already appreciate your time.
Fariha Abbasi's user avatar
1 vote
1 answer
309 views

Where does the length parameter end and the actual string start in an abi encoded string?

Assuming I decided to ABI encode a very long string (for the purpose of this question I just picked an arbitrary 5-paragraph lorem ipsum text generate by https://www.lipsum.com/feed/html) and get out ...
user avatar
0 votes
1 answer
659 views

Why does declaring returns type bytes memory give a compiler error?

If we have the following code: pragma solidity >= 0.5; contract stringsContract { function takesTwo(string memory str, uint idx) public pure returns (bytes memory) { bytes memory ...
adriaanbd's user avatar
  • 103
1 vote
1 answer
286 views

Garbage in string parameters of events

I have an event defined like this: event Created( address indexed target, string indexed name ); I do emit Created(..., _name); // called function with _name = "comment" which gives ...
Aaron Digulla's user avatar
1 vote
1 answer
1k views

Bytes memory as a function parameter increase gas cost

I've a smartcontract compiled with pragma solidity ^0.4.0; version and one function receives a bytes parameters which contain a long string. In these version it doesnt need to set the parameters as "...
mastervv's user avatar
  • 113
0 votes
1 answer
537 views

Solidity. Concatenate and hash two strings

Hi all I need tho sha256 two strings. I am new to solidity. This is what I've got: function addressToString(address _addr) public pure returns(string memory) { bytes32 value = bytes32(uint256(...
Alejandro Veintimilla's user avatar
0 votes
1 answer
74 views

Solidity. Concatenate hash w address. TypeError: Operator + not compatible with types string memory and address payable

I am trying to do something simple: examsFinalHash = keccak256(examHash + msg.sender); but I get the following error: TypeError: Operator + not compatible with types string memory and address ...
Alejandro Veintimilla's user avatar
0 votes
1 answer
2k views

What's the proper way to store a long string (like a news article) in Solidity?

I'm working on Layer 2 so gas/efficiency aren't primary concerns, assuming the function can be executed by the EVM
Michael C's user avatar
  • 463
0 votes
1 answer
170 views

Storing a monero address in smart contracts?

Assuming I would have to store Monero addresses or any cryptonote based coins addresses in a smart contract, would there be any issues? Consider that those addresses are as long as this random ...
Iulian's user avatar
  • 640
1 vote
1 answer
476 views

How to verify the sha256 result of integer 5 in the Zokrates tutorial?

The Zokrates tutorial here starts with calculating the SHA256 hash of (the number) 5. The hex representation of the result is shown at the bottom here: However, I could not reproduce this on my ...
Ytsen de Boer's user avatar
0 votes
1 answer
709 views

library modifying string vs string literal

I have a library which has the following function: function strConcat( string memory _a, string memory _b ) internal pure returns (string memory) My contract implements the library ...
Radek_pl's user avatar
  • 791
1 vote
2 answers
688 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 ...
Lou Treaser's user avatar
0 votes
1 answer
53 views

Can I use string(or any type) list as an argument of an event?

It`s my event. event Transfer(address sender, address receiver, string[] denoms, uint256[] amounts); And I view an Transfer event with watch() function, It`s the result. { address: "...
user55524's user avatar
3 votes
1 answer
2k views

Solidity: How to replace specific string position with letter?

I would like to replace a letter at a specific position of a string with another letter. function _stringReplace(string memory _string, uint256 _pos, string memory _letter) internal pure returns (...
Senju's user avatar
  • 701
1 vote
1 answer
417 views

Assert.equals() weird behavior does not recognize (apparently) equal strings

I'm facing problems related to string comparison using Assert.equals() provided by remix_tests.sol. I made a toy contract and a related test to show what the problem is: https://gist.github.com/...
Bruno Arruda's user avatar
3 votes
1 answer
2k views

Convert address to string after solidity 0.5.x

After solidity 0.5.x release none of conversions from address to string appear to be working. I've tested all of them on remix and got errors like converting bytes to uint or something like this. ...
Radek_pl's user avatar
  • 791
0 votes
1 answer
188 views

Expected ')' but got identifier if(string name != users[name]){ ^--^

pragma solidity >=0.4.0 <0.7.0; contract NewHello{ mapping(address => string) public users; // contains a name for every address function updateUser(string memory name) public { ...
Furkan Demirel's user avatar
1 vote
1 answer
534 views

Error encoding arguments: SyntaxError: Unexpected token e in JSON at position 2 while string concatenation

I am just adding 2 strings into one string but getting below error: transact to TestStrings.testCOntract errored: Error encoding arguments: SyntaxError: Unexpected token e in JSON at position 2 ...
Dharmesh Kheni's user avatar
0 votes
0 answers
73 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 ...
CryptoGrounds's user avatar
9 votes
3 answers
10k 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[]...
ak07_'s user avatar
  • 153
9 votes
2 answers
10k 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); } //...
Khalid168's user avatar
1 vote
0 answers
27 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 ...
Thibaut Dumont's user avatar
0 votes
1 answer
4k views

A solidity 0.5.x function to convert adress-string to ethereum address

I'm looking for a Solidity 0.5.x compatible function to convert a string with and address like "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe" into a real address. I did use this function: function ...
Stef Heyenrath's user avatar