Very simple withdrawal

hi. this is my first time using infura, and i just want to send some eth out of a custodial wallet, but it doesn’t like either my api or privatekey?

both were printed and seemed correct. private key starts with 0x but was also tested without.

both result in 401.

 80 // withdraw to ethereum address via infura
 81 app.post('/wallet/:id/withdraw', async (req, res) => {
 82   const wallet_id = req.params.id;
 83   const user_id = req.body.user_id;
 84   const target_address = req.body.target;
 85   const amount = req.body.amount;
 86   const network = process.env._APP_ETHEREUM_NETWORK;
 87
 88   const provider = new InfuraProvider(
 89     network,
 90     process.env._APP_API_INFURA
 91   );
 92
 93   const doc = await WalletModel.findById(wallet_id).exec();
 94
 95   const signer = new Wallet(doc.privateKey, provider);
 96
 97   const tx = await signer.sendTransaction({
 98     to: target_address,
 99     value: parseUnits(amount, "ether")
100   });
101
102   return res.send({'tx': tx.hash});
103 });
2 Likes

Hi, have you solved this? Have you console.log’d the API and private keys to ensure they are in the environment OK?

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.