I'm testing uniswap's swap transaction
my new contract swap() -> uniswap swapRouter02 contract exactInputSingle() which is not from wallet to contract swap
Specifically below code is trying swap my contract's 0.08 WETH to some UNI. and I checked my contract has 0.08 weth.
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 => WETH token address
0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 => UNI token address
0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 => Uniswap SwapRouter02 contract address
but error message when try
ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45).exactInputSingle(params);
Error: Transaction reverted without a reason string at ~~
what does this message mean? and how can I debug this error?
My test environment is hardhat local forking mainnet. The error message is from hardhat forking mainnet
hardhat: {
chainId: 31337,
forking: {
url: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,
blockNumber: 14390000
},
},
function swap() external payable override lock returns (uint256) {
//approve
address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).call(abi.encodeWithSelector(IERC20.approve.selector, 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45, 0x011C37937E080000));
//test
uint256 amountOut;
ISwapRouter02.ExactInputSingleParams memory params =
IV3SwapRouter.ExactInputSingleParams({
tokenIn: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
tokenOut: 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984,
fee: 0,
recipient: msg.sender,
//deadline: _params.deadline,
amountIn: 0x011C37937E080000, //0.08
amountOutMinimum: 0x0,
sqrtPriceLimitX96: 0
});
ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45).exactInputSingle(params);
return 1;
}
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="Error: Transaction reverted without a reason string", method="estimateGas", transaction={"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","to":"0xd5a946A0C214d732a8cf5678be593d26E1bf2170","data":"0x50ac1dd900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f984000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000001c6bf526340000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000021231000000000000000000000000000000000000000000000000000000000000","accessList":null}, error={"name":"ProviderError","code":-32603,"_isProviderError":true,"data":{"message":"Error: Transaction reverted without a reason string","data":"0x"}}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)
I found my fault,
reason was amountOutMinimum value must be not 0x0
Related
I adapted the code from this tutorial for my needs. It works fine at rinkeby network, but I am getting an error when I try to run it on Mumbai network.
AdvancedCollectible.sol >>
pragma solidity 0.6.6;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#chainlink/contracts/src/v0.6/VRFConsumerBase.sol";
contract AdvancedCollectible is ERC721 {
bytes32 internal keyHash;
uint256 public fee;
event requestedCollectible(address indexed senderAdd);
uint256 public tokenCounter;
struct Remedio {
string nome_medicamento;
uint256 dosagem;
string farmaceutica;
string posologia;
}
enum Breed{PUG, SHIBA_INU, ST_BERNARD}
mapping(uint256 => address) public requestIdToSender;
mapping(uint256 => Breed) public tokenIdToBreed;
mapping(uint256 => Remedio) public tokenIdToRemedio;
mapping(uint256 => uint256) public requestIdToTokenId;
constructor() public
ERC721("GeradorReceitasMedicas", "Receita")
{
tokenCounter = 0;
}
function createCollectible(string memory nomeMedicamento, uint256 dosagem, string memory farmaceutica, string memory posologia)
public returns (bytes32) {
uint256 newItemId = tokenCounter;
tokenCounter = tokenCounter + 1;
Remedio memory newRemedio = Remedio({
nome_medicamento: nomeMedicamento,
dosagem: dosagem,
farmaceutica: farmaceutica,
posologia: 'posologia'
});
requestIdToSender[newItemId] = msg.sender;
address receitaOwner = requestIdToSender[newItemId];
_safeMint(receitaOwner, newItemId);
tokenIdToRemedio[newItemId] = newRemedio;
emit requestedCollectible(receitaOwner);
}
}
LinkTokenInterface.sol:
pragma solidity ^0.6.6;
interface LinkTokenInterface {
function allowance(address owner, address spender) external view returns (uint256 remaining);
function approve(address spender, uint256 value) external returns (bool success);
function balanceOf(address owner) external view returns (uint256 balance);
function decimals() external view returns (uint8 decimalPlaces);
function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);
function increaseApproval(address spender, uint256 subtractedValue) external;
function name() external view returns (string memory tokenName);
function symbol() external view returns (string memory tokenSymbol);
function totalSupply() external view returns (uint256 totalTokensIssued);
function transfer(address to, uint256 value) external returns (bool success);
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);
function transferFrom(address from, address to, uint256 value) external returns (bool success);
}
DeployAdvanced.py:
from brownie import AdvancedCollectible, accounts, network, config
from scripts.helpful_scripts import fund_advanced_collectible
def main():
print(config['wallets']['from_key'])
dev = accounts.add(config['wallets']['from_key'])
print(network.show_active())
#print(config['networks'][network.show_active()]['host'])
publish_source = False
print(config['wallets']['from_key'])
advanced_collectible = AdvancedCollectible.deploy(
{"from": dev},
publish_source=publish_source,
)
fund_advanced_collectible(advanced_collectible)
return advanced_collectible
helpful_scripts.py:
from brownie import AdvancedCollectible, accounts, config, interface, network
def fund_advanced_collectible(nft_contract):
dev = accounts.add(config['wallets']['from_key'])
link_token = interface.LinkTokenInterface(
config['networks'][network.show_active()]['link_token']
)
link_token.transfer(nft_contract, 1000000000000000000, {"from": dev})
brownie-config.yaml:
exclude SafeMath when calculating test coverage
https://eth-brownie.readthedocs.io/en/v1.10.3/config.html#exclude_paths
reports: exclude_contracts:
- SafeMath dependencies:
smartcontractkit/chainlink-brownie-contracts#1.1.1
OpenZeppelin/openzeppelin-contracts#3.4.0 compiler: solc:
remappings:
'#chainlink=smartcontractkit/chainlink-brownie-contracts#1.1.1'
'#openzeppelin=OpenZeppelin/openzeppelin-contracts#3.4.0'
automatically fetch contract sources from Etherscan autofetch_sources: True dotenv: .env
set a custom mnemonic for the development network networks: default: development kovan:
vrf_coordinator: '0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9'
link_token: '0xa36085F69e2889c224210F603D836748e7dC0088'
keyhash: '0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4'
fee: 100000000000000000
oracle: '0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e'
jobId: '29fa9aa13bf1468788b7cc4a500a45b8'
eth_usd_price_feed: '0x9326BFA02ADD2366b30bacB125260Af641031331' rinkeby:
vrf_coordinator: '0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B'
link_token: '0x01be23585060835e02b77ef475b0cc51aa1e0709'
keyhash: '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
fee: 100000000000000000
oracle: '0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e'
jobId: '6d1bfe27e7034b1d87b5270556b17277'
eth_usd_price_feed: '0x8A753747A1Fa494EC906cE90E9f37563A8AF630e'
host: 'https://rinkeby.infura.io/v3/${WEB3_INFURA_PROJECT_ID}' mumbai:
link_token: '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'
eth_usd_price_feed: '0x0715A7794a1dc8e42615F059dD6e406A6594651A' polygon-test:
link_token: '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'
eth_usd_price_feed: '0x0715A7794a1dc8e42615F059dD6e406A6594651A' binance:
# link_token: ??
eth_usd_price_feed: '0x9ef1B8c0E4F7dc8bF5719Ea496883DC6401d5b2e' binance-fork:
eth_usd_price_feed: '0x9ef1B8c0E4F7dc8bF5719Ea496883DC6401d5b2e' mainnet-fork:
eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419' matic-fork:
eth_usd_price_feed: '0xF9680D99D6C9589e2a93a78A04A279e509205945' wallets: from_key: ${PRIVATE_KEY} from_mnemonic: ${MNEMONIC}
settings: gas_limit: "100000000000"
When I run it on Rinkeby, I get (run command brownie run .\scripts\advancedCollectible\deploy_advanced.py --network rinkeby):
INFORMAÇÕES: não foi possível localizar arquivos para o(s) padrão(ões)
especificado(s). Brownie v1.18.1 - Python development framework for
Ethereum
ContratoNftProject is the active project.
Running 'scripts\advancedCollectible\deploy_advanced.py::main'...
rinkeby
Transaction sent:
0xf3cbcf650ab9b4408f8e795469ffa60a61f5943ab485ec133e3650fece7545db
Gas price: 1.499999222 gwei Gas limit: 2377218 Nonce: 67
AdvancedCollectible deployed at:
0x5D37fc76D54880F878a395755df5101B644B655a
C:\Users\p\AppData\Roaming\Python\Python39\site-packages\brownie\network\contract.py:1180:
BrownieCompilerWarning: 0x5D37fc76D54880F878a395755df5101B644B655a:
Locally compiled and on-chain bytecode do not match! warnings.warn(
Transaction sent:
0x74a64ac1449a597584bbca8dc0947e80a6ad042ca68453da6e550a0dbbfe67da
Gas price: 1.499999221 gwei Gas limit: 56992 Nonce: 68
LinkToken.transfer confirmed Block: 10631644 Gas used: 51811
(90.91%)
When I run it on Mumbai, I get (run command brownie run .\scripts\advancedCollectible\deploy_advanced.py --network polygon-test):
INFORMAÇÕES: não foi possível localizar arquivos para o(s) padrão(ões)
especificado(s). Brownie v1.18.1 - Python development framework for
Ethereum
ContratoNftProject is the active project.
Running 'scripts\advancedCollectible\deploy_advanced.py::main'...
polygon-test
Transaction sent:
0x6915605b9dfb985b8ef078e3268a6b6e6e2e0b95d3d25ce8e5912c7a71db84d7
Gas price: 1.759579396 gwei Gas limit: 2377218 Nonce: 13
AdvancedCollectible.constructor confirmed Block: 26234140 Gas
used: 2161108 (90.91%) AdvancedCollectible deployed at:
0xdbae4544699a953f2b28AFfBA77008Fd9eb1B4Cf
File
"C:\Users\p\AppData\Roaming\Python\Python39\site-packages\brownie_cli\run.py",
line 51, in main
return_value, frame = run( File "C:\Users\p\AppData\Roaming\Python\Python39\site-packages\brownie\project\scripts.py",
line 103, in run
return_value = f_locals[method_name](*args, **kwargs) File ".\scripts\advancedCollectible\deploy_advanced.py", line 16, in main
fund_advanced_collectible(advanced_collectible) File ".\scripts\helpful_scripts.py", line 10, in fund_advanced_collectible
link_token.transfer(nft_contract, 1000000000000000000, {"from": dev}) File
"C:\Users\p\AppData\Roaming\Python\Python39\site-packages\brownie\network\contract.py",
line 1710, in call
return self.transact(*args) File "C:\Users\p\AppData\Roaming\Python\Python39\site-packages\brownie\network\contract.py",
line 1583, in transact
return tx["from"].transfer( File "C:\Users\p\AppData\Roaming\Python\Python39\site-packages\brownie\network\account.py",
line 644, in transfer
receipt, exc = self._make_transaction( File "C:\Users\p\AppData\Roaming\Python\Python39\site-packages\brownie\network\account.py",
line 727, in _make_transaction
raise VirtualMachineError(e) from None File "C:\Users\p\AppData\Roaming\Python\Python39\site-packages\brownie\exceptions.py",
line 93, in init
raise ValueError(str(exc)) from None ValueError: Gas estimation failed: 'invalid opcode: INVALID'. This transaction will likely
revert. If you wish to broadcast, you must set the gas limit
manually.
Why am I getting this error on Mumbai Network? Is it possible to fix the error above?
Your brownie-config.yaml defines a link_token address on the Mumbai testnet. The fund_advanced_collectible Python function then tries to transfer this token from the dev address.
From other context of your post, I was able to find that the dev address is 0x7cc6FA028dffa310445af40C3abEea61F8534d97.
Mind that you shared the private key as part of the debug output, but did not share the dev address directly (which I was still able to derive from the key). I'm not sure whether that was intentional on your part, but if there were crypto with monetary value on the same address on mainnet, anyone could steal it using this private key. So I'd recomend you to consider this address compromised and never use it on mainnet.
Anyway, the dev address does not own any LINK tokens on Mumbai testnet, which makes this part of the script fail:
link_token.transfer(nft_contract, 1000000000000000000, {"from": dev})
You can claim testnet LINK tokens from the Chainlink faucet: https://faucets.chain.link/mumbai
I'm trying to migrate/test my smart contract on ropsten network using this config:
networks: {
ropsten: {
provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/${infuraKey}`),
network_id: 3, // Ropsten's id
gas: 3000000,
}
},
running truffle migrate --network ropsten
but I keep getting this error:
Error: *** Deployment Failed ***
"Migrations" could not deploy due to insufficient funds
* Account: **address**
* Balance: 0 wei
* Message: sender doesn't have enough funds to send tx. The upfront cost is: 6000000000000000 and the sender's account only has: 0
How do I show truffle I have sufficient funds?
Your Ropsten account needs to have ETH in order to interact with the network.
I am trying to deploy my contract but it returns this error
truffle migrate --network ropsten --reset
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
Error: Error: Error: *** Deployment Failed ***
"Migrations" -- sender account not recognized.
truffle_config.js
ropsten: {
provider: function() {
return new HDWalletProvider(mnemonic, "https://ropsten.infura.io/v3/<PROJECTID>")
},
network_id: "*",
gas: 4000000,
from: "0x4e2f89...."
}
By default, the HDWalletProvider will use the address of the first
address that's generated from the mnemonic. If you pass in a specific
index, it'll use that address instead.
So if you are using address that isn't the first address from this mnemonic you should ether specify the address
HDWalletProvider(mnemonic, "ropsten.infura.io/v3/<PROJECTID>", indexOfYourAddress)
or unlock multiple addresses by putting number to the forth parameter
HDWalletProvider(mnemonic, "ropsten.infura.io/v3/<PROJECTID>",0, numberOfAddresses)
I followed the tutorial of quorum with truffle: https://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains
Now I want to migrate the SimpleStorage.sol Smart Contract to the blockchain, but I want to make it to add the "PrivateFor" parameter.
This is my Smart Contract:
pragma solidity ^0.4.17;
contract SimpleStorage {
uint public storedData;
constructor(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() view public returns (uint retVal) {
return storedData;
}
}
This is my: 2_deploy_simplestorage.js
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage, 42, {privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
But when I do truffle migrate, I get this error:
$ truffle migrate
⚠️ Important ⚠️
If you're using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.
Starting migrations...
======================
> Network name: 'development'
> Network id: 10
> Block gas limit: 3758096384
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0x0a55cd010bb30247c3ae303e54be8dd13177b520af5967728cf77e07ca9efe76
- Blocks: 0 Seconds: 0
> Blocks: 0 Seconds: 0
> contract address: 0x1932c48b2bF8102Ba33B4A6B545C32236e342f34
> account: 0xed9d02e382b34818e88B88a309c7fe71E65f419d
> balance: 1000000000
> gas used: 245462
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
- Saving migration to chain.
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
2_deploy_simplestorage.js
=========================
Deploying 'SimpleStorage'
-------------------------
Error: *** Deployment Failed ***
"SimpleStorage" -- Invalid number of parameters for "undefined". Got 2 expected 1!.
at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-deployer\src\deployment.js:364:1
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Truffle v5.0.1 (core: 5.0.1)
Node v8.11.4
When I don't add the "privateFor" parameter, it works:
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage, 42)
};
But I need this privateFor parameter..
Does someone know how to fix this?
Hey #BlockChainProgrammer. Thanks for guiding me on how to use the Quorum proxy. It worked.
For this error, Try to upgrade/downgrade your truffle version to v4.1.
$ npm install -g truffle#4.1.10
and change the version of solidity to 0.4.24 in your truffle-config.js and the SimpleStorage.sol and add back privateFor in your migration file.
In this case of quorum, the
{
privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
was not defined in the contract, and at such the error, but that particular truffle compiler is compatible with Quorum features.
But For non-Quorum users like myself
The error Usually means, define a variable in your contract and not a compiler problem. Most likely a parameter not set in the constructor.
Open to corrections
Problem solved!
What I had to do is to downgrade truffle to "4.1.10" with:
truffle uninstall -g
and then
npm install -g truffle#4.1.10
Many thanks to #TS28
I created a private network using geth.
And deploy a contract from remix (browser).
It shows following error.
genesis.json is this.
{
"config": {
"homesteadBlock": 0
},
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x4000",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"alloc": {}
}
And I created 2 accounts and run network by this code.
geth --identity "sampleNode" --rpc --rpcport 8545 --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" --rpcaddr "0.0.0.0" --datadir "~/eth-private-net/" --nodiscover --networkid 10 --unlock 0,1 --verbosity 6
And I deployed the contract.
pragma solidity ^0.5.0;
contract SingleNumRegister {
uint storedData;
function set(uint x) public{
storedData = x;
}
function get() public view returns (uint retVal){
return storedData;
}
}
After that, it shows error on geth console log.
DEBUG[01-27|11:05:50.009] VM returned with error err="contract creation code storage out of gas"
I got eth by mining and the account has 315 ether on my private network, but it shows same error.
> eth.getBalance(eth.accounts[0]);
315000000000000000000
What is the problem?
If you deploy using remix there is a field called gas limit. If your gas limit is 3000000 it should be enough, when I deploy your contract on remix it costs much less than that.
Also since you said you deploy on a private blockchain it could have something to do with the gas cost there. Try to deploy in the remix JavascriptVM to see if it works (this works in my case). If it works there try increasing the gas limit when deploying on your private blockchain.