why am I getting an invalid token standard error? - javascript

I want to update the metadata of an NFT using metaplex js library,
I followed the docs but I keep gettin an invalid token standard error.
const new_uri = await metaplex.nfts().uploadMetadata(
uri_obj,
)
await metaplex.nfts().update({
nftOrSft: nft,
uri:new_uri.uri
});
I created a new storage unit in airweave and got it's url but I keep getting the error
and not just on the url but when I try to change the name for testing purposes aswell.
full error:
return resolvedError ? new ProgramError.ParsedProgramError(program, resolvedError, error.logs) : new ProgramError.UnknownProgramError(program, error);
^
ParsedProgramError: The program [TokenMetadataProgram] at address [metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s] raised an error of code [135] that translates to "Invalid token standard".
Source: Program > TokenMetadataProgram [metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s]
Caused By: InvalidTokenStandard: Invalid token standard
Program Logs:
| Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]
| Program log: Instruction: Token Metadata Update
| Program log: Invalid token standard
| Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 18628 of 200000 compute units
| Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x87
here is the uri_object that I'm using
{
name: 'Suteki #467',
symbol: 'TEKI',
description: "Suteki is a unique collection of 6000 anime PFP's that focus on community building and creating real-world value. Claim your Buzoku (tribe), follow the lore and work up the ranks of the hierarchy to become a Oyabun (Family boss).",
seller_fee_basis_points: 900,
image: 'https://bafybeifsrfzvrms7ptbuv2pjhg3a5lr6waxhd6qyjzpm3ynogs3cbvfcdq.ipfs.nftstorage.link/467.png?ext=png',
attributes: [
{ trait_type: 'Background', value: 'Sand' },
{ trait_type: 'Type', value: 'Light Scar' },
{ trait_type: 'Tattoo or Scar Small', value: 'Mouth Scar' },
{ trait_type: 'Tattoo or Scar Large', value: 'Suteki Faction' },
{ trait_type: 'Mouth', value: 'Smile' },
{ trait_type: 'Eyes', value: 'Blue' },
{ trait_type: 'EyeBrows', value: 'Raised Right' },
{ trait_type: 'Clothes', value: 'Spike Blazer' },
{ trait_type: 'Mask', value: 'Cloth Wrap Blizzard' },
{ trait_type: 'Hair', value: 'Blue Comb Over' },
{ trait_type: 'Rank', value: 'Shatei (Little Brother)' },
{ trait_type: 'Buzoku', value: 'Akamatsu' }
],
properties: {
category: 'image',
files: [ [Object] ],
creators: [ [Object], [Object] ]
},
collection: { name: 'Suteki', family: 'Suteki' }
}

Related

Dynamically add values to specific property in object - Fluent UI React ContextualMenu

I have the following ContextualMenu structure inside my SPFx Extension build with Fluent UI React:
const menuProps: IContextualMenuProps = {
items: [
{
key: 'Access',
itemType: ContextualMenuItemType.Section,
sectionProps: {
topDivider: true,
bottomDivider: true,
title: 'Sites you have access to',
items: [
{ key: 'DynamicValue1.1', text: 'DynamicValue1.2' },
{ key: 'DynamicValue2.1', text: 'DynamicValue2.2' },
],
},
},
],
};
I also a MS Graph call running getting me some SharePoint Sites & Teams.
I would now like to push those dynamic responses to the to the menuProps at the right place.
So basically add the dynamic array into the nested items object.
items: [
{ key: 'DynamicValue1.1', text: 'DynamicValue1.2' },
{ key: 'DynamicValue2.1', text: 'DynamicValue2.2' },
],
How can I target that "object"? (hope I understand correctly and items is an object...)
Is there a way to do this using array.push()?
To make this library agnostic, it would look something like this:
const obj = {
items: [
{
key: 'Access',
itemType: '',
sectionProps: {
topDivider: true,
bottomDivider: true,
title: 'Sites you have access to',
items: [
{ key: 'DynamicValue1.1', text: 'DynamicValue1.2' },
{ key: 'DynamicValue2.1', text: 'DynamicValue2.2' },
],
},
},
],
};
obj.items[0].sectionProps.items.push({ key: 'DynamicValue3.1', text: 'DynamicValue3.2' })
console.log(obj.items[0].sectionProps.items)
Your console.log would return this:
[
{ key: 'DynamicValue1.1', text: 'DynamicValue1.2' },
{ key: 'DynamicValue2.1', text: 'DynamicValue2.2' },
{ key: 'DynamicValue3.1', text: 'DynamicValue3.2' }
]
If you can access menuProps: IContextualMenuProps, then just replace obj with the necessary variable.

