Skip to main content
added 423 characters in body
Source Link
 function createProduct(string memory _name, uint _price, string memory _info, uint _quantity) public payable { 

This function signature has _price in ethers. So try changing the default units to the ether from Wei and send the appropriate price of the product. enter image description here

Mine is working

[vm]from:0x4b0...4d2dbto:Buyproduct.purchaseProduct(uint256,uint256) 0x1df...bda71value:2000000000000000000 weidata:0xa04...00001logs:1hash:0x4e0...0d2b0 

You also don't need to call these explicitly.

address payable wallet = address(uint160(address(this))); wallet.transfer(msg.value); 

Contract balance will be updated automatically. You can check by implementing this function on your contract.

 function getBalance() public view returns(uint) { return address(this).balance;} 
 function createProduct(string memory _name, uint _price, string memory _info, uint _quantity) public payable { 

This function signature has _price in ethers. So try changing the default units to the ether from Wei and send the appropriate price of the product. enter image description here

Mine is working

[vm]from:0x4b0...4d2dbto:Buyproduct.purchaseProduct(uint256,uint256) 0x1df...bda71value:2000000000000000000 weidata:0xa04...00001logs:1hash:0x4e0...0d2b0 
 function createProduct(string memory _name, uint _price, string memory _info, uint _quantity) public payable { 

This function signature has _price in ethers. So try changing the default units to the ether from Wei and send the appropriate price of the product. enter image description here

Mine is working

[vm]from:0x4b0...4d2dbto:Buyproduct.purchaseProduct(uint256,uint256) 0x1df...bda71value:2000000000000000000 weidata:0xa04...00001logs:1hash:0x4e0...0d2b0 

You also don't need to call these explicitly.

address payable wallet = address(uint160(address(this))); wallet.transfer(msg.value); 

Contract balance will be updated automatically. You can check by implementing this function on your contract.

 function getBalance() public view returns(uint) { return address(this).balance;} 
Source Link

 function createProduct(string memory _name, uint _price, string memory _info, uint _quantity) public payable { 

This function signature has _price in ethers. So try changing the default units to the ether from Wei and send the appropriate price of the product. enter image description here

Mine is working

[vm]from:0x4b0...4d2dbto:Buyproduct.purchaseProduct(uint256,uint256) 0x1df...bda71value:2000000000000000000 weidata:0xa04...00001logs:1hash:0x4e0...0d2b0