Can I withdraw without authorization from my metamask wallet using truffle hdwalletprovider? - truffle

const HDWalletProvider = require('#truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync("secret").toString().trim();
module.exports = {
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard BSC port (default: none)
network_id: "*", // Any network (default: none)
},
testnet: {
provider: () => new HDWalletProvider(mnemonic, `https://data-seed-prebsc-1-s1.binance.org:8545`),
network_id: 97,
confirmations: 10,
timeoutBlocks: 200,
skipDryRun: true
},
Is there a way for a user who has logged in with metamask in the dapp to automatically withdraw when they write down the amount and press the button?

Related

Why does nodemailer throw the error: Invalid credentials? [duplicate]

I would like to find a way to send email from my app using nodemailer to the users either with some kind of google authentication or any other way. Below mentioned working code has stopped working after Google has disabled less secure app option.
const nodemailer = require('nodemailer')
const sendEmail = async options => {
const transporter = nodemailer.createTransport({
// host: "smtp.gmail.com",
// port: "465",
// secure: true,
service:'gmail',
auth: {
user: "USER_EMAIL",
pass: "USER_PASSWORD"
},
tls:{rejectUnauthorized:false}
})
const message = {
from: `${process.env.FROM_NAME} <${process.env.FROM_EMAIL}>`,
to: options.email,
subject: options.subject,
text: options.message,
html: options.message,
attachments: [
{
filename: '.png',
path: __dirname + '.png',
cid: '.png'
}
]
}
const info = await transporter.sendMail(message)
console.log('Message sent : %s', info.messageId)
console.log(__dirname)
}
module.exports = sendEmail
At the time of writing, Less Secure Apps is no longer supported by google. And you can't use your google account password.
You're gonna have to generate a new app password.
App passwords only work if 2-step verification is turned on.
Follow this steps to get the app password
Go to https://myaccount.google.com/security
Enable 2FA
Create App Password for Email
Copy that password (16 characters) into the pass parameter in Nodemailer auth.
const client = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "username#gmail.com",
pass: "Google-App-Password-Without-Spaces"
}
});
client.sendMail(
{
from: "sender",
to: "recipient",
subject: "Sending it from Heroku",
text: "Hey, I'm being sent from the cloud"
}
)
You should check out Xoauth2.
Nodmailer supports serval types of Oauth
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
type: "OAuth2",
user: "user#example.com",
clientId: "000000000000-xxx0.apps.googleusercontent.com",
clientSecret: "XxxxxXXxX0xxxxxxxx0XXxX0",
refreshToken: "1/XXxXxsss-xxxXXXXXxXxx0XXXxxXXx0x00xxx",
accessToken: "ya29.Xx_XX0xxxxx-xX0X0XxXXxXxXXXxX0x",
expires: 1484314697598,
},
});

Minecraft bot error using mineflayer for node JS

Can someone tell me why I'm getting this error?
"WARNING : unknown transaction confirmation for window 0, action 1432 and accepted false"
for this code:
var mineflayer = require('mineflayer')
var bot = mineflayer.createBot({
host: 'SERVER', // optional
port: 25565, // optional
username: 'USERNAME',
version: '1.16.1'
})
bot.on("login", async => {
console.log("Ingame Bot Online")
// bot.chat("Hello")
})
function Login(arg) {
bot.chat("/login PASSWORD")
}
setTimeout(Login, 3500);

prevent ffmpeg from opening console window

I have a node/express server which is used to give streams from IP camera to a website. Everything is working well. I run that webserver with PM2 on a windows server.
The problem : for each stream I have a windows console opening with just nothing logged in. The console reopen when I try to close it.
Is there a way to prevent those console to open ?
Here is the related node.js code :
const { NodeMediaServer } = require('node-media-server');
private _initiate_streams(): void{
DatabaseProvider.instance.camerasDao.getCamerasList().pipe(
take(1)
).subscribe(
(databaseReadOperationResult: DatabaseReadOperationResult<ICamera[]>) => {
if (databaseReadOperationResult.successful === true){
const cameras = databaseReadOperationResult.result;
const tasks = [];
cameras.forEach( camera => {
tasks.push(
{
app : config.get('media_server.app_name'),
mode: 'static',
edge: camera.rtsp_url,
name: camera.stream_name,
rtsp_transport: 'tcp'
}
)
});
const configMediaServer = {
logType: 3, // 3 - Log everything (debug)
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 60,
ping_timeout: 30
},
http: {
port: config.get('media_server.port'),
allow_origin: '*'
},
auth: {
play: true,
api: true,
publish: true,
secret: config.get('salt'),
api_user: 'user',
api_pass: 'password',
},
relay: {
ffmpeg: 'C:\\FFmpeg\\bin\\ffmpeg.exe',
tasks: tasks
}
};
var nms = new NodeMediaServer(configMediaServer)
nms.run();
} else {
// catch exception
}
}
);
}

Unable to verify the first certificate - Nodejs TLS

