Categories
Cryptocurrency Ethereum Mastering Development

invalid opcode. invalid opcode The execution might have thrown. Debug the transaction to get more information

I get an error when I call tokensend transact to Trust.tokensend errored: VM error: invalid opcode. invalid opcode The execution might have thrown. Debug the transaction to get more information. pragma solidity ^0.6.0; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol"; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol"; import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol"; contract Trust is Ownable{ event _Free (uint); using SafeMath for uint256; uint public free; mapping (address => […]

Categories
Cryptocurrency Ethereum Mastering Development

swapExactETHForTokens – Gas Error Message

After spending hours of research, I finally found the code from this forum that will do the trick for me. I’ve successfully compiled the code in Remix (Kovan Test Environment), but I’m getting this gas error message: Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want […]

Categories
Cryptocurrency Ethereum Mastering Development

How to transfer an external erc20 token with IERC20?

Currently, I try to send Wrapped ETH from my account to a contract address by using IERC20. But it returned an error on Remix. By the way, I could call token.balanceOf(msg.sender) but can’t execute token.transferFrom(msg.sender, address(this), amount) somehow. My code is below pragma solidity ^0.6.0; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol"; contract Test2 { IERC20 public token; constructor(address _token) […]

Categories
Cryptocurrency Ethereum Mastering Development

Swap ether for tokens and provide liquidity on Uniswap

I want to swap half of the provided ether for tokens on Uniswap and provide liquidity with other half and swapped tokens with the buy function. It’s working well in two separate steps, but I want to do this in one transaction. I approved the Uniswap router and this contract for spending tokens. For some […]

Categories
Cryptocurrency Ethereum Mastering Development

Contract ICO price

These codes are the codes of a contract approved in etherscan. it contains tokens and ico contracts in one contract, and it is an actively used contract. When I ran the same contract in tesnet I did not get a result, can you help me how to set the ico price of the contract? Your […]

Categories
Cryptocurrency Ethereum Mastering Development

safeIncreaseAllowance doesn’t work

I want to deposit an ERC-20 token to a contract, but for some reason, nothing happens when I’m trying safeIncreaseAllowance (I checked out the allowance of the token and it didn’t change). I’m using the OpenZeppelin library. pragma solidity ^0.6.7; import "./erc20.sol"; import "./safe-math.sol"; contract simpleContract { using SafeMath for uint256; using SafeERC20 for IERC20; […]

Categories
Cryptocurrency Ethereum Mastering Development

Swap Ether to tokens on Uniswap V2 Router Gas Estimation Error

I am trying to buy DAI tokens from my smart contract using IUniswapV2Router02 contract BuyToken{ address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; // Uniswap Router Address address private multiDaiKovan = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa; // DAI Kovan Address, Mainet: 0x6B175474E89094C44Da98b954EedeAC495271d0F IUniswapV2Router02 public uniswapRouter; constructor() { uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS); } function getPathForETHtoToken() private view returns (address[] memory) { address[] memory […]

Categories
Cryptocurrency Ethereum Mastering Development

How can I delete values from nested mapping after a sum

I’m making an staking contract in solidity and i have used structs and nested mapping for saving users staking amount and its staking time, At the time of unstake i want my users to unstake what ever value he wants, but couldn’t able to achieve that, I can withdraw whole staked amount after summing up […]

Categories
Cryptocurrency Ethereum Mastering Development

Contract example of staking ERC20 token and unstake return will be another token needed

I’m currently looking for an example of how to stake an ERC20 token but the return will be another ERC20 token. I already have an example of standard Stake and Unstake contract code, I want to edit this contract and change the unstake function so the return will be another token. This is the example: […]

Categories
Cryptocurrency Ethereum Mastering Development

Token balance is 0 in metamask after I deploy to Ropsten test net. What am I doing wrong?

Here is contract solidity code: pragma solidity ^0.5.13; interface Callable { function tokenCallback(address _from, uint256 _tokens, bytes calldata _data) external returns (bool); } contract Crunchy { uint256 constant private FLOAT_SCALAR = 2**64; uint256 constant private MainSupply = 10000000000000000000000000; // 10 mil coins uint256 constant private FeeOfStake = 1; // 1% fee per transaction uint256 constant […]