I don’t think there is any difference between the two in terms of execution or cost, it’s just the look. But I’m not 100% sure on that, could be a slight difference. You can try it in remix and see the gas cost if you are curious.
My code works, I was just concerned why…
User memory user = users[id];
this makes a “copy” in memory (which will disappear at the end of the execution) of the mapping…
User storage user = users[id];
this doesn’t make a copy but points to users[id]
(which is a variable saved in storage)
I also googled for info about this topic and found an interesting article I share to whoever is interested to read more: https://blog.b9lab.com/storage-pointers-in-solidity-7dcfaa536089
Hi @filip, I have some feedback about this course: I’m using Brave Browser and guess what, the remix debugger doesn’t work with Brave, but works with Chrome, Chromium etc. sharing this with all Brave users around, just in case.
Also I’m missing a video showing how to use the remix debugger properly. The course is for noobs, so showing how to debug properly is essential. I searched in youtube and found various videos about debugging with remix, but they are not very well made. Do you cover more in depth the debugger later in the course? I’m at the lecture “Owner modifier” and I think the debugger should have been definitively shown a bit earlier in the course, as you invite your students to try to debug on their own before posting in the forum, understanding the debugger is quite essential. My 2 cents suggestion…
My functionality to set a new owner ( Inheritance Programming Assignment):
For debugging I initially used:
function setNewOwner(address _address) public onlyOwner returns (address) {
owner = _address;
return owner;
}
Then I got rid of the return, as we have already a getter/setter for the owner I can call to see if it worked…
function setNewOwner(address _address) public onlyOwner {
owner = _address;
}
I’ve seen in your solution you used a different function name, and the function parameter name is without underscore. For consistency I used the underscore, why didn’t you name it _newOwner
for consistency? You innocently forgot it, or is there another convention I don’t know yet?
Great feedback! Thanks, will take it into account whenever I’m redoing the videos for this course. Which will happen sooner or later.
Looks good! As for my parameter missing the underscore. Just a mistake on my part. I’m also human and sometimes I forget the syntax convention for the current language I’m doing. Good to be consistent
Hi @filip you asked in “External Contracts & Interfaces” to write in the forum if we find a better workaround to copy/paste the smart contract address. I found it:
- Copy the smart contract address
- Browse to https://etherscan.io paste the address
- Copy the corrected address using the “copy” icon
- Paste the address in remix
Hope this helps, cheers
Hey @filip, here some feedback for “Testnet Deployment”
Normally you put the relevant URLs / source codes in the page, so this URL was missing: https://faucet.metamask.io/
Also to note, in the video you tell to use Rinbeby testnet, but this URL sent a transaction using Ropsten testnet.
That said, I got 1 faucet ETH and deployed on ropsten.
Also I used Chromium on Ubuntu Linux and I had the problem that in the “Run” tab, the “Account” was empty (empty dropdown list). I reloaded different times, got error about personal mode etc. nothing worked. I switched to Brave Browser (which gave me problems with debugging) and there it worked…
Also can you explain why it was not needed to deploy Ownable and Animal? When deploying on testnet (or mainnet) it’s enough to deploy just the final contract?
Here was the code that I changed in the bug detection problem:
function updateBalance(uint id, uint balance) public {
User memory user = users[id];
users[id].balance = balance;
}
What was not working seemed to be the line that said:
user.balance = balance;
it seems to be pointing at nothing, what user.balance?
making it specifically update the users[id].balance and that seems to hav solved the issue.
Hi @filip .
I am stuck on external contract and every time getting error
“transact to ExternalContract.addExternalApples 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
////// external Contract
pragma solidity 0.5.1;
contract Apllefruits {
function addApples (string memory _name, uint _id) public payable returns (uint);
function getBalance() public view returns (uint);
}
contract ExternalContract{
Apllefruits aplleInsstanse = Apllefruits(0x71526bF00EF919DDD7A17266a25b0c5A9E9E8033);
function addExternalApples (string memory _name, uint _id) public payable returns (uint) {
return aplleInsstanse.addApples.value(msg.value)(_name,_id);
}
////////Previous apples Contract
pragma solidity 0.5.1;
import “./Products.sol”;
contract Apllefruits is Products{
event moneySent (uint sentPayment);
modifier cost (uint sum){
require (msg.value >= sum);
_;
emit moneySent (msg.value);
if (msg.value > sum){
msg.sender.transfer(msg.value-sum);
}
}
function addApples (string memory _name, uint _id) public payable cost(10) returns (uint) {
return _addProduct(_name, _id);
}
function getBalance() public view returns (uint){
return address(this).balance;
}
}
Hi @filip
I have a little issue with my scrip and slowly going mad Not sure why it isn’t working as intended. When I deploy and add a Car with YearOfProduction, everything is fine. I try to delete - it’s ok. Problem is when I go to another address and add a car again and then try to delete. Then I get an error and car can not be deleted. (yes I copied a new address )
my script:
I hope you will be able to help me out. Many Thanks!
Please send your contract so it’s more easy to read. The forum has a code function for this. I read through so much code, I need to be able to read through it quickly.
You have the modifier onlyOwner on the delete function. Then only the CONTRACT owner can execute that function. Maybe it is confusing, it has nothing to do with the owner of the car.
Getting error
“transact to ExternalContract.addExternalApples errored: VM error: revert.
revert The transaction has been reverted to the initial state.
pragma solidity 0.5.1;
import "./Products.sol";
contract Apllefruits is Products{
event moneySent (uint sentPayment);
modifier cost (uint sum){
require (msg.value >= sum);
_;
emit moneySent (msg.value);
if (msg.value > sum){
msg.sender.transfer(msg.value-sum);
}
}
function addApples (string memory _name, uint _id) public payable cost(10) returns (uint) {
return _addProduct(_name, _id);
}
function getBalance() public view returns (uint){
return address(this).balance;
}
}
pragma solidity 0.5.1;
contract Apllefruits {
function addApples (string memory _name, uint _id) public payable returns (uint);
function getBalance() public view returns (uint);
}
contract ExternalContract{
Apllefruits aplleInsstanse = Apllefruits(0xe37538bE3AeE714CEF0e8a11c0227d2240fEC16f);
function addExternalApples (string memory _name, uint _id) public payable returns (uint) {
return aplleInsstanse.addApples.value(msg.value)(_name,_id);
}
function getExtBalance() public view returns (uint){
return aplleInsstanse.getBalance();
}
}```
Did you send enough ether?
Yes i did. Somehow i figured out that whenever i use transfer “msg.sender.transfer(msg.value-sum)” instead of send i do get error The constructor should be payable if you send value. Debug the transaction to get more information.”
Ok. Can you send your products contract as well?
Yes sure.
pragma solidity 0.5.1;
import "./Ownable.sol";
contract Products is Ownable{
struct ProductType{
string name;
uint id;
}
mapping (address => ProductType[]) ProductTypeToList;
function _addProduct(string memory _name, uint _id) internal returns (uint) {
return ProductTypeToList[msg.sender].push(ProductType(_name,_id))-1;
}
function getProduct(uint _id) public view returns(string memory){
return ProductTypeToList[msg.sender][_id].name;
}
}
Hi @filip I have a problem with test net deployment. First of all i successfully connected and got ether from rinkeby network but when i choose this network on remix it dosnet shows me my account, so i cant deploy my contracts.