I launched my local solana environment with 'solana-test-validator' command, I have a simple POST API like this:
app.post('/test', async (_: any, res: any) => {
const connection = new Connection('http://localhost:8899', 'confirmed');
const wallet = Keypair.generate();
const airdropSignature = await connection.requestAirdrop(
wallet.publicKey,
LAMPORTS_PER_SOL
);
await connection.confirmTransaction(airdropSignature);
res.json({ message: 'Ok' });
});
And I'm getting an error "request to http://localhost:8899/ failed, reason: connect ECONNREFUSED".
Meanwhile my CLI works. What am I doing wrong?
MacOs, node version 18.0.6, #solana/web3.js version 1.55.0
I don't know why, but it worked for me after I changed 'localhost' to '127.0.0.1'
Related
I'm trying to send a transaction with a memo program inside it.
The problem appears on solana cli and web3 too.
This is the command:
solana transfer --from ./.cache/solana.json RECIVER_PUBLIC_KEY 0.00001 --allow-unfunded-recipient --url https://api.testnet.solana.com --fee-payer ./.cache/solana.json --with-memo hello
and this the response:
Error: RPC response error -32005: Node is unhealthy
The same with typescript/js snippet:
async function sendRawTransaction(message:string):Promise<string>{
const connection = await new Connection(CONNECTION_STRING);
let tx = new Transaction().add(
SystemProgram.transfer({
fromPubkey: WALLET.publicKey,
toPubkey: RECIVER_ADDRESS,
lamports: 0,
}),
);
await tx.add(
new TransactionInstruction({
keys: [{ pubkey: WALLET.publicKey, isSigner: true, isWritable: true }],
data: Buffer.from(message, "utf-8"),
programId: MEMO_PROGRAM,
})
);
return new Promise((res, rej)=>{
sendAndConfirmTransaction(connection, tx, [WALLET]).then(s=>{
console.log(s)
res(s)
}).catch(e=>{
console.log(e)
rej(e)
})
})
}
and the response is:
SendTransactionError: failed to send transaction: Node is unhealthy
at Connection.sendEncodedTransaction (/Users/manueltardivo/Sviluppo/Notarify/Refactor/ntf-blackbox/node_modules/#solana/web3.js/lib/index.cjs.js:6812:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Connection.sendRawTransaction (/Users/manueltardivo/Sviluppo/Notarify/Refactor/ntf-blackbox/node_modules/#solana/web3.js/lib/index.cjs.js:6769:20)
at async Connection.sendTransaction (/Users/manueltardivo/Sviluppo/Notarify/Refactor/ntf-blackbox/node_modules/#solana/web3.js/lib/index.cjs.js:6759:12)
at async sendAndConfirmTransaction (/Users/manueltardivo/Sviluppo/Notarify/Refactor/ntf-blackbox/node_modules/#solana/web3.js/lib/index.cjs.js:2219:21) {
logs: undefined
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
SendTransactionError: failed to send transaction: Node is unhealthy
at Connection.sendEncodedTransaction (/Users/manueltardivo/Sviluppo/Notarify/Refactor/ntf-blackbox/node_modules/#solana/web3.js/lib/index.cjs.js:6812:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Connection.sendRawTransaction (/Users/manueltardivo/Sviluppo/Notarify/Refactor/ntf-blackbox/node_modules/#solana/web3.js/lib/index.cjs.js:6769:20)
at async Connection.sendTransaction (/Users/manueltardivo/Sviluppo/Notarify/Refactor/ntf-blackbox/node_modules/#solana/web3.js/lib/index.cjs.js:6759:12)
at async sendAndConfirmTransaction (/Users/manueltardivo/Sviluppo/Notarify/Refactor/ntf-blackbox/node_modules/#solana/web3.js/lib/index.cjs.js:2219:21) {
logs: undefined
}
Node.js v18.4.0
[nodemon] app crashed - waiting for file changes before starting...
I've already tried to delete node_modules and re install them.
Could be a problem with the RPC provider?
Copying my answer from https://solana.stackexchange.com/questions/4303/solana-error-creating-memo-program-node-is-unhealthy-solana-web3/
Under normal circumstances, "node is unhealthy" often means that the node has fallen behind from the rest of the network, so you either need to wait for it to catch up, or you need to use another RPC node.
However, I can tell you that testnet is currently down, so you'll need to use another network until it's back up, either devnet or a local solana-test-validator.
I am trying to replicate https://github.com/dboures/solana-random-number-betting-game
Although when I try to initiate my the Escrow I receive the following error:
Phantom - RPC Error: Transaction creation failed.
Uncaught (in promise) {code: -32003, message: 'Transaction creation failed.'}
I am using Phantom Wallet with Solana RPC.
const transaction = new Transaction({ feePayer: initializerKey })
let recentBlockHash = await connection.getLatestBlockhash();
transaction.recentBlockhash = await recentBlockHash.blockhash;
const tempTokenAccount = Keypair.generate();
// Create Temp Token X Account
transaction.add(
SystemProgram.createAccount({
programId: TOKEN_PROGRAM_ID,
fromPubkey: initializerKey,
newAccountPubkey: tempTokenAccount.publicKey,
space: AccountLayout.span,
lamports: await connection.getMinimumBalanceForRentExemption(AccountLayout.span )
})
);
const { signature } = await wallet.signAndSendTransaction(transaction);
let txid = await connection.confirmTransaction(signature);
console.log(txid);
You're trying to create an account without signing with the keypair of that account to prove ownership.
You have to add the keypair as a signer like such:
await wallet.signAndSendTransaction(transaction, {signers: [tempTokenAccount]})
I was able to solve my problem by using the following code:
const signed = await wallet.request({
method: "signTransaction",
params: {
message: bs58.encode(transaction.serializeMessage())
}
});
const signature = bs58.decode(signed.signature)
transaction.addSignature(initializerKey, signature);
transaction.partialSign(...[tempTokenAccount]);
await connection.sendRawTransaction(transaction.serialize())
instead of:
await wallet.signAndSendTransaction(transaction, {signers: [tempTokenAccount]})
Basically at first I was using one simple function to perform all the above steps, however, for some reason it was not working and throwing the subjected error. When I used this breakdown code it worked!. The cause of the error is still mysterious to me.
Thank you.
I am trying to connect socket.io client which inside react app to the socket.io server but i am getting xhr poll error. I am unable to figure out what is going wrong? client & server code is as follow:
import io from 'socket.io-client';
const socket = io("ws://loacalhost:5000");
socket.on("connect_error", (err) => {
console.log(`connect_error due to ${err.message}`);
});
const express = require('express');
const app = express();
app.use(require('cors')());
const http = require('http');
const server = http.createServer(app);
const io = require("socket.io")(server, {
rejectUnauthorized: false,
cors: {
origin: "http://localhost:3000",
methods: ["GET", "POST"]
}
})
io.on("connection", (socket) => {
console.log(socket.id)
})
server.listen(5000, () => {
console.log('Server is listening on Port 5000');
});
Everything is ok in server file as well as everything is ok in client file except there is syntax mistake in client code i.e.
const socket = io("ws://loacalhost:5000");
replaced with:
const socket = io("ws://localhost:5000");
then it is worked fine, successfully connected to server
Your localhost spelling is incorrect.
const socket = io("ws://loacalhost:5000");
Replaced with
const socket = io("ws://localhost:5000");
I have an app release process that has been working fine for a week or two and has now randomly stopped working.
My npm app is built with Heroku and a release job then runs that FTPs the static files to another host. I use the npm ftp library to do this. This has randomly stopped working with a timeout error:
Error: Timeout while connecting to server
at Timeout._onTimeout (/app/node_modules/ftp/lib/connection.js:304:24)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
the release script is as follows:
const DIST_PATH = `dist/cineworld-planner`;
const filesList = readdirSync(join(process.cwd(), DIST_PATH));
const client = new Client();
function pushFiles() {
const putFile = bindNodeCallback(client.put.bind(client));
from(filesList).pipe(
mergeMap(fileName => {
const localPath = join(process.cwd(), DIST_PATH, fileName);
console.log(`Putting path ${localPath} to remote ${fileName}`);
return putFile(localPath, fileName);
}, 1)
).subscribe({
complete: () => client.end()
});
}
client.on('ready', () => {
console.log(`READY`);
pushFiles();
});
client.on('error', (error: any) => {
const code = error.code || 'NO_CODE';
console.log(`ERROR: ${code}`);
console.log(error);
process.exit(1);
});
client.connect({
user: process.env.FTP_USER,
host: process.env.FTP_HOST,
password: process.env.FTP_PASSWORD
});
I have asked my host if there are any issues but all they have said is that the IP address that my script reported it was running on was not blocked.
I have tested the script from my home PC and it also works fine from there.
This will be a major pain if this has stopped working. I really don't know what else to try.
Any help very gratefully received.
It turns out that for me the fix was as simple as increasing the timeout:
const connectOptions: Options = {
user: process.env.FTP_USER,
host: process.env.FTP_HOST,
password: process.env.FTP_PASSWORD,
connTimeout: 60000,
pasvTimeout: 60000,
};
client.connect(connectOptions);
I'm trying to connect to a local dev environment via an IP address. I'm getting an error because HTTPBatchedNetworkInterface shows:
_uri: "http://10.0.1.10/graphql"
...when it needs to be:
"http://10.0.1.10:3000/graphql"
Here's my server-side setup code:
const localHostString = '10.0.1.10';
const METEOR_PORT = 3000;
const GRAPHQL_PORT = 4000;
const server = express();
server.use('*', cors({ origin: `http://${localHostString}:${METEOR_PORT}` }));
server.use('/graphql', bodyParser.json(), graphqlExpress({
schema,
context
}));
server.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
subscriptionsEndpoint: `ws://${localHostString}:${GRAPHQL_PORT}/subscriptions`
}));
// Wrap the Express server
const ws = createServer(server);
ws.listen(GRAPHQL_PORT, () => {
console.log(`GraphQL Server is now running on http://${localHostString}:${GRAPHQL_PORT}`);
console.log(`GraphiQL available at http://${localHostString}:${GRAPHQL_PORT}/graphiql`);
// Set up the WebSocket for handling GraphQL subscriptions
new SubscriptionServer({
execute,
subscribe,
schema
}, {
server: ws,
path: '/subscriptions',
});
});
What is the correct way to get the port number into HTTPBatchedNetworkInterface._uri?
Thanks in advance to all for any info.
Fixed. My framework is Meteor and I had to set ROOT_URL = 10.0.1.10:3000/.