Solana Web3.js: Getting `null` for Mint account, althought it should return an `AccountInfo` object - web3js

When I run connection.getAccountInfo(watermelonMint.key); I get a null object, although it should return an AccountInfoObject. Any idea why this is the case? When I look for the address associated with this mint on solana explorer, I get normal statistics (https://explorer.solana.com/address/7vLEZP5JHhKVg3HEGSWcFNaxAKg7L633uMT7ePqmn98V?cluster=devnet)
console.log("Watermelon mint is: ");
console.log(watermelonMint);
returns
Mint {conn: Connection, key: PublicKey}
conn: Connection {_commitment: undefined, _confirmTransactionInitialTimeout: undefined, _rpcEndpoint: 'https://api.devnet.solana.com', _rpcWsEndpoint: 'wss://api.devnet.solana.com/', _rpcClient: ClientBrowser, …}
key: PublicKey
_bn: BN {negative: 0, words: Array(11), length: 10, red: null}
[[Prototype]]: Struct
[[Prototype]]: Object
any idea what could cause this?
Update 1:
basically, Token.getMintInfo(); keeps failing
const token = new Token(conn, mint, TOKEN_PROGRAM_ID, {} as any)
console.log("Getting token: ", token);
let out: Promise<MintInfo> = token.getMintInfo();
console.log("Out is: ", out);

Most likely, mint in "Update 1" is incorrect, or that your connection is improperly defined somewhere. Can you double-check that mint is equal to PublicKey("7vLEZP5JHhKVg3HEGSWcFNaxAKg7L633uMT7ePqmn98V")?
Also, can you make sure to await the response from token.getMintInfo()?

Related

Typescript Error: Argument of type 'NodeListOf<HTMLInputElement> | undefined' is not assignable to parameter of type 'Iterable<HTMLInputElement> ..."

In my React/Typescript App, I am accessing an array of inputs in an event listener through using 'e.currentTarget'. I am using Array.from() to convert the NodeListOf into an array, and made sure to configure my TS.config.json settings of 'es2015'. However I'm receiving this error.
Error
Oddly, this error doesn't occur in my original directory. I had duplicated my project folder, deleted node modules, zipped it, and reopened it, and that's when this error occurs. Not quite sure how else to approach this issue, if anyone has suggestions or solutions, it'd be appreciated.
e: React.ChangeEvent<HTMLInputElement> | React.KeyboardEvent<Element>,
letter: string,
idx: number,
) => {
const fields: HTMLInputElement[] = Array.from(
e.currentTarget.parentElement?.parentElement?.querySelectorAll('input')
)
const length: number = fields.length
const position: number = fields.indexOf(e.target)
You didn't provide much code, but my guess is this is happening because e.currentTarget.parentElement?.parentElement?.querySelectorAll('input') could potentially be undefined. undefined cannot be used as the argument for Array.from, as undefined is not iterable. You need to make sure it exists before you feed it to Array.from. Two possible solutions:
Check that the NodeList you're targeting really exists, then assign your variable
if (document.querySelector('.maybe')?.parentElement?.querySelectorAll('.doesnt-exist?')) {
const fields = Array.from(document.querySelector('.maybe')!.parentElement!.querySelectorAll('.doesnt-exist?'))
}
Assign your potential NodeList to a variable, but default it to [], just in case. Autocast that variable as an HTMLInputElement[], and then it can be safely used in Array.from:
const checker =
document.querySelector('.maybe')?.parentElement?.querySelectorAll('.doesnt-exist?') ?? [] as HTMLInputElement[]
const fields: Element[] = Array.from(checker)
TS Playground

GraphQL error: Expected type Int. Int cannot represent non-integer value

I'm currently learning GraphQL with Apollo for React and I have a question that I can't find the answer online:
I've done a form to send data for my mongoDB and I have this query:
const addContactMutation = gql`
mutation($name: String!, $address: String!, $vat: Int!, $zip: String!, $email: String!, $contact: Int!){
addContact(name: $name, address: $address, vat: $vat, zip: $zip, email: $email, contact: $contact){
name
vat
email
}
}
`
However, my $vat and $contact are big numbers and when submit the form I receive this error:
Variable "$vat" got invalid value "232214336"; Expected type Int. Int cannot represent non-integer value
Which type should I use for that?
232214336 is not so big, the max int number is 9007199254740991
console.log(Number.MAX_SAFE_INTEGER);
I think the problem is you've passed a string value "232214336" when an Int value is expected as the error says Expected type Int, so you need to convert the value to an integer before or when passing variables to the mutation using parseInt()
addContact({ variables: { vat: parseInt(vat, 10), contact: parseInt(contact, 10), ... } })
This error also happens when a database field that is typed as an integer, contains a value of NULL, and that field is returned by your GraphQL query. One way to fix this, is to set up your database to give integer fields a default value so that they are never NULL when the row is created.
I faced this problem before and I resolved it by :
first I checked if the order of types in the front-end is the same as in graphql-types
then
in the input form I replaced: target.value
by: target.valueAsNumber
I also encountered a similar and weird kind of issue, as types were mentioned clearly but that wasn't accepted in variables by graphql-request version 3.1.4, I mapped them again in a variable that is working at my end so far.
const variables = {
orderId: +orderId,
vendorIds: vendorIds.map(id => +id),
};
I got the same error in my Grapql+NestJs application. What I did is changed the graph field type from Int to Float. It works

Error in JSON.parse() (when called from API Gateway)

I'm working on AWS lambda + API Gateway, and I need to pass an array of numbers in the url (GET method) for a REST call. It seems a good way is to pass the numbers as string (comma separated) and then use JSON.parse for the conversion to an array of numbers.
Following is the AWS lambda code I'm using;
exports.handler = (event, context, callback) => {
var arr = JSON.parse('[' + event.numbers + ']');
console.log("array: " + arr);
// TODO implement
callback(null, 'Hello from Lambda');
};
I'm testing this function in AWS Lambda using this Input test event;
{
"numbers": "1,5"
}
And everything works as expected; no errors.
However, when I test it via API Gateway, and passing the numbers as string in the query, I get following error (observed via CloudWatch);
*19:19:02
START RequestId: eabab882-8cee-11e7-8e2f-79d3086e061f Version: $LATEST
19:19:02
2017-08-29T19:19:02.688Z eabab882-8cee-11e7-8e2f-79d3086e061f SyntaxError: Unexpected token u in JSON at position 1 at Object.parse (native) at exports.handler (/var/task/index.js:4:20)
19:19:02
END RequestId: eabab882-8cee-11e7-8e2f-79d3086e061f
19:19:02
REPORT RequestId: eabab882-8cee-11e7-8e2f-79d3086e061f Duration: 215.25 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 18 MB
19:19:02
RequestId: eabab882-8cee-11e7-8e2f-79d3086e061f Process exited before completing request*
This is the request passed to lambda as shown in the log;
"body-json" : {},
"params" : {
"path" : {
}
,"querystring" : {
"numbers" : "1,6"
}
,"header" : {
}
},
"stage-variables" : {
},
I can't figure out what the problem is, since I'm passing same string in both cases.
I would appreciate any help.
Thanks
Gus
With this input json informed, you need to get it like this:
var arr = JSON.parse('[' + event.params.querystring.numbers + ']');
rather than:
var arr = JSON.parse('[' + event.numbers + ']');
Or make a body mapping template to stay the way you want:
{ "number": "$input.params('number')" }
http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
I hope I have helped!

whisper on private network. subscribe error

I'm use THIS GUIDE for start Testing the Whisper node (geth) on private network.
Version Geth: /v1.6.7-stable-ab5646c5. Version Whisper: 5.
Start with this command :geth --shh --testnet --nodiscover console.
Connect to the test node: admin.addPeer("enode://d25474361659861e9e651bc728a17e807a3359ca0d344afd544ed0f11a31faecaf4d74b55db53c6670fd624f08d5c79adfc8da5dd4a11b9213db49a3b750845e#52.178.209.125:30379")
In answer get true
Try Case Receive Asymmetrically Encrypted Messages
Generate a key pair, and save its ID.
> id = shh.newKeyPair()
"f87747702c8d4dc9b9abf889e77ca9bf36d9f87b23fcc3ed09ff1976e52ce4d3"
Retrieve and save public key.
> shh.getPublicKey("f87747702c8d4dc9b9abf889e77ca9bf36d9f87b23fcc3ed09ff1976e52ce4d3")
"0x04ea9a8e0fc1d831e4dc094e2769989a82f3094ff774e133ec733cf9940b7c73792ab634883ef1cdf17be2f6081571dbac98c2c73e3362420e6ab53c7687a82079"
And try subscribe to messages, encrypted with certain public key.
> f = shh.subscribe({type: 'asym', key: id})
Error: Invalid number of input parameters
at web3.js:3094:20
at web3.js:4931:15
at web3.js:4974:5
at web3.js:4998:23
at <anonymous>:1:5
Parameters for Subscribe:
type string
key string
sig string
minPoW float64
topics [][]byte
allowP2P bool
Create Public Key for sig:
> var pubk = shh.getPublicKey(id)
And try this command:
> f = shh.subscribe({type: 'asym', key: id, sig: pubk, minPoW: 1, topics: ['0x07678231'], allowP2P: true})
Error: Invalid number of input parameters
at web3.js:3094:20
at web3.js:4931:15
at web3.js:4974:5
at web3.js:4998:23
at <anonymous>:1:5
But I get the same error. Internet search on this error did not yield results. How to fix this behavior?

angularjs service doesn't see array

I'm trying to build a forum. I have a service and when i do console.log() on the service I see this
Constructor {page: "thread", showReplyForm: false, newPosts: Array[0], boardID: null, threadID: "24"}
boardID: null
newPosts: Array[1]
created: 1412040853
id: "56"
message: "test22"
score: 0
why is it that on top it says newPosts: array[0]
but when i expand it underneath, it says newPosts: array[1]
Also when I do service.newPosts.length, I get 0. How do I see that 1? I can't paste the rest of the code here because it's too long.

Resources