I'm playing Ethernaut DexTwo level,
So I first created my own ERC20 token contract:
The code is successfully deployed to 0x5922Bde44da58B1f73c753541318A0CCF1DbA2e1, and it works fine:
Then I approved the allowance on both Ethernaut and MyToken contract, when I try to swap the tokens:
contract.swap('0x5922Bde44da58B1f73c753541318A0CCF1DbA2e1', await contract.token1(), 100)
It results in invalid opcode error: https://rinkeby.etherscan.io/tx/0x6fa35c21d1c48cc67ed07ca3a175f57b51bc63fe303a77eb30094b97bf08b561
The solc compile is exactly the same, why would there be invalid opcode?
Related
I have two contracts of identical ERC20 code, but on BNB chain the functions fail, such as allowance, and on Ethereum they are fine.
I can't seem to understand why, I've never seen this happen before. I tested on Fantom testnet as well, and it also fails.
https://ropsten.etherscan.io/address/0xe95fc92e1ae8b46e83fc970f9a5f28c9439839ff#readContract
https://testnet.bscscan.com/address/0x6f74C965Fe9A27d3A84c88c83F4700351b0c2e8d#readContract
Allowance returns uint256 : Error: Wrong response id "0" (expected: "8") in {"jsonrpc":"2.0" on BNB chain
And passes on ETH
The allowance is different for every chain.
You need to call the approve function on each chain where you want to give allowance.
I am familiarizing myself with smart contract development using the brownie framework and solidity. To start of I was using the brownie console to deploy some standard OpenZeppelin token contracts.
I did this by copying the code right from their documentation and adjusting the imports to work with brownie, like in this page: https://docs.openzeppelin.com/contracts/3.x/erc777
It works fine for the ERC20 and the ERC721 contracts. The ERC777 however always get reverted and gives me a transaction without error message, where none of the tracing methods work, because they are not implemented for a deployment transaction.
Code For ERC777 Token (Not Working)
// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "OpenZeppelin/openzeppelin-contracts#3.0.0/contracts/token/ERC777/ERC777.sol";
contract GLDToken is ERC777 {
constructor(uint256 initialSupply, address[] memory defaultOperators)
public
ERC777("Gold", "GLD", defaultOperators)
{
_mint(msg.sender, initialSupply, "", "");
}
}
Code For ERC20 Token (Working)
// contracts/TestToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "OpenZeppelin/openzeppelin-contracts#3.0.0/contracts/token/ERC20/ERC20.sol";
contract TestToken is ERC20 {
constructor(uint256 initialSupply) public ERC20("Gold", "GLD") {
_mint(msg.sender, initialSupply);
}
}
Output In Brownie Console
>>> t1 = TestToken.deploy(1e21, {'from': accounts[0]})
Transaction sent: 0x33de3fadb7ccf2dd8b3841365ad88190c3486a803f6ea30c04ef8c0111ec9cbd
Gas price: 0.0 gwei Gas limit: 6721975 Nonce: 2
TestToken.constructor confirmed Block: 4 Gas used: 721166 (10.73%)
TestToken deployed at: 0x8c81630387e9507739fCeB6cbB14Ea1Da11D2339
>>> t2 = GLDToken.deploy(1e21, [], {'from': accounts[1]})
Transaction sent: 0xca91d510e7a54099182fe218ff0ec55c62ccb06227afbe9d9497790e35776651
Gas price: 0.0 gwei Gas limit: 6721975 Nonce: 0
GLDToken.constructor confirmed (reverted) Block: 5 Gas used: 260948 (3.88%)
I have also tried to enter a valid address (of deployed operator contract) in the list for a default token operator, that is passed as the second parameter to the deploy function of the GLDToken. Unfortunately it made no difference.
I have exhausted all possibilities with the deploy function and am getting no further debugging information. Has anyone experienced a similar problem, or knows how to debug this further? Any help would be much appreciated!
I was having a similar issue with the ERC777 contract from openzeppelin. I could not find a sufficient answer online so I wanted to share what worked for me. I rendered a flat file of the contract. On my line 772:
IERC1820Registry internal constant _ERC1820_REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
I deployed an ERC1820 registry locally and replaced that address.
Registry
I was then able to deploy the ERC777.
Hope that works and helps.
if you want to deploy it on local blockchain, you should at first deploy the ERC1820 contract and then deploy the ERC777, BUT on other blockchains ( including testnets and mainnets this 1820 contract is already deployed and you can just use that, its is my repository on github than I deployed a ERC777 contract with a function to check if 1820 not deployed (like on the local blockchain) I deploy it first, otherwise I continue with the deploying ERC777 , I used hardhat to deploy that, but its easy to change it with other lib that you like.
https://github.com/EhsanParsania/ERC777
-- read the readme.md first
I'm trying to use the "swapExactTokensForTokens" function from the pancakeswap Router contract on the testnet.
The pair that I am trying to use is the WBNB / ETH.
I already approved the amount in the WBNB contract. I also use the function "getAmountsOut"
But I always get the same error:
Fail with error 'TransferHelper :: transferFrom: transferFrom failed'
Router Address: https://testnet.bscscan.com/address/0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3#readContract
WBNB Address: https://testnet.bscscan.com/address/0xae13d989dac2f0debff460ac112a837c89baa7cd
ETH Address: https://testnet.bscscan.com/address/0x8babbb98678facc7342735486c851abd7a0d17ca
Transaction detail: https://testnet.bscscan.com/tx/0x23b9c4d80e443766d0fe2c33b7f398b0b639f735af06f7488bd6e56d68414014
Any help is welcome, thank you very much
I am new in Ethereum. How can I sign an ethereum transaction. I am using Blockcypher php-client library. It works fine for Bitcoin. I have changed the network to eth.main and it works for ethereum too. But I can not sign ethereum transaction. The exception arises here in Blockcypher/Crypto/CoinSymbolNetworkMapping.php. . The exception arises. I have added the blue signed lines. But I don't know what are parametes in create function and what value should they have. By adding blue signed code It returns following exception:
Fatal error: Uncaught exception 'BlockCypher\Exception\BlockCypherSignatureException' with message '1 private keys do not correspond to any input. Please check private keys provided.' in C:\xampp\htdocs\bitcoin\api2\BlockCypher\php-client\lib\BlockCypher\Api\TXSkeleton.php on line 164. How can I sign a transaction using Blockcypher API for my website?
I am using testrpc and truffle to test my smart contract before deploying it to the real network.
In my contract, each node has to register in the contract by calling the function register, after that he can send or receive messages to/from contract( the blockchain )
The problem is, when an address ( let say account 1 from testrpc accounts) call the functions (send or receive ) the transaction doesn't occur and this message appears
VM Exception while processing transaction: invalid JUMP at
But when I use another unregistered account to call this function, it works.
Although no messages have been sent or received but no exceptions..
Any idea how I can solve this.
Thanks
Unless your using an old version of solc to compile your solidity the chance of this being an optimization problem is almost none.
Now, what does this mean then, it can happen when for example you run a modifier and it doesn't work. or if you try to call a function you are not allowed to and it throws. For example, it happens a lot after an ICO finishes and you try to use a function that can't be used anymore due to a date constraint it returns an Invalid Jump
I can't see your code but I think you might have reversed your if condition in your modifier and now it returns true if the user is not registered.