New answers tagged

0

To my understanding, Yes! Of course you have to do the abi.encodeWithSignature beforehand and add b as input as type address. You can also specify the amount of gas and the msg.value as shown in the code below. Side note: When you call abi.encodeWithSignature the signature has to exactly match, e.g. uint instead of uint256 will lead to a failed call, ...


1

"Visibility" is similar. Let's have a context to explore the options. Contract Toyota is Car { ... Great. This is inheritance. Toyota will include the code for Car. Car's constructor will execute along with Toyota's when Toyota is deployed. Toyota will inherit Car's` methods (functions), so something like this works: contract Car { function ...


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/


2

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


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 ...


0

same as you use approve() to approve the spending of a particular amount tokens by a particular address (spender here). for example : approve(contract_address, amount) then in contract, you can call transferFrom() method in the contracts function as shown below: function sellToken() public { transferFrom(sender, recipient, amount) } Let me know if this ...


0

If you can modify the token contract it should be possible to give authorization to some addresses to 'approve' tokens on behalf of the users. OpenSea does something similar in isApprovedForAll from ERC721Tradable.sol.


0

In newer versions of solidity, you can use either abstract contracts or interfaces. Abstract contracts now need the abstract keyword to compile correctly, and the virtual modifier on functions. Interfaces are much better for your purpose here, in fact, that's what they were desinged for. I'm pretty sure that interfaces are represented on a low level by ...


0

Based on your description and a superficial look at what you're doing, it is because Roles.sol is imported more than once. It would be tempting to hand-wave and just advise you to linearized the inheritance graph so it gets imported exactly once. In practice, you'll find that very challenging since the dependency is there four times and you need the four ...


0

Doesnt etherscan automatically verify the contract if another contract with matching bytecode is already deployed and verified?


0

Of course you can use the same contract for all transactions. In fact it's meant yo be used this way. You only deploy it once and all transactions are run by the same contract. You need to clarify what do you mean by "my website address" because the way you have it written the "fee" will remain in the contract. You would need to still ...


0

If you want to control contract access, then you should use OpenZeppelin's Ownable, which is the document. https://docs.openzeppelin.com/contracts/3.x/api/access#Ownable


0

Edited: The method isContract is missing. You can just validate this way. modifier onlyNotContract() { require(msg.sender == tx.origin); _; } Read more: https://ethereum.stackexchange.com/a/14016/76945 Thanks Nulik for suggesting. -- Prior Answer: ⚠️ Warning: there is no secure way to prevent contract from calling for now. You can be hacked. Be mindful ...


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"...


2

It is not possible, there isn't a centralized registry for token names or symbols.


0

All answers are moot above. Add a 2nd line to the truffle-config. Where it says version: "X.X.X" Add a comma, then copy paste without the comma to the next line. Now your config should look like this: version: "X.X.X", version: "Y.Y.Y" Do not add a comma to the 2nd one. Save the changes. Now try compiling. It will use BOTH ...


0

It indicates if (and how much) a wallet (or a contract) can transfer another user (or contract) tokens. It's usually set with the approve method but there could other ways too like the permit method. E.g. _allowances[owner][spender] = 42 means that spender can transfer up to 42 owner's tokens towards whoever wants (even itself). Note that after this transfer ...


1

It's having a hard time finding ganache. You'll need nodejs and npm installed, and then run the following: npm install -g ganache-cli And you should be good to go


0

First thing to add at the top of method withdrawTokensFromContract is: require(_token != address(0), "Token cannot be zero address."); With the current logic I don't see validation for each user deposited balance and one user can withdraw all of the contract tokens. You cannot track simple token transfers to the contract, but you can build custom &...


1

Yes, I think this update came along with solidity 0.6.0 this.balance should be replaced with address(this).balance Hope this helps


1

If your project requires that you use an existing contract that has some volume of transactions going through it then using the testnet is the best choice. You can also fork the testNet or even the main net to a certain block and take it from there to start your testing. here you can use any account and give yourself a quasi-infinite balance to try anything ...


0

Are Ethereum smart contracts fit to maintain complex states? What is a feasible amount of information that a smart contact can hold in it's variables? Bytes, kilobytes, megabytes? No. Megabytes would cost hundreds of thousands of dollars. There is no point to put data on a public blockchain, unless it is strictly related to processing financial transactions....


1

This is second-hand information and speculation. I tried to reach out to people who did the original event. Logs were intended to be used as a proof for third party systems that something happened in a blockchain. Now logs are used by bridges between different blockchains for this purpose. Logs were intended to be purgeable i.e. full nodes have logged only ...


1

Events use one of the LOG operations. The output of LOG operations is not accessible from smart contracts by design - it allows clients to avoid storing event/log data as an optimization and as a result the LOG operation has a low gas cost reflecting the reduced hardware cost. In other words, SSTORE is expensive because it provides a guarantee that smart ...


0

I was able to solve this by creating a payable function in my smart contract and sending eth to that function instead of directly to the contract. Still not sure why I ran into this error in the testing environment but not in the truffle develop environment though.


1

But I didn't find a mention to why is that, because first: you don't need that in a contract, and event is a message from the inside to the outside, why would a contract need to access events of other contracts? Only for some weird use case. Second, you would spend a lot of Gas and your transaction wouldn't fit inside a block. if it's cheaper to store data ...


0

So - I saw that there's too much going on here and set up everything locally using Go-ethereum. Using Truffle.


0

I know it's late, but what the hell. What you're asking for would require a complete redesign on how the entire system works. I say this to highlight this because you ask a good question. I might be better to frame this as you're actually asking "How to avoid iteration in contract design". This would be a broader exploration of software ...


4

Yes. It is EIP-1271: Standard Signature Validation Method for Contracts. You can find details here. EIP-1271 is supported e.g. by Gnosis Multisig.


0

With the latest changes use window.ethereum as provider after the user has granted permission async function contract() { const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' }); const web3 = new Web3(window.ethereum);


0

I would like to add how the placement of _ matters in the code. The following code is taken from solidity docs. Note how _ is placed between both return statements. it implies when the code is merged the function body would be placed/merged at where _ is. hence Before the function body lock is acquired. After the body is complete the last line is still run ...


0

For you first question, you can directly port your code from ethereum to main net just make sure that if you are using any Standard interface such IERC20 in your code base convert them to their appropriate BSC alternative such as IBEP20. For your second question NO infura does not support the BSC network For your last question YES web3 can work with BSC, ...


1

Off-chain access Technically the entire transaction history does exist in the blockchain. If you have a full-node or if you use some external service, you should be able to query this data. However, this transaction history is not available on-chain unless you use an oracle service. On-chain access To access this data on-chain, you'll have to manually store ...


2

If you have a look at the function signature of that function, it's function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256). It returns 6 values, so you could get the return values with something like (uint256 a, b, c, d, e, f) = _getValues(tAmount);. If, however, you are not interested in all of the ...


0

You are not concerned if EVM implementation itself is multithreaded or not (there are several implementations, you do not care.) Does it work as a multithreaded environment, or are all transactions in a block executed in a linear fashion Yes. All transactions are atomic by the definition. The whole block gets executed, or none of a block gets executed. You ...


0

If you're looking for multithreading, look at Solana. EVM is single-threaded. https://fullstacks.org/materials/ethereumbook/14_evm.html


0

Paul's answer is very good. If you want to approximate an exponential function, I used a series of linear functions with a target half-life: function getPrice(uint256 value, uint256 t, uint256 halfLife) public pure returns (uint256 price) { price = value >> (t / halfLife); price -= price * (t % halfLife) / halfLife / 2; } Half-life in my code ...


1

OpenSea has a contract ERC721Tradable.sol that whitelist the OpenSea operator /** * Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. */ function isApprovedForAll(address owner, address operator) override public view returns (bool) { // Whitelist ...


0

I guess it is not possible, the contract and it's external/public functions will be available to the whole network when once you deploy it. I think if you don't verify your contract's code and don't expose them on your front end, no one will know about the functions names. Still, it is very bad practice. If you have some functions that should not be executed ...


0

It is the latter. Your contract must absolutely conform to the ERC20 standard. You cannot use a function such as your TransferTokens function. Pancakeswap (and pretty much everyone else also), will call the functions defined in ERC20. Custom functions not part of ERC20 will never be called.


0

You can transfer the token without the ownership. If you give an address approval, the address can transfer the token. function approve(address _approved, uint256 _tokenId) This function is used to give an address approval. In the transfer function of ERC-721. The from address must be either the token owner or have an approval. Here is the transfer function ...


0

Apparently you're passing a constant integer to selfdestruct, while the correct call would be to pass an address. 0x0 is not the 0 address, it's just the hexadecimal form of the integer 0. You need to convert it into a payable address and pass it to selfdestruct as follows: selfdestruct(payable(0x0)) Actually, you don't even need to use the hex format and ...


1

When you specify a value, you are transferring ETH from the calling contract to the called contract. But delegatecall doesn't actually switch which contract is running, instead it loads the other contract's code and runs it as if it was the calling contract. For example, if you call Michael Jordan to dunk the basketball, it makes sense to pass him the ...


0

Let them sign in via Metamask. You can let them sign without using any gas.


0

If you click some of the internal transactions, you'll notice that there are normal ERC20 transfers in the "parent" transaction. The concept is "internal" transaction simply means that the transfer is done inside another transaction, and otherwise there is nothing special about it - they work exactly the same way as if they were not ...


1

This looks like a front-run attempt(also known as a sandwich attack). Front running is an attempt to profit by a malicious actor by out-bidding a target transaction's gas, which results in the front-runner buying before them. Once both transactions are through, the front-runner is at an immediate profit because of the target transaction buying after them. ...


1

OpenZeppelin is a “battle-tested” open source framework comprised of reusable Ethereum smart contracts. The framework helps smart contract developers reduce the risk of vulnerabilities in their distributed applications (dapps) by using standard, tested, community-reviewed code. Yes, it should be the same. There is a bug in testnets since a lobg time which ...


3

Bit of Explanation First you should familiarise yourself with the concept of "unchecked arithmetic", which is part of the v0.8 breaking changes list: Arithmetic operations revert on underflow and overflow. You can use unchecked { ... } to use the previous wrapping behaviour. Importantly, overflows and underflows use the REVERT opcode instead of ...


1

Solidity 0.8 includes the following change regarding arithmatic overflows/underflows: Arithmetic operations revert on underflow and overflow. You can use unchecked { ... } to use the previous wrapping behaviour. The Solidity 0.8 arithmetic exception gets triggered before that require statement is fully assessed. I believe there is not way you could ...


Top 50 recent answers are included