Add Meta Data To Solana Token with #solana/web3.js - javascript

I am trying to create an NFT using web3.js and spl-token.js.
However, i need to add meta data (like the name of the token or other attributes), otherwise it just shows up as "Unknown Token" in my wallet.
This is the relevant part of the code where I am minting the token:
let mint = await splToken.Token.createMint(
connection,
fromWallet,
fromWallet.publicKey,
null,
0,
splToken.TOKEN_PROGRAM_ID
);
Otherwise the code is similar to the answers on this question: I would like to mint a new token on solana. How can I do this using solana-web3.js?
There does not seem to be any documentation whatsoever, except for the structure of the meta data (which I found here: https://docs.phantom.app/integrating/tokens/on-chain-metadata).
If anyone could point me in the right direction with an example or documentation it would be really much appreciated. Thank you!

In order to add metadata to NFT you need to invoke this program spl_token_metadata::instruction::create_metadata_accounts. You can find the documentation here.
PS: The example above is in Rust. To do it in JavaScript is like that:
import { Metaplex, keypairIdentity } from "#metaplex-foundation/js";
const metaplex = new Metaplex(connection);
metaplex.use(keypairIdentity(keypair));
const mintNFTResponse = await metaplex.nfts().create({
uri: "https://ffaaqinzhkt4ukhbohixfliubnvpjgyedi3f2iccrq4efh3s.arweave.net/KUAIIbk6p8oo4XHRcq0U__C2r0mwQaNl0gQow4Qp9yk",
maxSupply: 1,
});
Like described here is another exemple.

Create a metadata for an NFT token in Solana is quite complicated. It is because in Solana SPL-token account would not carry the Metadata. Instead, you have to create another account to carry such data. So, I suggest you to use Metaplex's Candy Machine to make your own NFT with Metadata. You may get more information from their github:
https://github.com/metaplex-foundation/metaplex/

Related

Error with AWS SDK-JS API when Retrieving Seller Partner Product Catalog Inventory

I need to retrieve the product catalog of my seller partner on Amazon. Although the API refers to this as "Inventory," I couldn't find this term in the SDK documentation. I assume that the "Catalog" namespace is the equivalent.
Update:
My custom application requires a list of the following product values:
ASINs
UPCs
SKUs
FNSKUs
I have read the documentation and found an API that returns what I need, which can be found here:
https://developer-docs.amazon.com/sp-api/docs/fba-inventory-api-v1-use-case-guide
According to the documentation, I need to create a signature in order to use the API. However, it is noted that if I use the AWS SDK, I do not need to calculate the signature myself. Therefore, I understand that the best practice is to use the AWS SDK.
I have the necessary IAM role permissions and the SP-API app has been published. I am currently attempting to use the AWS SDK.
I have made some changes based on recommendations, but I am not completely sure what else I need to do. Here is my current code:
```
export const /*bundle */ start = async () => {
const client = new MarketplaceCatalogClient({
region: REGION,
credentials: {
accessKeyId: ACCESS_KEY_ID,
secretAccessKey: ACCESS_SECRET_KEY,
},
});
const params = {
/** input parameters */
};
const answer = await client.send(
new ListEntitiesCommand({ Catalog: "AWSMarketplace", EntityType: "ContainerProduct" })
);
console.log(100, answer);
return answer;
};
```
I got the next answer with "AmiProduct" or "ContainerProduct":
{
'$metadata': {
httpStatusCode: 200,
requestId: '91fc5fed-6cdc-42d6-97ec-1ed3cc9d5796',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
EntitySummaryList: []
}
I'm having difficulty understanding how to correctly implement this. Any guidance would be greatly appreciated.
The docs should be better. I spent a good 15 mins on the docs at https://docs.aws.amazon.com/marketplace-catalog/latest/api-reference/welcome.html and failed to find a full list of valid EntityType values.
Some EntityType values are documented here: https://docs.aws.amazon.com/marketplace-catalog/latest/api-reference/seller-products.html
AmiProduct
ContainerProduct
It looks like these types correspond to the product types in the index of the seller guide here -> https://docs.aws.amazon.com/marketplace/latest/userguide/machine-learning-products.html. It's not clear what the other valid values are.
Some other EntityType values are documented here: https://docs.aws.amazon.com/marketplace-catalog/latest/api-reference/private-marketplace.html
Experience
Procurement Policy
It looks the way to go for now is to scrounge these valid values from examples in the docs https://docs.aws.amazon.com/marketplace-catalog/latest/api-reference/welcome.html. Not the best developer experience :grimace:
Assuming you are a seller, that you have registered successfully with your AWS account. You can then use Marketplace APIs.
To use them, you have to create an IAM role or a user with policies to grant access to invoke the selected APIs like listEntities, describeEntity, etc.
Here I again assume you have the Cognito authorized credentials if using AWS SDK.
Now to view the list of products successfully published, you use listEntites command.
You can only view AMI or Containter product types. Read here.
It uses minimum two required parameters Catalog and EntityType. The former has a fixed value AWSMarketplace, and latter can have a value either AmiProduct or ContainerProduct.
To get a detailed information about a specific product, you use describeEntity command. It takes minimum 2 required parameters Catalog and EntityID.
The former again has a fixed value AWSMarketplace. For latter, you'll obtain it from the listEntites response.

Can you call a Solidity contract method with only Metamask?

I’m wanting to use Metamask in my app to let users pay a fixed ETH fee (plus gas) to call a method from my Solidity contract. I looked at the Metamask documentation and the eth_sendTransaction method seems close to what I need; eth_sendTransaction would certainly allow me to request ETH from a user, but the “data” parameter is a bit confusing.
The Metamask docs say:
data is optional, but used for defining smart contract creation and interaction
and
also used for specifying contract methods and their parameters.
So “data” represents my method and its parameters, but how does Metamask (or window.ethereum, rather) know the contract whose methods I’m trying to call?
Don’t you normally have to provide a contract address and ABI/JSON in order to interact with a deployed contract? In short, is it possible to do what I’ve described with just Metamask alone? Or do you have to do other client-side setups in order to call a method with eth_sendTransaction?
Edit: by the way TylerH, the answer involved using web3.js. Maybe don't edit people's posts unless you know what the hell you're talking about. Just a thought...
Yes you will need the contract abi in order to get the information you need to include in the data that you're passing to the contract. There are also a few other things that you will need to accomplish this:
First you will need to make sure you download the ethers.js, and #alch/alchemy-web3 npm libraries into your application. Secondly you will need a provider API key from a platform like Alchemy in order to communicate with the contract abi. Lastly, you will need the contract abi which can be found at the bottom of the contract section of etherscan. There is plenty of information on how to obtain these things online, so I won't go over how to configure them here.
Once you have these, you are ready for the next step.
I suggest creating this in a utilities file somewhere in your applications file system, but the idea is this:
const alchemyKey = process.env.ALCHEMY_KEY;
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS;
const { createAlchemyWeb3 } = require("#alch/alchemy-web3");
const web3 = createAlchemyWeb3(alchemyKey);
const contractABI = require('../contract-abi.json');
export const contract = new web3.eth.Contract(contractABI, CONTRACT_ADDRESS);
export const yourMethod = () => {
if(window.ethereum.request({method: 'eth_requestAccounts'})){
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const address = await signer.getAddress();
const tx = {
from: address,
to: CONTRACT_ADDRESS,
value: "some wei value", // this is the value in wei to send
data: contract.methods.YOUR_CONTRACT_METHOD_HERE().encodeABI()
}
const txHash = await window.ethereum.request({
method: 'eth_sendTransaction',
params: [tx]
});
// do something with your transaction hash here
console.log({txHash});
}else{
console.log('user must connect wallet');
}
}
So the value that is populated in the data field of our transaction comes from calling the method that we are trying to invoke in our contract. This is encoded, and then we pass this information along with the rest of our transaction data.
This is a very short and brief description as to what this does, and I hope this is what you're looking for. If you need any more help I'm always available to chat on Twitter #_syndk8.

What is the Correct Way to Use Secret Manager in Firebase Cloud Function?

I started to add Secret Manager with a SECRET_NAME contains a certain password inside Cloud Function using Node.js. I tried both ways. First, adding Secret Manager using Console and another, adding Secret Manager directly through Firebase CLI. Unfortunately, both ways give an empty Secret value in Cloud Function variable of Secret as shown in picture below.
I used parameter runWith({secret: ["SECRET_NAME"]}) as shown in code below.
exports.Auth = functions.runWith(secret).https.onCall(async (data, context) => {
const response = 129132;
return Promise.resolve(response);
});
const secret = {
timeoutSeconds: 120,
memory: "1GB",
secret: ["SECRET_NAME"],
minInstances: 0,
};
I followed the documentation written in Firebase Cloud Function (https://firebase.google.com/docs/functions/config-env).
I had wasted almost a week to figure out where I got wrong and found nothing. I also added a role "Secret Manager Secret Accessor" to current SECRET_NAME in Google Cloud Console, and it gave result to nothing at all. As written in this stackoverflow post reference
My question is should I add SECRET_NAME manually in Cloud Function Console in Google Cloud Platform? If so, then what is the use of documentation written above? Is Firebase trying to lead us to nowhere?
I am sorry guys.
Apparently, I was wrong in writing the code:
const secret = {
timeoutSeconds: 120,
memory: "1GB",
secrets: ["SECRET_NAME"], //Must use secrets not secret
minInstances: 0,
};
Thank you, #MichaelBleigh.
Problem is now solved.

I need get a all transactions like mint , burn in web3

I need to get all transactions from aa address on bsc. I tried bscscan api but it doesn't give everything like burning minting actions, they just give transfers , how can I get all transactions with web3 js or web3 py. I would appreciate if someone can help me
You need scan all block and found that you need. This is very bad way.
Other way -- you can use API
check etherscan.io api you can get a list of all transactions easily as an alternative
https://etherscan.io/apis
http://api.etherscan.io/api?module=account&action=txlist&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken
and work with this answer.
This is easy way, but no easy way to get all transaction via web3js or web3py.
But if you need only specified events -- that was much easy.
you need function getPastEvents
const START_BLOCK = 7700000;
const END_BLOCK = 7701000;
contract.getPastEvents("allEvents",
{
fromBlock: START_BLOCK,
toBlock: END_BLOCK // You can also specify 'latest'
})
.then(events => console.log(events))
.catch((err) => console.error(err));
You can set mint or burn events only.
https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#getpastevents

What scope is required to access the list of AzureAD groups via MS Graph API?

I am trying to add a feature to a MS Graph API app written in Node.JS. The app was built from a Microsoft template. The app needs to fetch a list of Azure AD groups whose names begin with a prefix. I am having trouble getting it to work.
I copied this working code:
const client = graph.Client.init({...});
const events = await client
.api('/me/events')
.select('subject,organizer,start,end')
.orderby('createdDateTime DESC')
.get();
...and changed the api query according to the documentation I found. I have commented out the filter just to try to get the basic query to work.
const client = graph.Client.init({...});
const events = await client
.api('/groups')
.select('id,displayName')
// .filter("startsWith(displayName,'Prefix')")
.get();
But the query returns this error:
GraphError {
statusCode: 403,
code: 'Authorization_RequestDenied',
message: 'Insufficient privileges to complete the operation.',
requestId: 'f5330dbd-c7a9-4126-a227-10a656a11083',
date: 2020-07-10T22:25:24.000Z,
body: '{"code":"Authorization_RequestDenied"...}'
}
I'm not 100% certain the URI is correct. I would expect a 404 if the URI was wrong, but that may be expecting too much. Perhaps this /group API does not correlate to Azure AD groups.
OTOH, do I need to add a new scope to request access to the group information? The current scope list used by the application looks like this:
OAUTH_SCOPES='profile offline_access user.read calendars.read'
I have not found a reference for graph queries and scopes for Azure AD. I tried adding 'groups.read' to the list of scopes, but that did not work.
I would appreciate not only an answer, but link to documentation as well. I have to add a few other features from Azure AD.
The least to most privileged Permission for querying Groups is Group.Read.All as per your linked document. https://learn.microsoft.com/en-us/graph/api/group-list?view=graph-rest-1.0&tabs=javascript#permissions

Categories