3

The contract address is dependent on the address of the deployer and the nonce, so you should just use one account with the same nonce (newly created, for example) on each network and do not make any other transactions other than the deployment.


2

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


2

Seems kind of expensive for strings that have a different length, which could be most of the time. What about this solution? function memcmp(bytes memory a, bytes memory b) internal pure returns(bool){ return (a.length == b.length) && (keccak256(a) == keccak256(b)); } function strcmp(string memory a, string memory b) internal ...


2

The problem is that ECRecover expect the v parameter to be 27 or 28 and in the signature it is 0. r: 8ecd9d9f1ece5bd0ea1638d9a05bc194bb7536aed42fd6a09fbeb1a9479c3167 s: 60ce3ff2dfbf73ad7a488e6d46988a443430a13153b26b99a83d1101d00e36bb v: 00 From Ethereum's Yellow Paper Appendix F - Signing Transactions. The acceptable values for v are 27 or 28. A solution ...


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

I am not aware of a universally preferred way and it probably boils down to personal preference. Here is my personal take on it: If the contract is a template that may be deployed multiple times with different values, then all the potentially changing values will be assigned in the constructor. On the other hand, if a contract is deployed only once and will ...


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

I solved it this way. BTW, this code has no guards against stopping a user from registering multiple coins. // SPDX-License-Identifier: Unlicense pragma solidity >0.8.5; import &...


1

Change from==0x0 to from==address(0x0). Same thing on the other address comparisons. Currently you are comparing it to the integer 0, you need to cast that into an address in order for it to work.


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

It was implicitly convertible in older versions of the compiler. address a = bytes32(0); It is explicitly convertible through uint160 in recent versions of the compiler. address a = address(uint160(uint(bytes32(0)))); In both cases, it is a truncating conversion. In case parsing that expression is a little cryptic. bytes32 => uint256 is a non-truncating ...


1

Sorted, was being stupid and calling the tokens approve() function via the transfer contract and not on on the token contract directly.


1

Thanks to @zmy comment, pointing to https://www.npmjs.com/package/openzeppelin-solidity. 2.3.0 is earliest version on npm registry as "@openzeppelin/contracts" https://www.npmjs.com/package/@openzeppelin/contracts openzeppelin-solidity has older versions https://www.npmjs.com/package/openzeppelin-solidity So installation should be like npm i ...


1

Your code is wrong. The correct code should look like this. import "@openzeppelin/contracts/access/Ownable.sol"; There is no such library openZeppelin-solidity, The correct library is@openZeppelin/contracts


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

Example code, function stake(address _token, uint256 amount) external { require(amount > 0, "Cannot stake 0"); _totalSupply = _totalSupply.add(amount); _balances[msg.sender] = _balances[msg.sender].add(amount); // Before this you should have approved the amount // This will transfer the amount ...


1

You cannot do such a function because the tokens work in another way. What you can do is make a two-step payment, the classical way in the DeFi space. Firstly you should make a user approve his tokens so the contract can spend his tokens on the user's behalf. This is done through the call to the approve function of the ERC20 contract. Then you should call ...


1

This is the job of the compiler. If you're attempting to use a feature that is not available in the version encapsulated by your pragma, you will get an error. For example: pragma solidity ^0.7.0; contract ErrorExample { function foo(uint256 a, uint256 b) external view returns (uint256) { unchecked { return a + b; } } } ...


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

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

insufficient input amount means the router contract didn't receive the expected amount of your inbound token (WETH) do you have enough eth in your calling address to support the call?


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