How to create a paid keyvalue store
I'd like to create a contract through which people can set publicly available key=value information in exchange for some Ether sent to me (the owner of the contract).
This is to create a public decentralized database on which anyone can read and write, and the Ether cost would be to limit spam.
However, I'd like it to be free for all users to retrieve any key stored in the contract. My understanding of Ethereum is limited, is this possible?
contract-development contract-design
New contributor
add a comment |
I'd like to create a contract through which people can set publicly available key=value information in exchange for some Ether sent to me (the owner of the contract).
This is to create a public decentralized database on which anyone can read and write, and the Ether cost would be to limit spam.
However, I'd like it to be free for all users to retrieve any key stored in the contract. My understanding of Ethereum is limited, is this possible?
contract-development contract-design
New contributor
add a comment |
I'd like to create a contract through which people can set publicly available key=value information in exchange for some Ether sent to me (the owner of the contract).
This is to create a public decentralized database on which anyone can read and write, and the Ether cost would be to limit spam.
However, I'd like it to be free for all users to retrieve any key stored in the contract. My understanding of Ethereum is limited, is this possible?
contract-development contract-design
New contributor
I'd like to create a contract through which people can set publicly available key=value information in exchange for some Ether sent to me (the owner of the contract).
This is to create a public decentralized database on which anyone can read and write, and the Ether cost would be to limit spam.
However, I'd like it to be free for all users to retrieve any key stored in the contract. My understanding of Ethereum is limited, is this possible?
contract-development contract-design
contract-development contract-design
New contributor
New contributor
New contributor
asked 1 hour ago
thewonderedthewondered
161
161
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I'd like to create a contract through which people can set publicly
available key=value information
You can use a mapping to store data and public method to set values
exchange for some Ether sent to me (the owner of the contract)
You can make the set method payable and check for an amount of Ether from sender
I'd like it to be free for all users to retrieve any key stored in the
contract
You can create the function a view
one so no cost or transaction invlolved in reading values
is this possible?
Yes, This looks possible. It would look like below.
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) public keyValStore;
address payable public owner;
uint storeFee;
constructor(uint fee) public {
owner = msg.sender; // setting contract creator address as the owner
storeFee = fee; // setting a store fee for to set values
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value >= storeFee); // check if Ether value is greater than the store fee
owner.transfer(msg.value); // transfer Ether to owner account
keyValStore[key] = value; // setting the key value pair in mapping
}
function get(bytes32 key) public view returns (bytes32) {
bytes32 val = keyValStore[key]; // get the relavant value for the given key
return val;
}
}
add a comment |
Yes it's possible, here's an example key/value store contract to help you get started that requires 1 ether to set a key/value and anyone can read the data for free:
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) private store;
mapping(bytes32 => address) private authors;
address private owner;
constructor() public {
owner = msg.sender;
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value == 1 ether);
require(store[key] == 0 || authors[key] == msg.sender);
store[key] = value;
authors[key] = msg.sender;
}
function get(bytes32 key) public view returns(bytes32) {
return store[key];
}
function withdraw(address payable receiver) public {
require(msg.sender == owner);
receiver.transfer(address(this).balance);
}
}
https://rinkeby.etherscan.io/address/0xf7e0caef5cd7a18d31343670b60ff463fa23d5c8
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "642"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
thewondered is a new contributor. Be nice, and check out our Code of Conduct.
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%2fethereum.stackexchange.com%2fquestions%2f68654%2fhow-to-create-a-paid-keyvalue-store%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
I'd like to create a contract through which people can set publicly
available key=value information
You can use a mapping to store data and public method to set values
exchange for some Ether sent to me (the owner of the contract)
You can make the set method payable and check for an amount of Ether from sender
I'd like it to be free for all users to retrieve any key stored in the
contract
You can create the function a view
one so no cost or transaction invlolved in reading values
is this possible?
Yes, This looks possible. It would look like below.
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) public keyValStore;
address payable public owner;
uint storeFee;
constructor(uint fee) public {
owner = msg.sender; // setting contract creator address as the owner
storeFee = fee; // setting a store fee for to set values
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value >= storeFee); // check if Ether value is greater than the store fee
owner.transfer(msg.value); // transfer Ether to owner account
keyValStore[key] = value; // setting the key value pair in mapping
}
function get(bytes32 key) public view returns (bytes32) {
bytes32 val = keyValStore[key]; // get the relavant value for the given key
return val;
}
}
add a comment |
I'd like to create a contract through which people can set publicly
available key=value information
You can use a mapping to store data and public method to set values
exchange for some Ether sent to me (the owner of the contract)
You can make the set method payable and check for an amount of Ether from sender
I'd like it to be free for all users to retrieve any key stored in the
contract
You can create the function a view
one so no cost or transaction invlolved in reading values
is this possible?
Yes, This looks possible. It would look like below.
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) public keyValStore;
address payable public owner;
uint storeFee;
constructor(uint fee) public {
owner = msg.sender; // setting contract creator address as the owner
storeFee = fee; // setting a store fee for to set values
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value >= storeFee); // check if Ether value is greater than the store fee
owner.transfer(msg.value); // transfer Ether to owner account
keyValStore[key] = value; // setting the key value pair in mapping
}
function get(bytes32 key) public view returns (bytes32) {
bytes32 val = keyValStore[key]; // get the relavant value for the given key
return val;
}
}
add a comment |
I'd like to create a contract through which people can set publicly
available key=value information
You can use a mapping to store data and public method to set values
exchange for some Ether sent to me (the owner of the contract)
You can make the set method payable and check for an amount of Ether from sender
I'd like it to be free for all users to retrieve any key stored in the
contract
You can create the function a view
one so no cost or transaction invlolved in reading values
is this possible?
Yes, This looks possible. It would look like below.
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) public keyValStore;
address payable public owner;
uint storeFee;
constructor(uint fee) public {
owner = msg.sender; // setting contract creator address as the owner
storeFee = fee; // setting a store fee for to set values
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value >= storeFee); // check if Ether value is greater than the store fee
owner.transfer(msg.value); // transfer Ether to owner account
keyValStore[key] = value; // setting the key value pair in mapping
}
function get(bytes32 key) public view returns (bytes32) {
bytes32 val = keyValStore[key]; // get the relavant value for the given key
return val;
}
}
I'd like to create a contract through which people can set publicly
available key=value information
You can use a mapping to store data and public method to set values
exchange for some Ether sent to me (the owner of the contract)
You can make the set method payable and check for an amount of Ether from sender
I'd like it to be free for all users to retrieve any key stored in the
contract
You can create the function a view
one so no cost or transaction invlolved in reading values
is this possible?
Yes, This looks possible. It would look like below.
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) public keyValStore;
address payable public owner;
uint storeFee;
constructor(uint fee) public {
owner = msg.sender; // setting contract creator address as the owner
storeFee = fee; // setting a store fee for to set values
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value >= storeFee); // check if Ether value is greater than the store fee
owner.transfer(msg.value); // transfer Ether to owner account
keyValStore[key] = value; // setting the key value pair in mapping
}
function get(bytes32 key) public view returns (bytes32) {
bytes32 val = keyValStore[key]; // get the relavant value for the given key
return val;
}
}
edited 17 mins ago
answered 40 mins ago
Achala DissanayakeAchala Dissanayake
3,74481629
3,74481629
add a comment |
add a comment |
Yes it's possible, here's an example key/value store contract to help you get started that requires 1 ether to set a key/value and anyone can read the data for free:
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) private store;
mapping(bytes32 => address) private authors;
address private owner;
constructor() public {
owner = msg.sender;
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value == 1 ether);
require(store[key] == 0 || authors[key] == msg.sender);
store[key] = value;
authors[key] = msg.sender;
}
function get(bytes32 key) public view returns(bytes32) {
return store[key];
}
function withdraw(address payable receiver) public {
require(msg.sender == owner);
receiver.transfer(address(this).balance);
}
}
https://rinkeby.etherscan.io/address/0xf7e0caef5cd7a18d31343670b60ff463fa23d5c8
add a comment |
Yes it's possible, here's an example key/value store contract to help you get started that requires 1 ether to set a key/value and anyone can read the data for free:
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) private store;
mapping(bytes32 => address) private authors;
address private owner;
constructor() public {
owner = msg.sender;
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value == 1 ether);
require(store[key] == 0 || authors[key] == msg.sender);
store[key] = value;
authors[key] = msg.sender;
}
function get(bytes32 key) public view returns(bytes32) {
return store[key];
}
function withdraw(address payable receiver) public {
require(msg.sender == owner);
receiver.transfer(address(this).balance);
}
}
https://rinkeby.etherscan.io/address/0xf7e0caef5cd7a18d31343670b60ff463fa23d5c8
add a comment |
Yes it's possible, here's an example key/value store contract to help you get started that requires 1 ether to set a key/value and anyone can read the data for free:
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) private store;
mapping(bytes32 => address) private authors;
address private owner;
constructor() public {
owner = msg.sender;
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value == 1 ether);
require(store[key] == 0 || authors[key] == msg.sender);
store[key] = value;
authors[key] = msg.sender;
}
function get(bytes32 key) public view returns(bytes32) {
return store[key];
}
function withdraw(address payable receiver) public {
require(msg.sender == owner);
receiver.transfer(address(this).balance);
}
}
https://rinkeby.etherscan.io/address/0xf7e0caef5cd7a18d31343670b60ff463fa23d5c8
Yes it's possible, here's an example key/value store contract to help you get started that requires 1 ether to set a key/value and anyone can read the data for free:
pragma solidity >=0.4.22 <0.6.0;
contract Store {
mapping(bytes32 => bytes32) private store;
mapping(bytes32 => address) private authors;
address private owner;
constructor() public {
owner = msg.sender;
}
function set(bytes32 key, bytes32 value) public payable {
require(msg.value == 1 ether);
require(store[key] == 0 || authors[key] == msg.sender);
store[key] = value;
authors[key] = msg.sender;
}
function get(bytes32 key) public view returns(bytes32) {
return store[key];
}
function withdraw(address payable receiver) public {
require(msg.sender == owner);
receiver.transfer(address(this).balance);
}
}
https://rinkeby.etherscan.io/address/0xf7e0caef5cd7a18d31343670b60ff463fa23d5c8
edited 31 mins ago
answered 40 mins ago
Miguel MotaMiguel Mota
2,8421027
2,8421027
add a comment |
add a comment |
thewondered is a new contributor. Be nice, and check out our Code of Conduct.
thewondered is a new contributor. Be nice, and check out our Code of Conduct.
thewondered is a new contributor. Be nice, and check out our Code of Conduct.
thewondered is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ethereum Stack Exchange!
- 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%2fethereum.stackexchange.com%2fquestions%2f68654%2fhow-to-create-a-paid-keyvalue-store%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