3

In 0.8.0 or better, math overflows revert by default but you can get the old behaviour with unchecked. unchecked { uint256 p = a * b; } Great. Maybe it overflowed. bool didNotOverflow = p / a == b; // carry on Hope it helps.


2

to push item to array use .push() on array , in this way it's semms to work : myArray.push(i*2); ;)


2

No, this code is safe. constructor(...) is a special function, which can only be called once on the contract deployment to initialize the contract params. After the constructor has run, the final code of the contract is deployed to the blockchain. Ref: https://docs.soliditylang.org/en/v0.8.6/contracts.html#constructor


1

All inputs and output on a public blockchain must be public, so anyone coudl fast forward time and get the outcome key. Some blockchains based on the trusted devices, like Intel SGX chips, might be a better choice, but they are still subject to attacks: https://scrt.network/


1

It is the way etherscan display "internal transactions", the token transfers are under the same transaction hash and they are displayed together. If the requirement is to display them as individual operations then each has to have their own transaction hash. It is not possible with a contract since transfers will be "internal transactions"...


1

If I understand your idea correctly. You'd like to have a contract (addr X) which has a custom filter for receiving transactions. In case if transactions coming from specific address (addr A) values automatically forwarding to (addr Y). // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; contract Tranfer { // address X event ...


1

Because, the return type is not address but a contract (OwnedToken) with public methods and properties that you could call (from solidity). On the javascript side or (other web3 client library), the closest type available in ABI is address (as mentioned in the comments in the code blocks of your question), so that is what it gets converted to.


1

This works assuming your code includes the IERC20 library (this also works with BEP20 tokens ofc, they're essentially the same). It's trivial to modify it so you can withdraw only a certain amount or to another address. function withdrawToken (address tokenAddress) public { IERC20 token = IERC20(tokenAddress); uint256 balance = token.balanceOf(...


1

Depends on the design of the project. You will see the difference when you work on a project or you go through a project step by step. I remember there is a limitation if you wanna use inheritance contracts "Linearization of inheritance graph impossible" https://docs.soliditylang.org/en/v0.8.6/contracts.html#multiple-inheritance-and-linearization ...


1

In fact what protects the contract ownership transfer is this line below: modifier onlyOwner() { require(msg.sender == owner, "Ownable: caller is not the owner"); _; } and then applied on the transferOwnership function function transferOwnership(address newOwner) external onlyOwner { if (newOwner != address(0)) { owner = newOwner; } } ...


1

I don't think you can spoof addresses like that, even locally. The same rules apply everywhere in generating addresses. What you can do is fork mainnet. At least Hardhat supports this easily, and I think also Truffle supports this in some fashion nowadays. Once you've forked mainnet, you can run tests against your local version and impersonate accounts. You ...


1

I wonder why OpenZappelin didn't implement so useful functionality. Talking about your code: holders = 0; not necessary, it is already zero you don't count partially sending, it should increase holders count compute changes for all operations transfer/transferFrom/mint/burn or use OpenZappelin ERC20 implementation and use_beforeTokenTransfer (or reproduce ...


1

I know this is an old question, but this answer could be useful for other people searching for the same thing. The issue can also be resolved from the migrations file, but here's a solution for when you want to deploy from truffle tests: var content = JSON.parse(fs.readFileSync("build/contracts/CitizenAccount.json")); var abi = content['abi'...


Only top voted, non community-wiki answers of a minimum length are eligible