How to get public key with web3 library when you are already unlocked.
Related
I'm learning solidity on remix
I'm also referencing this open source api for token creation.
Right here they provide a _totalSupply() function that I'd like to wire to my smart contract so it shows the total amount of tokens why I deploy it.
What am doing wrong here?
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract Foobar is ERC20 {
constructor(uint256 initialSupply) public ERC20("Foobar", "FOO") {
_mint(msg.sender, initialSupply);
// add totalSupply here
_totalSupply(uint256 5000000000000000000000000000000000000000);
}
}
OpenZeppelin ERC20 _totalSupply is a private property, which means you can't access it from a derived contract (in your case Foobar).
GitHub link to the property definition
Solidity docs on visibility modifiers
Also your syntax is incorrect. If the property were at least internal, you could set its value as
_totalSupply = 5000000000000000000000000000000000000000;
or in a more readable way
_totalSupply = 5 * 1e39;
If you want to change its visibility, you'll need to copy the (parent) ERC20 contract to your IDE and change the import statement to reflect the new (local) location. Then you'll be able to update the property visibility in your local copy of the contract.
Mind that the OpenZeppelin ERC20 contains relative import paths (e.g. import "./IERC20.sol";). You'll need to rewrite these in your local copy as well, so that they point back to the GitHub locations. Otherwise, the compiler would be trying to import non-existing local files.
OpenZeppelin contracts automatically update totalSupply when you mint or burn tokens. They also automatically expose this as a variable you can read. You do not need, and you should not and you cannot set totalSupply by hand, because then the number of distributed tokens would not match the total supply.
I'm writing upgradable Smart Contracts with the Proxy Design Pattern. Here, I'm facing a challenge when I make a delegate call from the proxy contract to the logic contract methods, it throws me an error message as below.
I'm wondering what I have done wrong.
The below code is the method call in the proxy contract.
/*Delegates calls to the Logic contract*/
function setAccepted() public returns(Status){
emit setToAccept(status,now,msg.sender);
bool success;
bytes memory result;
(success,result) = delegateContract.delegatecall(abi.encodePacked(bytes4(keccak256("setAccepted()"))));
require(success);
status = abi.decode(result, (Status));
return status;
}
Logic contract code as below.
function setAccepted() public _WhenNoPaused returns(Status){
return Status.Accepted;
}
It is checked overall solidity code. I recommend studying a tutorial on proxy patterns in solidity. I attached a tutorial link.
https://github.com/rhcproc/solidity-proxy-tutorial
And I found several blogs that explained proxy patterns in solidity.
https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies
https://fravoll.github.io/solidity-patterns/proxy_delegate.html
https://runtimeverification.com/blog/using-foundry-to-explore-upgradeable-contracts-part-1/
When I deploy the below smart contract, the variable manager has the address 0x0000000000000000000000000000000000000000. It is only after I call the constructor (Lottery()) that the variable manager has an address that matches the account it is deployed by.
Why is my constructor not called automatically?
pragma solidity ^0.4.17;
contract Lottery {
address public manager;
function Lottery() public {
manager = msg.sender;
}
}
Your constructor should be called automatically.
I used Remix (https://remix.ethereum.org) with compiler version 0.4.17 and then deployed and manager was set to the deployment address as expected.
The issue you are experiencing would happen if the contract name and the constructor had different names, so the function was no longer a constructor.
Solidity 0.4.22 changed to use constructor instead of the contract name to avoid these type of bugs:
https://github.com/ethereum/solidity/releases/tag/v0.4.22
Constructors should now be defined using constructor(uint arg1, uint arg2) { ... } to make them stand out and avoid bugs when contracts are renamed but not their constructors.
I would suggest you look at using a later version of Solidity 0.5.x.
Why does Remix fail to deploy the simple contract (simplified from the Mastering Ethereum book https://github.com/ethereumbook/ethereumbook/blob/develop/code/Solidity/Faucet2.sol )? --
pragma solidity ^0.4.19;
contract Faucet {
function withdraw(uint withdraw_amount) public {
require(withdraw_amount <= 100000000000000000);
msg.sender.transfer(withdraw_amount);
}
function () external payable {}
}
No matter how I raise gasLimit and/or gasPrice
Your code is fine (I have also tried it myself). From what I see above you are also sending a value along with the deploy. Since you have not defined a constructor yourself the default one is being called which is not payable. If you want to send ether when you deploy the contract you should also define a payable constructor.
I know that in RSA algorithm a Public key is used to ecrypt data which can be decrypted using only the private key.
When a digital certificate is signed the hash of the certificate is signed using the private key of the RootCA and during validation the public key is used to verify the hash. In this case signing means encrypting. Also, sha1RSA algorithm is one of the algos used for signing a certificate.
Thus private key used for Encryption and public key used for Decrytion of the Hash ?
Is this possible using RSA or I understood wrong?
This is quite logical. Private key is known only by owner and public key is known by everyone.
When doing asynchronous encryption, it's important that everyone can produce encrypted message (by using public key), but only recipient (private key holder) will be able to read the message.
When doing digital signatures, it's important that everyone can verify signature (by using public key), but only creator (private key holder) will be able to produce it.