How to make payment to owner address?
My problem is that I cannot make payment from buyer address to owner address via transfer()
function. I have tried to do that in completeOrder()
, however I get the same error again and again. Then I tried kinda do debugging via sendtoOwner
function at buyers address on Remix ide. Error remained same.
- owner address = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c
- buyer address = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c
Error message that I got:
transact to UPChain.sendtoOwner errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value.
Debug the transaction to get more information.
My code:
pragma solidity ^0.5.0;
contract UPChain {
address payable public owner;
address payable public buyerAd;
uint private price;
Order private order;
mapping(uint => Product) offeredProducts;
uint private productseq;
uint private orderedProductseq;
struct Product{
string productName;
uint productPrice;
}
struct Order{
uint orderNo;
mapping(uint => Product) products;
}
modifier ownerMod {
require(owner == msg.sender);
_;
}
modifier buyerMod {
require(buyerAd == msg.sender);
_;
}
function () external payable {
buyerAd.transfer(msg.value);
}
constructor (address payable _buyerAd) public payable {
buyerAd = _buyerAd;
order = Order(1);
owner = msg.sender;
}
function addProduct(string memory _productName,uint _productPrice) public ownerMod{
offeredProducts[productseq] = Product(_productName,_productPrice);
productseq++;
}
function queryProduct(uint _productseq) public view returns(string memory, uint){
return (offeredProducts[_productseq].productName,offeredProducts[_productseq].productPrice);
}
// functions used by buyer
function addtoOrder(uint _productseq) public buyerMod{
order.products[orderedProductseq] = offeredProducts[_productseq];
orderedProductseq++;
}
function queryOrderedProduct(uint _orderedProductseq) public view buyerMod returns(string memory,uint){
return(order.products[_orderedProductseq].productName,order.products[_orderedProductseq].productPrice);
}
function completeOrder() public payable buyerMod returns(string memory,uint){
uint totalPrice=0;
for(uint i=0; i<orderedProductseq;i++){
totalPrice+= order.products[i].productPrice*1000000000000000000;
}
if(msg.value > totalPrice){
owner.transfer(msg.value);
return ("Order is completed", buyerAd.balance);
}
else{
revert();
return ("Order is not completed", buyerAd.balance);
}
}
//
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
function setPrice(uint _price) public ownerMod {
price = _price;
}
function getPrice() public view returns(uint) {
return price;
}
function getContractValue() public payable returns(uint){
return owner.balance;
}
}
ethereum solidity remix
add a comment |
My problem is that I cannot make payment from buyer address to owner address via transfer()
function. I have tried to do that in completeOrder()
, however I get the same error again and again. Then I tried kinda do debugging via sendtoOwner
function at buyers address on Remix ide. Error remained same.
- owner address = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c
- buyer address = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c
Error message that I got:
transact to UPChain.sendtoOwner errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value.
Debug the transaction to get more information.
My code:
pragma solidity ^0.5.0;
contract UPChain {
address payable public owner;
address payable public buyerAd;
uint private price;
Order private order;
mapping(uint => Product) offeredProducts;
uint private productseq;
uint private orderedProductseq;
struct Product{
string productName;
uint productPrice;
}
struct Order{
uint orderNo;
mapping(uint => Product) products;
}
modifier ownerMod {
require(owner == msg.sender);
_;
}
modifier buyerMod {
require(buyerAd == msg.sender);
_;
}
function () external payable {
buyerAd.transfer(msg.value);
}
constructor (address payable _buyerAd) public payable {
buyerAd = _buyerAd;
order = Order(1);
owner = msg.sender;
}
function addProduct(string memory _productName,uint _productPrice) public ownerMod{
offeredProducts[productseq] = Product(_productName,_productPrice);
productseq++;
}
function queryProduct(uint _productseq) public view returns(string memory, uint){
return (offeredProducts[_productseq].productName,offeredProducts[_productseq].productPrice);
}
// functions used by buyer
function addtoOrder(uint _productseq) public buyerMod{
order.products[orderedProductseq] = offeredProducts[_productseq];
orderedProductseq++;
}
function queryOrderedProduct(uint _orderedProductseq) public view buyerMod returns(string memory,uint){
return(order.products[_orderedProductseq].productName,order.products[_orderedProductseq].productPrice);
}
function completeOrder() public payable buyerMod returns(string memory,uint){
uint totalPrice=0;
for(uint i=0; i<orderedProductseq;i++){
totalPrice+= order.products[i].productPrice*1000000000000000000;
}
if(msg.value > totalPrice){
owner.transfer(msg.value);
return ("Order is completed", buyerAd.balance);
}
else{
revert();
return ("Order is not completed", buyerAd.balance);
}
}
//
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
function setPrice(uint _price) public ownerMod {
price = _price;
}
function getPrice() public view returns(uint) {
return price;
}
function getContractValue() public payable returns(uint){
return owner.balance;
}
}
ethereum solidity remix
add a comment |
My problem is that I cannot make payment from buyer address to owner address via transfer()
function. I have tried to do that in completeOrder()
, however I get the same error again and again. Then I tried kinda do debugging via sendtoOwner
function at buyers address on Remix ide. Error remained same.
- owner address = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c
- buyer address = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c
Error message that I got:
transact to UPChain.sendtoOwner errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value.
Debug the transaction to get more information.
My code:
pragma solidity ^0.5.0;
contract UPChain {
address payable public owner;
address payable public buyerAd;
uint private price;
Order private order;
mapping(uint => Product) offeredProducts;
uint private productseq;
uint private orderedProductseq;
struct Product{
string productName;
uint productPrice;
}
struct Order{
uint orderNo;
mapping(uint => Product) products;
}
modifier ownerMod {
require(owner == msg.sender);
_;
}
modifier buyerMod {
require(buyerAd == msg.sender);
_;
}
function () external payable {
buyerAd.transfer(msg.value);
}
constructor (address payable _buyerAd) public payable {
buyerAd = _buyerAd;
order = Order(1);
owner = msg.sender;
}
function addProduct(string memory _productName,uint _productPrice) public ownerMod{
offeredProducts[productseq] = Product(_productName,_productPrice);
productseq++;
}
function queryProduct(uint _productseq) public view returns(string memory, uint){
return (offeredProducts[_productseq].productName,offeredProducts[_productseq].productPrice);
}
// functions used by buyer
function addtoOrder(uint _productseq) public buyerMod{
order.products[orderedProductseq] = offeredProducts[_productseq];
orderedProductseq++;
}
function queryOrderedProduct(uint _orderedProductseq) public view buyerMod returns(string memory,uint){
return(order.products[_orderedProductseq].productName,order.products[_orderedProductseq].productPrice);
}
function completeOrder() public payable buyerMod returns(string memory,uint){
uint totalPrice=0;
for(uint i=0; i<orderedProductseq;i++){
totalPrice+= order.products[i].productPrice*1000000000000000000;
}
if(msg.value > totalPrice){
owner.transfer(msg.value);
return ("Order is completed", buyerAd.balance);
}
else{
revert();
return ("Order is not completed", buyerAd.balance);
}
}
//
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
function setPrice(uint _price) public ownerMod {
price = _price;
}
function getPrice() public view returns(uint) {
return price;
}
function getContractValue() public payable returns(uint){
return owner.balance;
}
}
ethereum solidity remix
My problem is that I cannot make payment from buyer address to owner address via transfer()
function. I have tried to do that in completeOrder()
, however I get the same error again and again. Then I tried kinda do debugging via sendtoOwner
function at buyers address on Remix ide. Error remained same.
- owner address = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c
- buyer address = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c
Error message that I got:
transact to UPChain.sendtoOwner errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value.
Debug the transaction to get more information.
My code:
pragma solidity ^0.5.0;
contract UPChain {
address payable public owner;
address payable public buyerAd;
uint private price;
Order private order;
mapping(uint => Product) offeredProducts;
uint private productseq;
uint private orderedProductseq;
struct Product{
string productName;
uint productPrice;
}
struct Order{
uint orderNo;
mapping(uint => Product) products;
}
modifier ownerMod {
require(owner == msg.sender);
_;
}
modifier buyerMod {
require(buyerAd == msg.sender);
_;
}
function () external payable {
buyerAd.transfer(msg.value);
}
constructor (address payable _buyerAd) public payable {
buyerAd = _buyerAd;
order = Order(1);
owner = msg.sender;
}
function addProduct(string memory _productName,uint _productPrice) public ownerMod{
offeredProducts[productseq] = Product(_productName,_productPrice);
productseq++;
}
function queryProduct(uint _productseq) public view returns(string memory, uint){
return (offeredProducts[_productseq].productName,offeredProducts[_productseq].productPrice);
}
// functions used by buyer
function addtoOrder(uint _productseq) public buyerMod{
order.products[orderedProductseq] = offeredProducts[_productseq];
orderedProductseq++;
}
function queryOrderedProduct(uint _orderedProductseq) public view buyerMod returns(string memory,uint){
return(order.products[_orderedProductseq].productName,order.products[_orderedProductseq].productPrice);
}
function completeOrder() public payable buyerMod returns(string memory,uint){
uint totalPrice=0;
for(uint i=0; i<orderedProductseq;i++){
totalPrice+= order.products[i].productPrice*1000000000000000000;
}
if(msg.value > totalPrice){
owner.transfer(msg.value);
return ("Order is completed", buyerAd.balance);
}
else{
revert();
return ("Order is not completed", buyerAd.balance);
}
}
//
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
function setPrice(uint _price) public ownerMod {
price = _price;
}
function getPrice() public view returns(uint) {
return price;
}
function getContractValue() public payable returns(uint){
return owner.balance;
}
}
ethereum solidity remix
ethereum solidity remix
edited Jan 1 at 13:00
marc_s
580k13011191266
580k13011191266
asked Dec 19 '18 at 14:35
MustafaylMustafayl
84
84
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I could run your code with no issues. When you are calling the below function
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
are you calling with owner account or buyer account. You need to call as a buyer when executing this function as you have a modifier that will check if its buyer or owner. If its not buyer then it will revert, that is what i expect is happening in your case.
When I deploy the contract I am sending buyer adress to constructor. Then I ran that function when buyer account(adress) is selected. As you said it must run. However ı get error in my case
– Mustafayl
Dec 19 '18 at 15:15
Are you sending any ether? Looks like that is also a requirement. Another thing to check is if ether is selected or wei? If its wei change to ether.
– Khaja Mohammed
Dec 19 '18 at 15:40
wei is selected in remix Ide by default.
– Mustafayl
Dec 19 '18 at 16:04
As mentioned in my earlier comment change that to ether and try to send some 5 ethers I.e., put Number 5 in the value field and select ether instead of wei.
– Khaja Mohammed
Dec 19 '18 at 16:06
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%2f53853431%2fhow-to-make-payment-to-owner-address%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I could run your code with no issues. When you are calling the below function
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
are you calling with owner account or buyer account. You need to call as a buyer when executing this function as you have a modifier that will check if its buyer or owner. If its not buyer then it will revert, that is what i expect is happening in your case.
When I deploy the contract I am sending buyer adress to constructor. Then I ran that function when buyer account(adress) is selected. As you said it must run. However ı get error in my case
– Mustafayl
Dec 19 '18 at 15:15
Are you sending any ether? Looks like that is also a requirement. Another thing to check is if ether is selected or wei? If its wei change to ether.
– Khaja Mohammed
Dec 19 '18 at 15:40
wei is selected in remix Ide by default.
– Mustafayl
Dec 19 '18 at 16:04
As mentioned in my earlier comment change that to ether and try to send some 5 ethers I.e., put Number 5 in the value field and select ether instead of wei.
– Khaja Mohammed
Dec 19 '18 at 16:06
add a comment |
I could run your code with no issues. When you are calling the below function
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
are you calling with owner account or buyer account. You need to call as a buyer when executing this function as you have a modifier that will check if its buyer or owner. If its not buyer then it will revert, that is what i expect is happening in your case.
When I deploy the contract I am sending buyer adress to constructor. Then I ran that function when buyer account(adress) is selected. As you said it must run. However ı get error in my case
– Mustafayl
Dec 19 '18 at 15:15
Are you sending any ether? Looks like that is also a requirement. Another thing to check is if ether is selected or wei? If its wei change to ether.
– Khaja Mohammed
Dec 19 '18 at 15:40
wei is selected in remix Ide by default.
– Mustafayl
Dec 19 '18 at 16:04
As mentioned in my earlier comment change that to ether and try to send some 5 ethers I.e., put Number 5 in the value field and select ether instead of wei.
– Khaja Mohammed
Dec 19 '18 at 16:06
add a comment |
I could run your code with no issues. When you are calling the below function
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
are you calling with owner account or buyer account. You need to call as a buyer when executing this function as you have a modifier that will check if its buyer or owner. If its not buyer then it will revert, that is what i expect is happening in your case.
I could run your code with no issues. When you are calling the below function
function sendtoOwner(uint256 value) public payable buyerMod{
owner.transfer(value);
}
are you calling with owner account or buyer account. You need to call as a buyer when executing this function as you have a modifier that will check if its buyer or owner. If its not buyer then it will revert, that is what i expect is happening in your case.
answered Dec 19 '18 at 14:58
Khaja MohammedKhaja Mohammed
564313
564313
When I deploy the contract I am sending buyer adress to constructor. Then I ran that function when buyer account(adress) is selected. As you said it must run. However ı get error in my case
– Mustafayl
Dec 19 '18 at 15:15
Are you sending any ether? Looks like that is also a requirement. Another thing to check is if ether is selected or wei? If its wei change to ether.
– Khaja Mohammed
Dec 19 '18 at 15:40
wei is selected in remix Ide by default.
– Mustafayl
Dec 19 '18 at 16:04
As mentioned in my earlier comment change that to ether and try to send some 5 ethers I.e., put Number 5 in the value field and select ether instead of wei.
– Khaja Mohammed
Dec 19 '18 at 16:06
add a comment |
When I deploy the contract I am sending buyer adress to constructor. Then I ran that function when buyer account(adress) is selected. As you said it must run. However ı get error in my case
– Mustafayl
Dec 19 '18 at 15:15
Are you sending any ether? Looks like that is also a requirement. Another thing to check is if ether is selected or wei? If its wei change to ether.
– Khaja Mohammed
Dec 19 '18 at 15:40
wei is selected in remix Ide by default.
– Mustafayl
Dec 19 '18 at 16:04
As mentioned in my earlier comment change that to ether and try to send some 5 ethers I.e., put Number 5 in the value field and select ether instead of wei.
– Khaja Mohammed
Dec 19 '18 at 16:06
When I deploy the contract I am sending buyer adress to constructor. Then I ran that function when buyer account(adress) is selected. As you said it must run. However ı get error in my case
– Mustafayl
Dec 19 '18 at 15:15
When I deploy the contract I am sending buyer adress to constructor. Then I ran that function when buyer account(adress) is selected. As you said it must run. However ı get error in my case
– Mustafayl
Dec 19 '18 at 15:15
Are you sending any ether? Looks like that is also a requirement. Another thing to check is if ether is selected or wei? If its wei change to ether.
– Khaja Mohammed
Dec 19 '18 at 15:40
Are you sending any ether? Looks like that is also a requirement. Another thing to check is if ether is selected or wei? If its wei change to ether.
– Khaja Mohammed
Dec 19 '18 at 15:40
wei is selected in remix Ide by default.
– Mustafayl
Dec 19 '18 at 16:04
wei is selected in remix Ide by default.
– Mustafayl
Dec 19 '18 at 16:04
As mentioned in my earlier comment change that to ether and try to send some 5 ethers I.e., put Number 5 in the value field and select ether instead of wei.
– Khaja Mohammed
Dec 19 '18 at 16:06
As mentioned in my earlier comment change that to ether and try to send some 5 ethers I.e., put Number 5 in the value field and select ether instead of wei.
– Khaja Mohammed
Dec 19 '18 at 16:06
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%2f53853431%2fhow-to-make-payment-to-owner-address%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