Truffle migrate success but contract address is not displayed - ethereum

I am using testrpc to deploy my contracts. Contract deployment is successful and it also displays the contract address in console when it is deployed.
But when I try to query from truffle console it throws this error: Contract has no network configuration for its current network id (5777).
I am clueless. Any help would be much appreciated. I am using Truffle v4.1.0-beta.0 (core: 4.1.0).
Solidity v0.4.19 (solc-js)

You need to return the the deployed contract from the Promise to have the contract object be injected by Truffle. Example:
var Caller = artifacts.require("Caller");
var Callee = artifacts.require("Callee");
module.exports = function(deployer) {
deployer.deploy(Callee).then(function() {
return deployer.deploy(Caller, Callee.address);
});
};

Related

How to call functions of a contract deployed on hardhat forking mainnet

I am trying to use my own contract's functions deployed to hardhat forking mainnet. To do that I have some steps like this:
I added the forking configuration in hardhat.config.js
networks: {
hardhat: {
forking: {
url: "https://eth-mainnet.alchemyapi.io/v2/<key>",
}
}
}
I ran npx hardhat node in a terminal to start rpc server.
I deployed the contract by using hardhat forking as network. So I took the deployed contract address. I used the network parameter as --network hardhat Then it gave me deployed contract address. This address I guess is in the mainnet forking.
I wrote a js file to interact with this contract and call its functions.(For testing I added a simple pure function in contract, returning a uint256)
const { ethers } = require('ethers');
const provider2 = new ethers.providers.getDefaultProvider('http://127.0.0.1:8545/')
const hrdhatAccountPrivate = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"//owner
const hrdhatAccountPublic = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"//owner
const ERC_20_ABI = require("./erc20_abi.json")
const FORK_MAIN_ABI = [
"function myTestFunction() pure returns (uint256)",
]
const walletFork = new ethers.Wallet(hrdhatAccountPrivate, provider2)
async function main() {
const fundxPoolAddr = '0xBbc18b580256A82dC0F9A86152b8B22E7C1C8005'//forking
const fundxPoolContract = new ethers.Contract(fundxPoolAddr, FORK_MAIN_ABI, provider2)
const fundxPoolContractWithWallet = fundxPoolContract.connect(hrdhatAccountPublic)//walletFork
const tx = await fundxPoolContractWithWallet.myTestFunction()//{gasLimit:300000}
console.log(tx);
}
main()
.catch((error) => {
console.error(error);
process.exitCode = 1;
});
But when I try to run this script (to call contract function), it throws an error.
Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="myTestFunction()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.3)
at Logger.makeError (C:\Users\***\node_modules\#ethersproject\logger\lib\index.js:233:21)
at Logger.throwError (C:\Users\***\node_modules\#ethersproject\logger\lib\index.js:242:20)
at Interface.decodeFunctionResult (C:\Users\***\node_modules\#ethersproject\abi\lib\interface.js:388:23)
at Contract.<anonymous> (C:\Users\***\node_modules\#ethersproject\contracts\lib\index.js:395:56)
at step (C:\Users\***\node_modules\#ethersproject\contracts\lib\index.js:48:23)
at Object.next (C:\Users\***\node_modules\#ethersproject\contracts\lib\index.js:29:53)
at fulfilled (C:\Users\***\node_modules\#ethersproject\contracts\lib\index.js:20:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
reason: null,
code: 'CALL_EXCEPTION',
method: 'myTestFunction()',
data: '0x',
errorArgs: null,
errorName: null,
errorSignature: null,
address: '0xB9d9e972100a1dD01cd441774b45b5821e136043',
args: [],
transaction: {
data: '0xd100387c',
to: '0xB9d9e972100a1dD01cd441774b45b5821e136043',
from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
}
}
When I deploy to --network goerli, it works well. But in --network hardhat it occurs an error. How can I solve this?
I tried to deploy my contract into the goerli testnet, then I called this contract's function and it worked. But for hardhat forking mainnet, it isn't deployed properly or I am doing something wrong during calling the contract's function. Otherwise it wouldn't work in goerli.
When I comment/remove the networks parameters in hardhat.config.js and then start the hardhat forking sw with command line just like this: npx hardhat node --fork https://eth-mainnet.alchemyapi.io/v2/<key>, it works well. The problem was about network. I had started the forking network and deployed the contract into it. But in my script I was trying to interact with this contract in the local network.
I very thank nick.tran in KyberNetwork Team for his help.

Automatically pointing contract address to solidity interface

I'm trying to use a interface on remix IDE and my only issue is that I have to copy and paste the contract's address.
Is there a way that I can point it automatically?
ty.
In Remix IDE, you need to copy and paste the newly deployed address manually.
With frameworks, such as Hardhat, you can retrieve the address of the deployed contract in the code and then pass it to the other contract.
In the example below, we're passing the address of First instance to Second's constructor, using the Hardhat JS framework.
const firstFactory = await ethers.getContractFactory("First");
const first = await firstFactory.deploy();
await first.deployed();
const secondFactory = await ethers.getContractFactory("Second");
const second = await secondFactory.deploy(first.address);
await second.deployed();
pragma solidity ^0.8;
contract First {}
contract Second {
constructor(address firstAddress) {}
}

Cannot Deploy to AVAX C-Chain Mainnet | Internal JSON-RPC error. { “code”: -32000, “message”: “execution reverted” }

I've been trying to deploy a smart contract to the AVAX C-Chain Mainnet but continue to get this error:
Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" }
The code snippet that seems to be giving me an issue is this:
IDEXRouter public router; //The DEX router
address public pair; //The address for the token pair
address public WAVAX = 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7; //Avalanche WAVAX
router = IDEXRouter(_router); //Initialize the router with the TraderJoeV2 router address
pair = IDEXFactory(router.factory()).createPair(WAVAX, address(this)); //Update the pair address
_router represents the TraderJoeV2 AVAX C-Chain Mainnet Address, which is 0x60aE616a2155Ee3d9A68541Ba4544862310933d4
I know the most common resolution to this problem seems to be the router address needing to be changed, but the address is correct for the Avalanche C-Chain Mainnet.
I've actually deployed the same exact contract on BSC (Mainnet and Testnet) and ETH (Mainnet and Rinkeby Testnet) with the respective PancakeSwap/Uniswap router addresses and it works perfectly fine. This issue only seems to happen when attempting to deploy to AVAX. I'm using Remix and have no issues with compiling the code.
Any help would be GREATLY appreciated, as I'm completely stuck as to why it works on other networks but not AVAX.
Thank you!

How do I solve the Smart Contract error "returned values aren't valid"?

I am trying to read basic information from a smart contract using web3.js (GRAPH Token):
https://etherscan.io/address/0xc944e90c64b2c07662a292be6244bdf05cda44a7#code
This is my super simple react web3.js setup:
import Web3 from 'web3';
...
useEffect(() => {
const start = async () => {
const web3 = new Web3('https://bsc-dataseed1.binance.org:443')
const abi = [{"inputs":[{"internalType":"uint256","name":"_initialSupply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"NewOwnership","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"NewPendingOwnership","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"addMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"governor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"isMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingGovernor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint256","name":"_deadline","type":"uint256"},{"internalType":"uint8","name":"_v","type":"uint8"},{"internalType":"bytes32","name":"_r","type":"bytes32"},{"internalType":"bytes32","name":"_s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"removeMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newGovernor","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
const address = '0xc944E90C64B2c07662A292be6244BDf05Cda44a7'
const contract = new web3.eth.Contract(abi, address)
console.log(contract);
const i = await contract.methods.getName().call()
console.log(i); // => ERROR
}
start()
}, [])
And it throws error:
Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
This is a known and misleading error which usually means that the address or the contract abi is invalid but I verified it is correct.
I researched this error for two days but didn't manage to solve this issue... any suggestions?
You're trying to interact with an Ethereum contract, using a BSC (Binance Smart Chain) Web3 provider (in your case https://bsc-dataseed1.binance.org:443). This results in trying to call the getName() function on the BSC address (which doesn't contain any contract).
Ethereum and BSC are different networks, unrelated to each other.
Solution: Use an Ethereum mainnet provider (for example Infura is widely used).

Calling External Contract throws error : VM Exception while processing transaction: revert

I've deployed the ScoreStore contract to test RPC, and it works fine. This is ScoreStore contract:
pragma solidity ^0.4.4;
contract ScoreStore
{
mapping(string => int) PersonScores;
function SetScore(string name, int score) {
if(PersonScores[name]>0){
throw;
}
else{
PersonScores[name] = score;
}
}
function GetScore(string name) returns (int){
return PersonScores[name];
}
}
Now I want to use this contract on another contract named MyGame, the contract code is as follows:
pragma solidity ^0.4.4;
contract IScoreStore{
function GetScore(string name) returns (int);
}
contract MyGame{
function ShowScore(string name) returns (int){
// Interface takes an address of the existing contract as parameter
IScoreStore ss = IScoreStore(0x6c38cfb90e8fb1922e61ea4fbe09d29c7751bf82);
return ss.GetScore(name);
}
}
When I give this command on truffle console, mg.ShowScore.call("Anna")
it thorws this:
Error: VM Exception while processing transaction: revert
at XMLHttpRequest._onHttpResponseEnd (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:509:1)
at XMLHttpRequest._setReadyState (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:354:1)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:64:1)
at XMLHttpRequest.request.onreadystatechange (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\httpprovider.
at C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\truffle-provider\wrapper.js:134:1
at C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\requestmanager.js:86:1
at Object.InvalidResponse (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\errors.js:38:1)
Any idea, what i am doing wrong?
Any help is appreciated, P.S: testrpc is already running.
I was able to compile both the contracts in remix and call the ShowScore function after setting some value from ScoreStore contract successfully.
Are you sure the address given to the interface is correct? Because I got the same revert error when I gave an invalid address.