Filecoin EVM : What is the possible solution to the error with code 1 when trying to look up actor state nonce on the Hyperspace network? - smartcontracts

import '#ethersproject/shims';
import 'text-encoding';
import { ethers } from 'ethers';
import { Buffer } from 'buffer';
const fa = require("#glif/filecoin-address");
import { DAPP_CONTRACT } from "#env"
const networkInfo = {
defaultNetwork: "hyperspace",
networks: {
hyperspace: {
chainId: 3141,
url: "https://api.hyperspace.node.glif.io/rpc/v1",
},
},
}
const MintTokens = async (key, amount) => {
try {
let cleanKey = key.replace(/["]/g, "");
let provider = new ethers.providers.JsonRpcProvider(FevmProviderUrl, networkInfo.networks.hyperspace);
const wallet = new ethers.Wallet(cleanKey, provider);
const signer = wallet.connect(provider);
const f4ContractAddress = fa.newDelegatedEthAddress(DAPP_CONTRACT).toString();
const f4WalletAddress = fa.newDelegatedEthAddress(wallet.address).toString();
const f4ActorAddress = fa.newActorAddress(wallet.address).toString();
console.log("Ethereum Contract address in .env (this address should work for most tools):", DAPP_CONTRACT);
console.log("f4address Contract (also known as t4 address on testnets):", f4ContractAddress);
console.log("f4address Actor (also known as t4 address on testnets):", f4ActorAddress);
console.log("f4address Wallet (also known as t4 address on testnets):", f4WalletAddress);
console.log("Provider:", provider);
console.log("Eth Wallet:", wallet);
console.log("Minting FitMint");
const FitMints = new ethers.Contract(DAPP_CONTRACT, ContractABI.abi, signer)
console.log("Contract:", FitMints)
// //Call the mint method
let result = await FitMints.mint(wallet.address, amount, { gasLimit: 30000 })
if(result) {
console.log("Minting Token:", result)
return result
} else {
return {"result": result.toString()}
}
} catch (error) {
console.log(error)
return error
}
}
export default {
MintTokens,
};
Output of mint token:
[Error: processing response error (bod
c":"2.0","id":50,"error":{"code":1,
"failed to look up actor state nonce: resol
failed (t410fzzzo2dimmzy63d4vgxvfak6wvxdhcr
resolve address t410fzzzo2dimmzy63d4vgxvfak6
j3vy: actor not found: validation failure"}
{"code":1}, requestBody="{"method":"eth_s
ction","params":["0x02f8b1820c4580845968c6aa9ae8453d4e311f6749ae0c80b84440c10f1900008f9535ea502bd6adc671469c0000000000000000000000000001c001a00a9df20582d715909d4d7dd7606f2622e3f64c0faa03bdbc7b6b23cb5f26aaccbd12060c3djsonrpc":"2.0"}", requestMethod="POST", u.io/rpc/v1", code=SERVER_ERROR, version=web/
AI Said
Check the imports to make sure all necessary packages are imported correctly.
Verify the contract address in the .env file is correct.
Verify the network information is correctly set for the Hyperspace network.
Check the code for the getTokens and MintTokens functions to ensure all parameters are correctly passed.
Make sure the wallet address is correct and matches the f4 address.
Check the gas limit settings for the MintTokens function.
Ensure the request body and method are correctly set in the code.
Verify the URL for the Json RPC Provider is correct.
But Im just lost, thanks

Related

Can only send data from the end which initiated the connection. How to send Data from other end (PeerJs)

I am using the peerjs module in my SvelteKit app to create a peer-to-peer file transfer app
Also the custom signaling server using peerjs --port 5000 command and it's connecting successfully
Here's my code typescript from the file sender's end:
import { FormatFileSize } from '../lib/utils/FormatFileSize'; // function to convert file size into a string of kb, MB, GB file sizes
import Peer from 'peerjs';
import type { DataConnection } from 'peerjs'; // had to import separately because no export of DataConnection was shown from the 'peerjs' module I don't know why
import { onMount } from 'svelte';
export let file: FileList; // the file which needs to be transfered
let senderPeerId: string = '';
onMount(() => {
let peer: Peer = new Peer({
host: '/',
port: 5000
});
peer.on('open', function (id) {
console.log('My peer ID is: ' + id);
senderPeerId = id;
});
peer.on('connection', (dataConnection: DataConnection) => {
console.log('connected', dataConnection);
dataConnection.send('Hello'); // trying to send this but it's not being recie
dataConnection.on('data', function (data) {
console.log('Received', data); // I am logging the data received from the other end
});
});
});
And here's my code typescript from the file receiver's end (But this end is initiating the peer connection):
import type { PageData } from './$types';
import Peer from 'peerjs';
import { onMount } from 'svelte';
export let data: PageData; // in the formate of { receiverId: string } because this page params contain the peer id of the sender.
let peer: Peer; // initiating here so that can use it elsewhere
onMount(() => {
peer = new Peer({
host: '/',
port: 5000
});
peer.on('open', function (id) {
console.log('My peer ID is: ' + id);
startPeerConnection();
});
});
function startPeerConnection() {
const dataConnection = peer.connect(data.receiverId);
console.log(dataConnection);
dataConnection.on('open', function () {
console.log('connection started');
dataConnection.on('data', function (data) {
console.log('Received', data); // logging the data, but no data is recieved
});
dataConnection.send('World'); // this data is sent successfully and logged in the console of the other side
});
}
What am I doing wrong here, or only the side which initiates the connection can send data?
I looked through the internet but couldn't find a similar problem and a solution to it, please help !!

AAVE v3 - POLYGON - TEST <UnrecognizedContract>.<unknown> When running a script to deposit tokens to AAVE using a fork of the polygon mainnet

I'm testing v3 AAVE contracts on a fork of the polygon mainnet using harhat locally, but when I call de supply() function I get this error:
Error: Transaction reverted without a reason string
at <UnrecognizedContract>.<unknown> (0x794a61358d6845594f94dc1db02a252b5b4814ad)
at <UnrecognizedContract>.<unknown> (0x794a61358d6845594f94dc1db02a252b5b4814ad)
at <UnrecognizedContract>.<unknown> (0x794a61358d6845594f94dc1db02a252b5b4814ad)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at HardhatNode._mineBlockWithPendingTxs (/home/daniel/daniel/dev/chainlink/flowmi/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1802:23)
at HardhatNode.mineBlock (/home/daniel/daniel/dev/chainlink/flowmi/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:491:16)
at EthModule._sendTransactionAndReturnHash (/home/daniel/daniel/dev/chainlink/flowmi/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1522:18)
at HardhatNetworkProvider.request (/home/daniel/daniel/dev/chainlink/flowmi/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:118:18)
at EthersProviderWrapper.send (/home/daniel/daniel/dev/chainlink/flowmi/node_modules/#nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
The script I'm trying to run:
const { getNamedAccounts, ethers } = require("hardhat");
async function main() {
const { deployer } = await getNamedAccounts();
// Mainnet pool adready given by the deployment
// Deposit
// Aprove to get Matic
const AMOUNT = ethers.utils.parseEther("0.11");
//const maticTokenAddress = "0x0000000000000000000000000000000000001010"; //mainnet
const Pool = await getPool(deployer);
const maticTokenAddress = "0xD65d229951E94a7138F47Bd9e0Faff42A7aCe0c6"; // testnet matic address
await approveErc20(maticTokenAddress, Pool.address, AMOUNT, deployer);
console.log("Depositing...");
console.log("Address provided: ", Pool.address);
await Pool.supply(maticTokenAddress, AMOUNT, deployer, 0);
console.log("Deposited!");
}
async function getPool(account) {
const PoolAddressesProvider = await ethers.getContractAt(
"IPoolAddressesProvider",
"0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb", // mainnet pool addresses provider
//"0x5343b5bA672Ae99d627A1C87866b8E53F47Db2E6", // testnet pool addresses provider
account
);
const PoolAddress = await PoolAddressesProvider.getPool();
const Pool = await ethers.getContractAt("IPool", PoolAddress, account);
return Pool;
}
async function approveErc20(
erc20Address,
spenderAddress,
amountToSpend,
account
) {
const erc20Token = await ethers.getContractAt(
"IERC20",
erc20Address,
account
);
const tx = await erc20Token.approve(spenderAddress, amountToSpend);
await tx.wait(1);
console.log("Approved!");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
When I ask for which address was provided the answer is:
Address provided: 0x794a61358D6845594F94dc1DB02A252b5b4814aD
Which happens to be a polygon mainnet pool address according to documentation. Notice is the same address the error gives.
I'll be most thankful if someone points out my mistake
I've tried different combinations of "mainnet" and "testnet" addresses, for the maticToken, and the pool addresses provider
The problem was the matic address, It seems I misundertood documentation, thought the fact that matic is an ERC20 compliant implied it should not need to be wrapped to deposit.
But the script only works with the address of wrapped matic on mainnet.
Maybe is a problem of the mainnet fork, don't know but I moved on.

relay subscription onNext not triggered on react-native

I am a subscription setup but onNext is not getting triggered I am not sure why since this is my first time implementing subscription and docs was not much help with the issue.
Here are the code implementations:
import {
graphql,
requestSubscription
} from 'react-relay'
import environment from '../network';
const subscription = graphql`
subscription chatCreatedSubscription{
chatCreated{
id
initiate_time
update_time
support_id
category_id
email
name
}
}
`;
function chatCreated(callback) {
const variables = {};
requestSubscription(environment, {
subscription,
variables,
onNext: () => {
console.log("onNext");
callback()
},
updater: () => {
console.log("updater");
}
});
}
module.exports = chatCreated;
and here is my network for the subscription
import { Environment, Network, RecordSource, Store } from "relay-runtime";
import Expo from "expo";
import { SubscriptionClient } from "subscriptions-transport-ws";
import { WebSocketLink } from 'apollo-link-ws';
import { execute } from 'apollo-link';
import accessHelper from "../helper/accessToken";
const networkSubscriptions = async (operation, variables) => {
let token = await accessHelper();
if (token != null || token != undefined) {
const subscriptionClient = new SubscriptionClient("ws://localhost:3000/graphql",
{
reconnect: true,
connectionParams: {
Authorization: token,
},
});
execute(new WebSocketLink(subscriptionClient), {
query: operation.text,
variables,
});
}
}
const network = Network.create(fetchQuery, networkSubscriptions);
const store = new Store(new RecordSource());
const environment = new Environment({
network,
store
});
export default environment;
the subscription is called in a componentDidMount method on a component it executes but the onNext method inside the subscription is never triggered when new information is added to what the subscription is listening to.
so i figured out that my issue was the network js not being setup properly and the version of subscription-transport-ws. i added version 0.8.3 of the package and made the following changes to my network file:
const networkSubscriptions = async (config, variables, cacheConfig, observer) => {
const query = config.text;
let token = await accessHelper();
if (token != null || token != undefined) {
const subscriptionClient = new SubscriptionClient(`ws://${api}/graphql`,
{
reconnect: true,
connectionParams: {
Authorization: token,
},
});
subscriptionClient.subscribe({ query, variables }, (error, result) => {
observer.onNext({ data: result })
})
return {
dispose: subscriptionClient.unsubscribe
};
}
}
i hope this helps you if you get stuck with the same issue as mine.

Solidity issue passing parameters to a function

I have a Smart Contract with the function:
contract Example {
event claimed(address owner);
function claimStar() public {
owner = msg.sender;
emit claimed(msg.sender);
}
}
I'm using Truffle V5.0 and the Webpack box as a boiler plate code.
In my truffle-config.js file I have the in the networks configuration:
development:{
host:"127.0.0.1",
port: 9545,
network_id:"*"
}
Everything compile fine using:
- truffle develop
- compile
- migrate --reset
It says Truffle Develop started at http://127.0.0.1:9545
In my index.js file I have the following code:
import Web3 from "web3";
import starNotaryArtifact from "../../build/contracts/StarNotary.json";
const App = {
web3: null,
account: null,
meta: null,
start: async function() {
const { web3 } = this;
try {
// get contract instance
const networkId = await web3.eth.net.getId();
const deployedNetwork = starNotaryArtifact.networks[networkId];
this.meta = new web3.eth.Contract(
starNotaryArtifact.abi,
deployedNetwork.address,
);
// get accounts
const accounts = await web3.eth.getAccounts();
this.account = accounts[0];
} catch (error) {
console.error("Could not connect to contract or chain.");
}
},
setStatus: function(message) {
const status = document.getElementById("status");
status.innerHTML = message;
},
claimStarFunc: async function(){
const { claimStar } = this.meta.methods;
await claimStar();
App.setStatus("New Star Owner is " + this.account + ".");
}
};
window.App = App;
window.addEventListener("load", async function() {
if (window.ethereum) {
// use MetaMask's provider
App.web3 = new Web3(window.ethereum);
await window.ethereum.enable(); // get permission to access accounts
} else {
console.warn("No web3 detected. Falling back to http://127.0.0.1:9545. You should remove this fallback when you deploy live",);
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
App.web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:9545"),);
}
App.start();
});
In my browser I have Metamask installed and I added a Private Network with the same URL and also imported two accounts.
When I start the application and opened in the browser it opens Metamask to request permission because I'm using window.ethereum.enable();.
But when I click on the button to claim it doesn't do anything.
The normal behavior is to Metamask open a prompt to ask for confirmation but it never happen.
I created also a new property in the contract for test and it works fine showing me the value assigned in the contract constructor.
My question is, Am I missing something?
I also tried to change the functionawait claimStar(); to await claimStar({from: this.account}); but in this case I got an error saying that claimStar doesn't expect parameters.
I would appreciate any help. Thanks
I solved the issue, the problem was in the function claimStarFunc
It should be in this way:
claimStarFunc: async function(){
const { claimStar } = this.meta.methods;
await claimStar().send({from:this.account});
App.setStatus("New Star Owner is " + this.account + ".");
}
Because I'm sending a transaction.
Thanks

Get uid after anonymously signing in using AngularFire2 AngularFireAuth

Sign in works, however when I try to access the uid, it comes back null. I've seen the uid in console. I just can't seem to get it out of my service. Here are the relevant parts of my AuthService:
#Injectable()
export class AuthService {
uid: any = null;
constructor(private _firebaseAuth: AngularFireAuth, private router: Router) {
this._firebaseAuth.auth.onAuthStateChanged(function(user) {
if (user) {
this.uid = user.uid;
}
});
signInAnonymously() {
return this._firebaseAuth.auth.signInAnonymously().catch(function(error) {
const errorCode = error.code;
const errorMessage = error.message;
console.log(errorCode, errorMessage);
});
}
In my component, I call signInAnonymously() on a button click:
onGuestClick() {
let uid: any = null;
const guestSignIn = this.authService.signInAnonymously().then(() => {
uid = this.authService.uid;
console.log(uid); // returns null
this.toggleOnline(uid);
});
}
Auth state is changing, but my uid isn't being updated, or at least not before I call for it. Do I need to call on AuthStateChanged somewhere other than my service constructor? What am I doing wrong?
Solved by moving the function that needed the id from the component and into the auth service where access to the id was working.