How to transform only 2 properties but keep remaining same as is in a nested object structure?

Apologies if title is not clear.
I am using json2csv npm package to prepare csv from json object and this package allows us to add a hook to transform object before actual csv line is prepared.
I only need to manipulate two properties out of all. How can I do this effectively? My code feels too bloated.
const {
Parser: Json2csvParser,
transforms: { unwind },
} = require('json2csv');
const json2csvFields = [
{ value: 'root.filename', label: 'File Name' },
{ value: 'issue.root.priority', label: 'Priority' },
{ value: 'issue.root.url', label: 'URL' },
{ value: 'issue.root.startline', label: 'Start Line' },
{ value: 'issue.root.stopline', label: 'Stop Line' },
{ value: 'issue.root.startcolumn', label: 'Start Column' },
{ value: 'issue.root.stopcolumn', label: 'Stop Column' },
{ value: 'issue.root.issuename', label: 'Issue Name' },
{ value: 'issue.root.issuecategory', label: 'Issue Category' },
{ value: 'issue._', label: 'Issue Description' },
];
const sampleData = [
{
root: {
filename:
'/home/users/john-doe/workspace/foo-project/src/main/classes/foo.cls',
},
issue: {
root: {
priority: 1,
url: 'www.example.com',
startline: 100,
stopline: 105,
startcolumn: 20,
stopcolumn: 25,
issuename: 'blah',
issuecategory: 'Category A',
},
_: ' Fox ',
},
},
];
const json2csvOptions = {
fields: json2csvFields,
quote: '',
header: true,
transforms: [
(item) => ({
'root.filename': item.root.filename.replace(
'/home/users/john-doe/workspace/foo-project/src/main/classes/',
''
),
'issue._': `"${item.issue._.trim()}"`,
// Except for the above two, everything else doens't need any transformation.
'issue.root.priority': item.issue.root.priority,
'issue.root.url': item.issue.root.url,
'issue.root.startline': item.issue.root.startline,
'issue.root.stopline': item.issue.root.stopline,
'issue.root.startcolumn': item.issue.root.startcolumn,
'issue.root.stopcolumn': item.issue.root.stopcolumn,
'issue.root.issuename': item.issue.root.issuename,
'issue.root.issuecategory': item.issue.root.issuecategory,
}),
],
};
const json2csvParser = new Json2csvParser(json2csvOptions);
const csv = json2csvParser.parse(sampleData);
console.log(csv);
This prints below output:
File Name,Priority,URL,Start Line,Stop Line,Start Column,Stop Column,Issue Name,Issue Category,Issue Description
foo.cls,1,www.example.com,100,105,20,25,blah,Category A,"Fox"
EDIT: Updated code to a working example.
After listing the two properties with special treatment, use Object.fromEntries and Object.entries to transform all the issue.root properties to their flat structure with .s in the property names. Then that object can be spread into the returned object.
const transformsFn = ({ root, issue }) => ({
'root.filename': root.filename.replace(
'/home/users/john-doe/workspace/foo-project/src/main/classes/',
''
),
'issue._': `"${issue._.trim()}"`,
...Object.fromEntries(
Object.entries(issue.root).map(
([key, val]) => [`issue.root.${key}`, val]
)
),
});
const json2csvOptions = {
fields: json2csvFields,
quote: '',
header: true,
transforms: [transformsFn],
};

DiscordJS v13 Invalid Form Body