I'm using the node-module basic-ftp to try to establish a secure connection via TLS/ SSL.
The server uses a wildcard CA-signed certificate as it's hostname. I can't seem to find an answer for the followig error code.
Connected to 1.1.1.1:21
< 220 Welcome to ftp.foo.com
> AUTH TLS
< 234 Using authentication type TLS
{ Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1051:34)
at TLSSocket.emit (events.js:189:13)
at TLSSocket._finishInit (_tls_wrap.js:633:8) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}
Below you find the sample code:
const ftp = require("basic-ftp");
async establishFtpsConnection() {
const client = new ftp.Client();
client.ftp.verbose = true;
try {
await client.access({
host: "ftp.foo.com",
user: "bar",
password: "1234",
port: 21,
secure: true
});
const list = await client.list();
console.log(list);
} catch (err) {
console.log(err);
}
client.close();
}
NOTE: I'm trying to get it to work for my production environment. So disabling or rejecting unauthorization is NO option for me.
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
OR
rejectUnauthorized: false
Try this :
const ftp = require("basic-ftp");
async establishFtpsConnection() {
const client = new ftp.Client();
client.ftp.verbose = true;
const tlsOptions = {
cert: fs.readFileSync('fullchain.pem', 'ascii')
// a PEM containing the SERVER and ALL INTERMEDIATES
}
try {
await client.access({
host: "ftp.foo.com",
user: "bar",
password: "1234",
port: 21,
secure: true,
secureOptions:tlsOptions
});
const list = await client.list();
console.log(list);
} catch (err) {
console.log(err);
}
client.close();
}
If you are still getting an error then try to inject root SSL certificates
var sslRootCAs = require('ssl-root-cas/latest')
sslRootCAs.inject()

HLF fabric-network fails to connect to IBP2 peer from node-red

I am currently using IBM Blockchain Platform 2.0. I am connecting to it with fabric-network 1.4.0 and fabric-client 1.4.0.
When I listen for events from a simple node.js script on my machine, it works perfectly well. Here is the sample script:
const ccpPath = path.resolve('C:/Users/FlorianCastelain/Documents/GitHub/blockchain-code/node-red/fabric-server/config/org1/ibp2/user1/connection.json');
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
const walletPath = path.resolve('C:/Users/FlorianCastelain/Documents/GitHub/blockchain-code/IBP2/CHAINCODE/public-resource/profile/wallet');
const wallet = new FileSystemWallet(walletPath);
const gateway = new Gateway();
const options = { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: false } };
await gateway.connect(ccp, options);
const network = await gateway.getNetwork('CHANNELNAME');
const contract = network.getContract('CCNAME');
const channel = network.getChannel();
const eventHub = channel.newChannelEventHub('IP:PORT');
let event = eventHub.registerChaincodeEvent('CCNAME', 'EVENTREGEX', (event, number, txid, status) => {
console.log(event);
console.log(event.payload.toString());
console.log(number);
}, (error) => {
console.log(error);
}, { startBlock: 0 });
eventHub.connect(true);
However, my goal is to include this code into node-red nodes (check here.
A bit of context: currently these nodes do not handle discovery, which may be needed. The purpose of my work is to include this into these nodes.
As a consequence, I tried to insert the code above into my nodes code, which gives the following: (same code, it is just a copy/paste)
else if (actionType === 'event') {
node.log('EVENT');
const ccPath = path.resolve('C:/Users/FlorianCastelain/Documents/GitHub/blockchain-code/node-red/fabric-server/config/org1/ibp2/user1/connection.json');
const ccp = JSON.parse(fs.readFileSync(ccPath, 'utf8'));
const walletPath = path.resolve('C:/Users/FlorianCastelain/Documents/GitHub/blockchain-code/IBP2/CHAINCODE/public-resource/profile/wallet');
const wallet = new FileSystemWallet(walletPath);
const gateway = new Gateway();
const options = { wallet, identity: 'user1', discovery: { enabled: true, asLocalHost: false } };
await gateway.connect(ccp, options);
const network = await gateway.getNetwork('CHANEL NAME');
const channel = network.getChannel();
const eventHub = channel.newChannelEventHub('IP:PORT');
let event = eventHub.registerChaincodeEvent('CCNAME', 'REGEX', (event, number, txid, status) => {
console.log(event);
console.log(event.payload.toString());
console.log(number);
}, (error) => {
console.log(error);
}, { startBlock: 0 });
eventHub.connect(true);
// const networkInfo = await connect(identityName, node.connection.discoveryEnabled, node.connection.discoveryAsLocalhost, channelName, contractName, node);
// const channel = networkInfo.network.getChannel();
// await subscribeToEvent(channel, contractName, msg.payload.peerName, msg.payload.startBlock,
// msg.payload.endBlock, msg.payload.timeout, msg.payload.eventName, node, msg);
} else if
It produces the following error:
{ Error: 14 UNAVAILABLE: Connect Failed
at Object.exports.createStatusError (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\common.js:91:15)
at ClientDuplexStream._emitStatusIfDone (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client.js:233:26)
at ClientDuplexStream._receiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client.js:211:8)
at Object.onReceiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client_interceptors.js:1306:15)
at InterceptingListener._callNext (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client_interceptors.js:618:8)
at C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client_interceptors.js:1123:18
code: 14, metadata: Metadata { _internal_repr: {} }, details:
'Connect Failed' }
I checked fabric-network version on both "environment", it is 1.4.0
Does anyone has a clue on what can be the difference and/or what can cause this error?
Edit:
When testing the package when linking it to node-red via npm install PATH instead of using npm link, I get the following error:
{ Error: 14 UNAVAILABLE: failed to connect to all addresses
at Object.exports.createStatusError (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\common.js:91:15)
at ClientDuplexStream._emitStatusIfDone (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client.js:233:26)
at ClientDuplexStream._receiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client.js:211:8)
at Object.onReceiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client_interceptors.js:1306:15)
at InterceptingListener._callNext (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client_interceptors.js:618:8)
at C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client_interceptors.js:1123:18
code: 14,
metadata: Metadata { _internal_repr: {} },
details: 'failed to connect to all addresses' }
Edit: More info from HLF logging. You can find the entire logs here
All addresses have been changed to ADDRESS or ADDRESS:PORT (depending on what was written), except localhost addresses, for security.
The current default (1.4.0-1.4.4) when discovery is used is for all returned ip addresses to be converted to localhost. You need to explicitly disable this. In your code I see you have tried but got the property name slightly wrong. It should be asLocalhost with a small h whereas you have used a capital H

Resources