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
Related
I want to get pool with ETH (ETH/UNI, ETH/USDC, ...).
I tried to call getPool() function of uniswap factory contract with 0x0000000000000000000000000000000000000000, but it returns 0x0, which means there is no pool.
There are no pools with ETH in Uniswap v3 (or v2 for that matter), only pools with ERC-20 wrapped ETH (WETH). The address of the WETH token depends on the network, for instance, for the Ethereum mainnet it is 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2. Use this address as an argument for the getPool function.
For instance, to get the UNI/WETH 0.3% pool (UNI token address is 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 on the mainnet), call:
getPool('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
3000)
Something to note: the pool addresses are deterministic and can also b computed off-chain. See here for example code.
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?
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 traying to swap some DAI for ETH on the Ropsten Network using the UniswapV2Router02 on Etherscan (Ropsten Test Network).
DAI Address on Ropsten = 0xad6d458402f60fd3bd25163575031acdce07538d
WETH = 0xc778417E063141139Fce010982780140Aa0cD5Ab
in my Wallet i have 2000 DAI (Ropsten)
but when i put the data there. like this:
Metamask shows that there is an Error thrown by the Contract.
So i might be missing something or am'i doing it wrong.
can please someone help and show me how can i make a successful transaction there ?
i got this to work.
if someone is interested to know how, here is what i have done.
1- amountIn should be in 10^18, that means 100 was wrong, it should be 100x10^18 = 100000000000000000000
2- first i had to approve the UniswapRouterAddress to spend this 100 DAI.
so on the DAI contract Address i had to put the data like this:
after that i was able t swap the 100 DAI for ETH (as much as 100 DAI is worth of ETH)
I am a newbie in Solidity and Ethereum smart contract deployment. I have been trying to deploy some contract on Ethereum Testnet - Ropsten. I have successfully deployed and published
But, I received the error "Unable to Verify Contract source code." when trying to publish the following source code for this contract: https://ropsten.etherscan.io/address/0x811f7cf0f9534f54c4a56c383bbaed73dc88f609#code
I didn't know where did I do wrong.
pragma solidity ^0.4.0;
contract Test3 {
uint storageData;
function set(uint x) public {
storageData = x;
}
}
Any help would be appreciated.
Ok so I don't have enough reputation to comment otherwise I would have but there are very few things that could go wrong here so Ill just go over what you need to do. And you can chat with me on discord or something if you have any other questions. First I assumed you deployed with remix. So go to the settings tab and make sure that on etherscan you selected the same version that is displayed there, otherwise it will not work and then if the optimization box is not checked which is the third checkbox down then select no on etherscan otherwise again it wont work. then you just copy the exact source code into the box and type in the name of the contract and that is it.