I am trying to make a toggle able slash command, if they pick the disable option it turns it off but when if you pick the enable option it asks to pick a channel but it gives this error
Error:
DiscordAPIError[50035]: Invalid Form Body
23.name[BASE_TYPE_REQUIRED]: This field is required
rawError: {
code: 50035,
errors: { '23': [Object] },
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'put',
url: 'https://discord.com/api/v9/applications/971024098098569327/commands'
Code:
module.exports = {
name: 'welcomer',
permissions: 'MANAGE_CHANNELS',
description: 'Set Where Welcome Messages Get Sent To.',
options: [
{
name: 'toggle',
description: 'Toggle On/Off The Welcomer',
type: 3,
required: true,
choices: [
{
name: 'disable',
value: 'off',
},
{
name: 'enable',
value: 'on',
choices: [
{
name: 'channel',
description: 'Select channel to send welcome messages to',
type: 7,
required: true,
},
]
},
],
},
],
Those would be an example of a subcommand and need to be indicated as such and will need descriptions in a couple places.
module.exports = {
name: 'welcomer',
permissions: 'MANAGE_CHANNELS',
description: 'Set Where Welcome Messages Get Sent To.',
options: [{
name: 'disable',
description: `'Disable welcomer`, // Added needed description
type: 1, //converted to subcommmand
}, {
name: 'enable',
description: `'Enable welcomer`, // Added needed description
type: 1, //converted to subcommmand
options: [{
name: 'channel',
description: 'Select channel to send welcome messages to',
type: 7,
required: true,
channel_types: [0] // allows only text channels to be selected
}]
}],
// run command pick only one of the below two
// if command.execute()
async execute(client, interaction, args)
// if command.run()
run: async (client, interaction, args) =>
// command code below here assumes you have the code in your `interactionCreate` listener to set up args
{
if (args.disable) {
// Code to turn off
} else if (args.enable) {
const channel = args.channel
// Code to turn on
};
}
}

RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty

I have this code, and I keep getting this error:
RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty.
at Object.run (C:\Users\Sochum\Desktop\BobloxBot\commands\GroupStats.js:41:2)
Line 41 has this code: .addFields(
Here is the code:
const embed = new Discord.MessageEmbed()
.setTitle(`${groupname}`)
.addFields(
{ name: `🤴 Group Owner`, value: `<#${owner}>` },
{ name: `👑 Group Co-Owner`, value: `<#${co_owner}>` },
{ name: `🚹 Member Count`, value: `${membercount}` },
{ name: `💰 Group Funds`, value: `${funds}` },
{ name: `📦 Group Items`, value: `${group_items}` },
{ name: `🎂Group Birthday`, value: `${Group_Bday}` },
{ name: `🤝Group Sharing Circle`, value: `${sharing_circle}` },
{ name: `📈Group Warwins`, value: `${Group_Warwins}` },
{ name: `📉Group Warlosses`, value: `${Group_Warlosses}` },
)
message.channel.send(embed)
I can't seem to find a problem anywhere, so I am not sure why I am getting this error
I've ran your code and it works fine for me. This error happens when one of the field value is empty, so be sure that all your variables are defined and that they can be read inside of a string.

Is it possible to query JSON data from amazon Dynamodb using javascript SDK

I need help on amazon Dynamo. I am looking to special query in dynamodb
my JSON looks below
{
blocknumber: '20',
BusinessData: {
BASE_UNIT: 'kg',
FARMERID: 'FAINKABR0001',
FARMLOCATION: 'Farm 3927',
GAPINFO: {},
PLANTINGDATE: '2020-11-02T18:30:00.000Z',
PRODUCEQUANTITES: [
{
name: 'Priya',
qty: 200
}
],
SELECTED_UNIT: {
NAME: 'kg'
}
},
chaincodeID: 'producechaincode',
docType: 'Produce',
PRID: 'PRFAINKABR0007',
PRODUCE: 'Sweetcorn',
STATUS: 'Approved',
timestamp: '2020-12-06T13:03:08.857Z'
}
I would like to query all Data(Produce) where FARMERID is 'FAINKABR0001'.
I went through all of the examples but it seems that I can query only on hash key, sort key and using GSI.
Can we query it using Javascript SDK of AWS?
Thanks in advance
The Query operation in DynamoDB finds items based on primary key values. You can query any table or secondary index (GSI) that has a composite primary key (a partition key and a sort key).
Now for your question, you have two options:
Option 1
Make FARMERID as your GSI
Option 2
Use Scan method and filter the result
Now you will need to do cost evaluation based on your need. Each method has it's own pros and cons.
PFB some references:
Scan-JS SDK
Query-DDB
Based on comment, one approach could be
var data =
[
{
blocknumber: '20',
BusinessData: {
BASE_UNIT: 'kg',
FARMERID: 'FAINKABR0001',
FARMLOCATION: 'Farm 3927',
GAPINFO: {},
PLANTINGDATE: '2020-11-02T18:30:00.000Z',
PRODUCEQUANTITES: [
{
name: 'Priya',
qty: 200
}
],
SELECTED_UNIT: {
NAME: 'kg'
}
},
chaincodeID: 'producechaincode',
docType: 'Produce',
PRID: 'PRFAINKABR0007',
PRODUCE: 'Sweetcorn',
STATUS: 'Approved',
timestamp: '2020-12-06T13:03:08.857Z'
},
{
blocknumber: '20',
BusinessData: {
BASE_UNIT: 'kg',
FARMERID: 'FAINKABR0002',
FARMLOCATION: 'Farm 3927',
GAPINFO: {},
PLANTINGDATE: '2020-11-02T18:30:00.000Z',
PRODUCEQUANTITES: [
{
name: 'Priya',
qty: 200
}
],
SELECTED_UNIT: {
NAME: 'kg'
}
},
chaincodeID: 'producechaincode',
docType: 'Produce',
PRID: 'PRFAINKABR0007',
PRODUCE: 'Sweetcorn',
STATUS: 'Approved',
timestamp: '2020-12-06T13:03:08.857Z'
},
{
blocknumber: '20',
BusinessData: {
BASE_UNIT: 'kg',
FARMERID: 'FAINKABR0001',
FARMLOCATION: 'Farm 3927',
GAPINFO: {},
PLANTINGDATE: '2020-11-02T18:30:00.000Z',
PRODUCEQUANTITES: [
{
name: 'Priya',
qty: 200
}
],
SELECTED_UNIT: {
NAME: 'kg'
}
},
chaincodeID: 'producechaincode',
docType: 'Produce',
PRID: 'PRFAINKABR0007',
PRODUCE: 'Sweetcorn',
STATUS: 'Approved',
timestamp: '2020-12-06T13:03:08.857Z'
}
];
function filterResponse(data, id) {
for(var i = 0; i < data.length; i++) {
if(data[i].BusinessData.FARMERID === id ) {
console.log(data[i]);
}
}
}
filterResponse(data, "FAINKABR0001");
Thanks #Atul Kumar for Help I have also added my whole code my be in future somebody face same issue
Here FilterExpression as FilterExpression: "BusinessData.FARMERID = :farmeridvalue"
Here we need to give FilterExpression value which attribute we want to query i.e BusinessData.FARMERID and give one name as I give farmeridvalue now you have set ExpressionAttributeValues as search value for me as FAINKABR0001
see whole scan code as below
var params = {
TableName: "Your_tableName",
FilterExpression: "BusinessData.FARMERID = :farmeridvalue",
ExpressionAttributeValues: {
":farmeridvalue" :"FAINKABR0001"
}
};
docClient.scan(params, onScan);
function onScan(err, data) {
if (err) {
console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
} else {
// print all the movies
console.log("Scan succeeded.", data);
data.Items.forEach(function(Block) {
console.log( "result",
Block.docType + ": ",
Block.timestamp, "- rating:", Block.BusinessData.FARMERID);
});
// continue scanning if we have more movies, because
// scan can retrieve a maximum of 1MB of data
if (typeof data.LastEvaluatedKey != "undefined") {
console.log("Scanning for more...");
params.ExclusiveStartKey = data.LastEvaluatedKey;
docClient.scan(params, onScan);
}
}
}

Categories