Dynamic array in Solidity
I a very new to Ethereum and Solidity development.
I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array.
I search a lot but not able to find this simple stuff.
Thanks in advance
ethereum solidity
add a comment |
I a very new to Ethereum and Solidity development.
I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array.
I search a lot but not able to find this simple stuff.
Thanks in advance
ethereum solidity
add a comment |
I a very new to Ethereum and Solidity development.
I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array.
I search a lot but not able to find this simple stuff.
Thanks in advance
ethereum solidity
I a very new to Ethereum and Solidity development.
I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array.
I search a lot but not able to find this simple stuff.
Thanks in advance
ethereum solidity
ethereum solidity
edited Dec 31 '18 at 10:07
saman.shahmohamadi
374218
374218
asked Dec 31 '18 at 9:42
Jay VyasJay Vyas
1,60131638
1,60131638
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Here is my solution, you need experimental ABIEncoderV2
to return array of strings.
pragma solidity ^0.5.2;
pragma experimental ABIEncoderV2;
contract Test {
string array;
function push(string calldata _text) external {
array.push(_text);
}
function get() external view returns(string memory) {
return array;
}
}
Can I test it before deploy ?
– Jay Vyas
Dec 31 '18 at 10:04
sure, go to remix.ethereum.org, inRun
tab choose EnvironmentJavaScript VM
and deploy for testing
– Egor
Dec 31 '18 at 10:08
Wow, amazing solution Accepted Thanks
– Jay Vyas
Dec 31 '18 at 10:10
Also when you will push string in array in Remix IDE, make sure that you have quotes like"yourString"
– Egor
Dec 31 '18 at 10:12
Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract
– Jay Vyas
Dec 31 '18 at 10:46
|
show 1 more comment
If, finally, you want to interact with your smart contract with tools like web3j
(for java) or web3js
(javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.
In this case you should serialize your output array. Same applies if you have an input array.
such a good point
– Egor
Dec 31 '18 at 10:20
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985923%2fdynamic-array-in-solidity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is my solution, you need experimental ABIEncoderV2
to return array of strings.
pragma solidity ^0.5.2;
pragma experimental ABIEncoderV2;
contract Test {
string array;
function push(string calldata _text) external {
array.push(_text);
}
function get() external view returns(string memory) {
return array;
}
}
Can I test it before deploy ?
– Jay Vyas
Dec 31 '18 at 10:04
sure, go to remix.ethereum.org, inRun
tab choose EnvironmentJavaScript VM
and deploy for testing
– Egor
Dec 31 '18 at 10:08
Wow, amazing solution Accepted Thanks
– Jay Vyas
Dec 31 '18 at 10:10
Also when you will push string in array in Remix IDE, make sure that you have quotes like"yourString"
– Egor
Dec 31 '18 at 10:12
Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract
– Jay Vyas
Dec 31 '18 at 10:46
|
show 1 more comment
Here is my solution, you need experimental ABIEncoderV2
to return array of strings.
pragma solidity ^0.5.2;
pragma experimental ABIEncoderV2;
contract Test {
string array;
function push(string calldata _text) external {
array.push(_text);
}
function get() external view returns(string memory) {
return array;
}
}
Can I test it before deploy ?
– Jay Vyas
Dec 31 '18 at 10:04
sure, go to remix.ethereum.org, inRun
tab choose EnvironmentJavaScript VM
and deploy for testing
– Egor
Dec 31 '18 at 10:08
Wow, amazing solution Accepted Thanks
– Jay Vyas
Dec 31 '18 at 10:10
Also when you will push string in array in Remix IDE, make sure that you have quotes like"yourString"
– Egor
Dec 31 '18 at 10:12
Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract
– Jay Vyas
Dec 31 '18 at 10:46
|
show 1 more comment
Here is my solution, you need experimental ABIEncoderV2
to return array of strings.
pragma solidity ^0.5.2;
pragma experimental ABIEncoderV2;
contract Test {
string array;
function push(string calldata _text) external {
array.push(_text);
}
function get() external view returns(string memory) {
return array;
}
}
Here is my solution, you need experimental ABIEncoderV2
to return array of strings.
pragma solidity ^0.5.2;
pragma experimental ABIEncoderV2;
contract Test {
string array;
function push(string calldata _text) external {
array.push(_text);
}
function get() external view returns(string memory) {
return array;
}
}
answered Dec 31 '18 at 9:54
EgorEgor
598114
598114
Can I test it before deploy ?
– Jay Vyas
Dec 31 '18 at 10:04
sure, go to remix.ethereum.org, inRun
tab choose EnvironmentJavaScript VM
and deploy for testing
– Egor
Dec 31 '18 at 10:08
Wow, amazing solution Accepted Thanks
– Jay Vyas
Dec 31 '18 at 10:10
Also when you will push string in array in Remix IDE, make sure that you have quotes like"yourString"
– Egor
Dec 31 '18 at 10:12
Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract
– Jay Vyas
Dec 31 '18 at 10:46
|
show 1 more comment
Can I test it before deploy ?
– Jay Vyas
Dec 31 '18 at 10:04
sure, go to remix.ethereum.org, inRun
tab choose EnvironmentJavaScript VM
and deploy for testing
– Egor
Dec 31 '18 at 10:08
Wow, amazing solution Accepted Thanks
– Jay Vyas
Dec 31 '18 at 10:10
Also when you will push string in array in Remix IDE, make sure that you have quotes like"yourString"
– Egor
Dec 31 '18 at 10:12
Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract
– Jay Vyas
Dec 31 '18 at 10:46
Can I test it before deploy ?
– Jay Vyas
Dec 31 '18 at 10:04
Can I test it before deploy ?
– Jay Vyas
Dec 31 '18 at 10:04
sure, go to remix.ethereum.org, in
Run
tab choose Environment JavaScript VM
and deploy for testing– Egor
Dec 31 '18 at 10:08
sure, go to remix.ethereum.org, in
Run
tab choose Environment JavaScript VM
and deploy for testing– Egor
Dec 31 '18 at 10:08
Wow, amazing solution Accepted Thanks
– Jay Vyas
Dec 31 '18 at 10:10
Wow, amazing solution Accepted Thanks
– Jay Vyas
Dec 31 '18 at 10:10
Also when you will push string in array in Remix IDE, make sure that you have quotes like
"yourString"
– Egor
Dec 31 '18 at 10:12
Also when you will push string in array in Remix IDE, make sure that you have quotes like
"yourString"
– Egor
Dec 31 '18 at 10:12
Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract
– Jay Vyas
Dec 31 '18 at 10:46
Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract
– Jay Vyas
Dec 31 '18 at 10:46
|
show 1 more comment
If, finally, you want to interact with your smart contract with tools like web3j
(for java) or web3js
(javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.
In this case you should serialize your output array. Same applies if you have an input array.
such a good point
– Egor
Dec 31 '18 at 10:20
add a comment |
If, finally, you want to interact with your smart contract with tools like web3j
(for java) or web3js
(javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.
In this case you should serialize your output array. Same applies if you have an input array.
such a good point
– Egor
Dec 31 '18 at 10:20
add a comment |
If, finally, you want to interact with your smart contract with tools like web3j
(for java) or web3js
(javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.
In this case you should serialize your output array. Same applies if you have an input array.
If, finally, you want to interact with your smart contract with tools like web3j
(for java) or web3js
(javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.
In this case you should serialize your output array. Same applies if you have an input array.
edited Jan 6 at 6:20
answered Dec 31 '18 at 10:18
saman.shahmohamadisaman.shahmohamadi
374218
374218
such a good point
– Egor
Dec 31 '18 at 10:20
add a comment |
such a good point
– Egor
Dec 31 '18 at 10:20
such a good point
– Egor
Dec 31 '18 at 10:20
such a good point
– Egor
Dec 31 '18 at 10:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985923%2fdynamic-array-in-solidity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown