Questions tagged [string]

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

Filter by
Sorted by
Tagged with
0 votes
2 answers
85 views

How do i convert Boolean to String in Solidity?

The problem is pretty simple: I want to concatenate boolean values to string values. I order to do this, i assume they have to first be converted into strings and then concatenated. Could someone ...
PupSt4r's user avatar
  • 47
0 votes
1 answer
32 views

Chainlink Functions return an array or list of strings from Functions-request-source.js

Hope someone can help. I am stuck trying to work out how best to extract the different string values from the returned bytes data. Chainlink Function request source requires the return value to be a ...
Vince Reid's user avatar
0 votes
2 answers
24 views

Initializing string variables from mapping values doesnt work

I try something like this: mapping (uint256 =>string) public example; then i initialze 'example' in the constructor example[0]="apple"; example[1]="peach"; then i define a ...
PupSt4r's user avatar
  • 47
1 vote
0 answers
24 views

Serializing SafeTransaction

How do I serialize SafeTransaction into a string and construct it from a string back to the instance with all data and signatures? Using the safe-core-sdk, how does one serialize SafeTransaction (...
user118333's user avatar
0 votes
0 answers
16 views

string storage vs memory

i have a function in my smart contract which needs a string to work, and for this i have two options : OPTION 1 : Store my string in a state variable : contract A { string public immutable ...
noro meb's user avatar
  • 328
1 vote
2 answers
403 views

Operator == not compatible with types string memory and string memory [duplicate]

function hasRole(uint256 tokenId, string memory role) public view returns (bool) { string[] memory userRoles = tokenToRoles[tokenId]; uint256 userRolesLength = userRoles.length; unchecked {...
dd0sxx's user avatar
  • 175
0 votes
1 answer
75 views

Why isn't 'require' working?

In the create function, I need the _title to be required and the _description to be optional. But when calling create without _title & with _description, it executes without any errors, but the ...
Kzhunter's user avatar
  • 103
1 vote
0 answers
64 views

How to handle both String and Bytes return types in Rust

I'm trying to query the MAKER ERC20 contract and get the name and symbol of the token. The problem is that they are stored as a Bytes and I don't want to change the return type of my function from a ...
Mitchs's user avatar
  • 11
0 votes
2 answers
75 views

bytes5 vs string

I have an smart contract with some defined fixed length variables from 3 to 5 characters long. Defining these variables as string is more intuitive for those that come from another languages. Also ...
pellyadolfo's user avatar
0 votes
1 answer
15 views

I get this type error question while writing my solidity Programming

//SPDX-License-Identifier:MIT pragma solidity 0.6.1; contract ExampleMapping1{ mapping(uint => string) names; struct Name{ string yourName; } function MyNames(uint _rNo,...
Akhil Vinayak P's user avatar
1 vote
1 answer
31 views

Transalte Assembly(Solidity)

I want translate code to assembly, but i don't understand , how i can get data from string ( or bytes) Example String: 123 --> uint 123 for (uint256 i = 0; i < bytes(_str).length; i++) { ...
Kilo Arms's user avatar
0 votes
2 answers
37 views

Cannot create 2D-Array string[][] in function

I'm trying to create a 2D string array to serialize my struct, which is: struct Submission { uint256 id; address creator; string title; string IPFS_CID; uint16 likeCount; ...
Saphire's user avatar
  • 111
1 vote
1 answer
376 views

How do I return a string in a pure Yul contract?

I am writing a contract in pure Yul and I want to return a string from a function. Imagine the ABI as: function getString() view returns (string memory); But in Yul, how can I do this?
Jesper - jtk.eth's user avatar
0 votes
1 answer
152 views

What is the difference between string and uint(int) in solidity?

// SPDX-License-Identifier: MIT pragma solidity 0.8.16; contract test7 { function getNum() public pure returns(uint256[4] memory,string memory) { string[4] memory _a = ['1','2','3','4']; ...
imelon2's user avatar
  • 425
1 vote
0 answers
54 views

How come there is "Integer Overflow and Underflow" in string variables in smart contracts?

I was analyzing a contract in Oyente. The contract is : pragma solidity ^0.4.21; contract Test{ address admin; function Test() public{ admin = msg.sender; } string str = &...
MHS's user avatar
  • 11
1 vote
1 answer
233 views

storing ASCII on the blockchain

what is the best way to store ASCII characters/strings on the ethereum blockchain? scenario: there are users that want to upload ONLY ASCII strings to the blockchain. these strings don't contain ...
WhiteRainbowPlz's user avatar
0 votes
1 answer
42 views

Can you concatenate a string url in solidity before sending it to a Chainlink APi? I tried with this but it didn't work

function requestFirstId( string memory _obid) public returns (bytes32 requestId) { Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); obj= _obid; ...
vasquez's user avatar
1 vote
1 answer
56 views

How to compare string and bytes32 in an optimal way?

I have keccak256 string encrypt in blockchain and keccak256(decrypt) bytes in function. This code works well. I pass an unencrypted string to the function and check it for validity. // SPDX-License-...
Alex Baker's user avatar
0 votes
2 answers
339 views

How do you pass in a variable as a string to a constructor in solidity

I'm currently working on an NFT project, using the openzeppelin ERC721 standard for the nfts. When Inheriting the ERC721 NFT contract standard from openzeppelin you're required to pass in the "...
Tame.nation's user avatar
0 votes
1 answer
158 views

Solidity dynamic unicode variable

I previously asked about unicode in Solidity and got some great answers (thanks for that!). Issue is now I'm experimenting with passing in the value of a utf-8 (not a literal): constructor (string ...
aug2uag's user avatar
  • 85
1 vote
0 answers
442 views

Copying strings and bytes from memory to storage via storage references

What's the proper way to copy a string (or bytes) from memory to storage? When copied directly into a state variable lvalue (or into a mapping), there's no problem, but when assigning a string memory ...
Duncan Townsend's user avatar
2 votes
2 answers
404 views

How to add variable into the string in solidity?

I want to add the extractedStr variable into the path? bytes memory extractedStr; string memory combine = '<path d="string(extractedStr)" fill="#FFFFFF"/>';
Hardik Sharma's user avatar
1 vote
1 answer
385 views

Operator += not compatible with types String memory and bytes memory?

How can I add, string(b[i] to number & alpha variable? bytes memory number; bytes memory alpha; function getNumAndAlpha() public pure external returns( bytes n, bytes a){ ...
Hardik Sharma's user avatar
0 votes
1 answer
537 views

How to encode string as bytes array?

A similar question has been asked but using web3 in java, however, I would like to encode a string to bytes[] in solidity itself.
MShakeG's user avatar
  • 1,099
0 votes
1 answer
1k views

How To Convert Hex String to A Uint in Solidity ^8.0.0

I have this function that converts a unit to a hex string: function uintToHexString(uint i) public pure returns (string memory) { if (i == 0) return "0"; uint j = i; uint length; ...
Jim's user avatar
  • 173
0 votes
1 answer
30 views

How many methods do we have to keep String type in Solidity?

How many methods do we have to keep String type in Solidity? Explain the Visibility Quantifiers in Solidity language in detail
Hossein Shahmohammadi's user avatar
0 votes
1 answer
216 views

concatenated string reason message in require() not displaying

I'm using Solidity 0.8.13 and Truffle 5.5.6. I'm just trying to debug a transaction call that fails then reverts when I do truffle migration. I temporarily changed my onlyOwner modifier to make the ...
CodeCalibre's user avatar
2 votes
2 answers
4k views

Convert bytes to hexadecimal string in solidity

In a smart contract I have stored a bytes4 value: 0xa22cb465. I'd like to parse this value as a string: string memory test = "0xa22cb465" I've only stumbled upon explanations on how to ...
Riccardo Perego's user avatar
0 votes
1 answer
34 views

when i call my function metamask telling "this operation is expected to fail"

Hi guys im trying to create question challenge dapp and i have a checkAnswer() function can accessable from frontend. My question struct: struct Question{ string qDesc; uint qPrize;...
Enes Çakır's user avatar
0 votes
1 answer
59 views

bytes and uint concatenation returns \u0004 instead it should show 4 only? What is the problem?

I am trying to concatenate byte and uint in my project. I am using the following logic I found somewhere: bytes data = abi.encodePacked("Gold_",Gold); where Gold contains a uint8 number. ...
Abdullah Hanif Chaudhary's user avatar
1 vote
1 answer
302 views

Solidity - How to split the URL?

I have an ipfs URL stored in a variable named string memory _uri and I am setting it to this in the constructor: "ipfs://QmPsG54TQRaeuqRexDXxd77E916zMugjsqmifH2QTvAmxr/{id}.json" and I want ...
MehmedB's user avatar
  • 233
1 vote
2 answers
61 views

Can strings be passed between contracts

I want to call a function from another contract. Can I pass a string? IUpgrade(upgradeAddress).wrap(label, wrappedOwner, _fuses, resolver); label is a string. I read somewhere that you can't pass ...
nxt3d's user avatar
  • 11
2 votes
1 answer
386 views

Solidity (find a word in a string and replace it)

I am learning solidity string/byte manipulation and I am trying to create a Solidity function that finds specific words in a string/format and replaces them with given variables to return "edited&...
Sky's user avatar
  • 2,144
0 votes
1 answer
409 views

Storing image URLs in Solidity

I have a very basic but functional smart contract which stores an image URL (and some other fields) for front-end use. However, while it works with shortened image URLs, most URLs are too long, ...
quantummidget's user avatar
0 votes
0 answers
124 views

String limitation in Solidity

I am sending some data as a string to a function in Smart Contract but it seems that there is a limitation. I can send this string: 1643934348.9036129,1643934348.9495316?1487.4277,1627.4347?0.1,0.0?...
ZSA's user avatar
  • 11
2 votes
2 answers
102 views

Multidimensional String arrays are not supported - Vyper

Whenever I try to make a list of strings (2D array), I get this error Multidimensional String arrays are not supported. This is the code I tried: names: String[30][100]. Does anyone know how to help? (...
thegamebegins25's user avatar
1 vote
1 answer
917 views

Concatenating values in Solidity

I need to concatenate two strings in Solidity. I'm having problem with below code. I reveive message error: Member "concat" not found or not visible after argument-dependent lookup in type(...
Wojtek's user avatar
  • 13
4 votes
2 answers
2k views

Assign a portion of an array into another array

I want to create a new string array with elements from another array. After that, my randomization will go through this new array. What is the best way to do this? Here's example code piece: // SPDX-...
Chain Left's user avatar
1 vote
0 answers
65 views

Algorithmic complexity of abi.encodePacked

What is the algorithmic complexity of repeated string concatenation via abi.encodePacked? Specifically, if we have m strings s_i for i in [1, m], each of identical length n, is abi.encodePacked(s_1, ...
dbmikus's user avatar
  • 125
0 votes
1 answer
421 views

Store utf-8 in string variable

I know it is possible to store utf-8 text in string variable. but it gives error. contract test1{ string text = "ğğğğ şşşş üüüü"; }
yigitt's user avatar
  • 103
1 vote
0 answers
32 views

(Update Solidity ^0.8.0) How to check string length? [duplicate]

There is a question about this from four years ago. One answer suggests using bytes(str).length, which still works as described, as an estimate that potentially overestimates the number of characters. ...
Chris_77's user avatar
  • 141
1 vote
0 answers
434 views

Escaping HTML special characters in Solidity

I realize I am not supposed to do this, and yet I am curious about the least-bad approach. Will the code below work? It is based on some of Uniswap's code. function escapeHTML(string memory input) ...
Tom's user avatar
  • 133
0 votes
1 answer
2k views

How to split a string in solidity?

I'm using the OpenZeppelin Preset of the 1155 Token Standard. (https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/token/ERC1155/presets) I'm able to mint tokens with that and ...
Matthias Härle's user avatar
0 votes
0 answers
214 views

Encrypt and decrypt a string in solidity

I would like to write a function to encrypt a string by decreasing it's length then it will be possible to reach the original one too ( two way encryption ). I don't care about the security. my ...
Amirali Sahraei's user avatar
1 vote
0 answers
369 views

Why is `abi.encodePacked` preferred to `bytes` in string comparison?

The official documentation recommends to test string equality using keccak256(abi.encodePacked(s1)) == keccak256(abi.encodePacked(s2)) Why is this to be preferred to keccak256(bytes(s1)) == keccak256(...
ldub's user avatar
  • 11
0 votes
0 answers
508 views

Return JSON from view function

I'm trying to find the "best practice" to return a JSON formatted string from a view function. Basically, I plan to loop through a set of data stored in contract state, build it all into a ...
pdmoerman's user avatar
  • 131
1 vote
1 answer
554 views

String compare function works when defined in contract but not in library

I have a very basic string helper library that defines a function to compare two strings like so: library StringLib { function compareTwoStrings(string memory s1, string memory s2) public ...
Olshansky's user avatar
  • 185
0 votes
1 answer
43 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
  • 247
0 votes
0 answers
436 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
805 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

1
2 3 4 5