Transfer error using Phantom Wallet when using signAndSendTransaction function - javascript

Does anyone know what's wrong with this code?
await window.solana.connect();
let fromWallet = window.solana.publicKey;
let toWallet = new PublicKey("<KEY>");
let transaction = new Transaction();
transaction.add(
SystemProgram.transfer({
fromPubKey: fromWallet,
toPubKey: toWallet,
lamports: LAMPORTS_PER_SOL
})
);
transaction.feePayer = fromWallet;
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
let bk = await connection.getLatestBlockhash();
transaction.recentBlockhash = bk.blockhash;
const signature = await window.solana.signAndSendTransaction(await transaction);
await connection.confirmTransaction(signature);
console.log(signature);
It throws an error at line
const signature = await window.solana.signAndSendTransaction(await transaction)
Something about converting undefined to base58.
I have checked the keys, they are both fine.
Here is the error log:
vue.runtime.esm.js?2b0e:1897 TypeError: Cannot read properties of undefined (reading 'toBase58')
at eval (index.browser.esm.js?64b9:2451:1)
at Array.sort (<anonymous>)
at Transaction.compileMessage (index.browser.esm.js?64b9:2450:1)
at Transaction._compile (index.browser.esm.js?64b9:2563:1)
at Transaction.serializeMessage (index.browser.esm.js?64b9:2585:1)
at ia (inpage.js:141:130205)
at inpage.js:141:137033
at c (inpage.js:2:47880)
at Generator._invoke (inpage.js:2:47668)
at Generator.next (inpage.js:2:48309)
Any ideas?

Oh dear lord,
I fixed the issue by changing the code:
transaction.add(
SystemProgram.transfer({
fromPubKey: fromWallet,
toPubKey: toWallet,
lamports: LAMPORTS_PER_SOL
})
);
to the following:
const instruction = SystemProgram.transfer({
fromPubkey: fromWallet,
toPubkey: toWallet,
lamports: LAMPORTS_PER_SOL,
});
transaction.add(instruction);
I still don't understand why it works, but hey it solved my issue.

The error TypeError: Cannot read properties of undefined (reading 'toBase58') typically means that there's an invalid PublicKey somewhere.
Assuming that the connection to the wallet is correct, there's probably an issue with the line:
let toWallet = new PublicKey("<KEY>");
First, be sure that the result of that call is correct, by logging it, ie.:
console.log(toWallet.toBase58());
If that works, then there's likely an issue with the wallet connection.

Related

Gnosis Transaction Failing On Polygon w/ "Transaction Underpriced" error

I've been trying to get a transaction to execute on Polygon but it's been failing with the following error:
reason: 'processing response error',
code: 'SERVER_ERROR',
body: '{"jsonrpc":"2.0","id":89,"error":{"code":-32000,"message":"transaction underpriced"}}',
This error only occurs on Polygon and it only occurs when using the Gnosis SDK. I've tested it using the Gnosis UI and it executes successfully. I've also tested it using the Gnosis SDK on rinkeby and that works as well.
Here is the code that fails:
const infuraProvider = new ethers.providers.JsonRpcProvider(RPC_PROVIDER);
const wallet = new ethers.Wallet(`0x${PRIVATE_KEY}`, infuraProvider);
const owner1 = wallet.connect(infuraProvider);
const ethAdapterOwner1 = new EthersAdapter({ ethers, signer: owner1 });
const safeSdkInstance = await Safe.create({
ethAdapter: ethAdapterOwner1,
safeAddress: GNOSIS_SAFE_ADDR,
});
const contract = new ethers.Contract(contractJson.address, contractJson.abi, owner1);
const tx = {
to: contract.address,
value: '0',
data: contract.interface.encodeFunctionData('mint', ['[wallet address here]', '[token id here]']),
};
const safeTransaction = await safeSdkInstance.createTransaction(tx);
const executeTxResponse = await safeSdkInstance.executeTransaction(safeTransaction);
Other things I've tried:
Adding a gasPrice - making that gas price incredibly large
Adding a gasLimit
Changing RPC_PROVIDER from an infura provider to a public one
Calling a different function - I tried calling my contracts burn function and it came back with the exact same error
I did notice that even when providing a gasPrice the error I get back says that the transaction provided had a gasPrice of null. But when logging the safeTransaction object it shows a gasPrice is generated by the createTransaction function. So something must be going wrong in the executeTransaction function

How to Define TextdecoderStream and TextEncoderStream while using Web Serial in react?

My code is like this in react when i run it, it says TextDecoderStream() & TextEncoderStream() is not defined.
async function connect() {
const port = await navigator.serial.requestPort();
// - Wait for the port to open.
await port.open({ baudRate: 115200 });
console.log("Open");
let decoder = new TextDecoderStream();
inputDone = port.readable.pipeTo(decoder.writable);
inputStream = decoder.readable;
const encoder = new TextEncoderStream();
outputDone = encoder.readable.pipeTo(port.writable);
outputStream = encoder.writable;
let reader = inputStream.getReader();
}
getting error
src\Components\play\Remote\Ace\RemoteSection\RemoteSection.js
Line 453:23: 'TextDecoderStream' is not defined no-undef
Line 457:25: 'TextEncoderStream' is not defined no-undef
And if i remove stream and only use TextDecoder() and TextEncoder()
then it is showing
Unhandled Rejection (TypeError): Failed to execute 'pipeTo' on
'ReadableStream': parameter 1 is not of type 'WritableStream'.
Unhandled Rejection (TypeError): Cannot read properties of undefined
(reading 'pipeTo')
TextDecoderStream and TextEncoderStream are available in Chrome 71 according to https://chromestatus.com/features/4881011259211776.
I suspect your issue is a linter issue. You may want to try this eslint rule as documented at https://eslint.org/docs/rules/no-undef.
// eslint-disable-next-line no-undef
let decoder = new TextDecoderStream();
...
// eslint-disable-next-line no-undef
const encoder = new TextEncoderStream();

ethers js exits with this error=> invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.5.0)

I tried to send a request to my contract using ethersjs like this:
const web3Modal = new Web3Modal()
const connection = await web3Modal.connect()
const provider = new ethers.providers.Web3Provider(connection)
const signer = provider.getSigner()
const contract = new ethers.Contract(Contract, Market.abi, signer)
const price = ethers.utils.parseUnits(price.toString(), 18)
//const price = web3.utils.toWei(nft.price);
//const price = ethers.BigNumber.from(nft.price.toString()).toHexString();
const transaction = await contract.createSale(address, price)
await transaction.wait()
This code shows an error, I have tried all the solutions in this world, but nothing worked. => versions: nodejs 14.15, npm 8, web3 1.6, ethers 5.5
Any help?
Unhandled Rejection (Error): invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.5.0)
It looks like your price variable has the value undefined when you call createSale, resulting in an error.
Your issue is similar to: https://ethereum.stackexchange.com/questions/111042/cant-send-ether-to-smart-contract-using-ethers-js
When I connect to metamask in my frontend, the below error was happened.
invalid BigNumber string (argument="value", value="1.2e+21", code=INVALID_ARGUMENT, version=bignumber/5.5.0)
I have fixed it with bignumber in ethers.
If you are using web3.js version : 1.5.1, please try it in this way.
And also in other version you can try to use bignumber.js and web3.utils.toBn.
import { BigNumber} from 'ethers';
....
const decimals = 18;
const trans_amount = 1500;
const amount= BigNumber.from(trans_amount).mul(BigNumber.from(10).pow(decimals));

i m trying to run a command Discord.js but error appear "TypeError: Cannot read property 'get' of undefined"

below there is a code hope someone helps me :)
i tried to search on google but didnt find any solutions
const { MessageEmbed } = require("discord.js");
module.exports.run = async (bot, message, args) => {
const snipes = bot.snipes.get(message.channel.id) || [];
const msg = snipes[args[0] - 1 || 0];
if (!msg) return message.channel.send(`That is not a valid snipe...`);
const Embed = new MessageEmbed()
.setAuthor(
msg.author.tag,
msg.author.displayAvatarURL({ dynamic: true, size: 256 })
)
.setDescription(msg.content)
.setFooter(`Date: ${msg.date} | ${args[0] || 1}/${snipes.length}`);
if (msg.attachment) Embed.setImage(msg.attachment);
message.channel.send(Embed);
},
module.exports.help = {
name: "snipe",
}
it is normal for you to attach the error's location (usually in the form error: 53,23 so users can find it more easily.
First of all, undefined errors are the most common errors you will get (please read). They occur when you either havent declared a variable, or a method you have used is incorrect. In this case, I believe it is coming from this line:
const snipes = bot.snipes.get(message.channel.id) || [];
I don't know what snipes is but in v12 we use cache, and #get is out of use as per (also read)
If I knew what snipes was I could tell you what the right code is, but I do not. Please use the info attached to see if you can solve the issue.

"cannot read property "id" of null node js

i am trying to convert my old discord bot from node js 6.x.x to 8.x.x, i am also putting the commands in a separate folder to make it look cleaner, the command works on my old bot but not with this bot, i get
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'id' of null
UPDATED CODE STILL RETURNS THE SAME:
var settings = '../settingsConfig/settings.json';
var file = require(settings)
const SteamTotp = require('steam-totp');
const Discord = require('discord.js');
const configS = require('../settingsConfig/ConfigSammy.json');
const configJ = require('../settingsConfig/ConfigJack.json');
const configB = require('../settingsConfig/ConfigBen.json');
module.exports.run = async (bot, message, args) => {
function myFunc(){
var JackCode = SteamTotp.getAuthCode(configJ.sharedSecret);
var BenCode = SteamTotp.getAuthCode(configB.sharedSecret);
var SammyCode = SteamTotp.getAuthCode(configS.sharedSecret);
var codess = new Discord.RichEmbed()
.addField("__**Bens Code:**__", BenCode)
.addField("__**Jacks Code:**__", JackCode)
.addField("__**Sammys Code:**__", SammyCode)
.setColor(0x00FF00)
message.author.send(codess)
}
new myFunc();
};
module.exports.help = {
name: "codes"
}
Looks like the error comes from having message.guild not being defined, there for calling message.guild.id yields the error
The reason you're getting this specific error is since you are using the async keyword, which basically means you are using a promise, but you don't provide a reject method for it, hence UnhandledPromiseRejectionWarning
The error may occur because your MongoDB would not be connected. Try to repair it while installing MongoDB.

Categories