bmresearch / solnet.metaplex Goto Github PK
View Code? Open in Web Editor NEWMetaplex Protocol .NET integration library.
License: MIT License
Metaplex Protocol .NET integration library.
License: MIT License
Given a token address , we would need to fetch the json metadata from the uri field of the metadata account data.
Maybe implement metadataJson as a class?
I am aware that there has not yet been released a version which takes into account certified collections. Anyway, I do plan to make the necessary adjustments to the existing code so as to allow creating a collection.
From my understanding, for creating a certified collection, the following are needed:
MetadataProgram.CreateMetadataAccount
function so as to also encode the collectionDetails
. However, I tried to change it according to the order, offsets and sizes of arguments listed here https://docs.metaplex.com/programs/token-metadata/instructions#create-a-metadata-account and I don't seem to manage to get it working. My modified version of MetadataProgram.CreateMetadataAccount
is:private static byte[] EncodeCreateMetadataAccountData(MetadataParameters parameters, int? collectionDetailsSize = null, bool isMutable = true)
{
byte[] bytes = Encoding.UTF8.GetBytes(parameters.name);
byte[] bytes2 = Encoding.UTF8.GetBytes(parameters.symbol);
byte[] bytes3 = Encoding.UTF8.GetBytes(parameters.uri);
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write((byte)0);
binaryWriter.Write(bytes.Length);
binaryWriter.Write(bytes);
binaryWriter.Write(bytes2.Length);
binaryWriter.Write(bytes2);
binaryWriter.Write(bytes3.Length);
binaryWriter.Write(bytes3);
binaryWriter.Write((ushort)parameters.sellerFeeBasisPoints);
int num;
if (parameters.creators != null)
{
List<Creator> creators = parameters.creators;
num = ((creators != null && creators.Count < 1) ? 1 : 0);
}
else
{
num = 1;
}
if (num != 0)
{
binaryWriter.Write((byte)0);
}
else
{
binaryWriter.Write((byte)1);
binaryWriter.Write(parameters.creators.Count);
foreach (Creator creator in parameters.creators)
{
byte[] buffer = creator.Encode();
binaryWriter.Write(buffer);
}
}
// collection - ADDED BY ME
binaryWriter.Write((byte)0);
// uses - ADDED BY ME
binaryWriter.Write((byte)0);
binaryWriter.Write(isMutable);
// - whole below if-else block ADDED BY ME
if (collectionDetailsSize != null)
{
binaryWriter.Write((byte)1);
byte[] collectionDetailsByteArray = new byte[8];
var collectionDetailsSizeBytes = BitConverter.GetBytes(collectionDetailsSize.Value);
collectionDetailsSizeBytes.CopyTo(collectionDetailsByteArray, 0);
binaryWriter.Write(collectionDetailsByteArray);
}
else
{
binaryWriter.Write((byte)0);
}
return memoryStream.ToArray();
}
I always get a deserialization exception from the on-chain program. I am using testnet at the moment. Can you help me get the encoding of the collectionDetails
right until the feature will be implemented in this repo? Also, as I am in the need of using this quite often, I will be delighted to also contribute to the project.
Thank you very much!
Implement the missing MetadataProgram instructions.
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
Describe alternatives you've considered
Hi. I was trying to update Metadata Account fields' value, but the following error shows up!
{"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid transaction: Transaction failed to sanitize accounts offsets correctly"},"id":2}
Could you provide me a sample?
Add new instructions ( v1.1.0 of Metadata program )
Hello,
Is there going to be a NuGet version bump after @BifrostTitan' latest merges? Last one was #47, but the NuGet package was lastly updated 4 months ago.
He did way too many amazing things to not get that in the NuGet package manager.
Thanks a lot @BifrostTitan!
I'm trying to replicate a metaplex v2 minting made with the metaplex js cli, here is a sample transaction: https://solscan.io/tx/2qgQRycQLf3mQi9QP1vMidod9XK1rWfhp9eDQss4ME1gFEuHVfWfDxuspsxdFBwf8no5xYj8Ly5H1MqZGntTbE8F?cluster=devnet
With the following solnet code I'm able to recreate it until the MintTo step:
var tokenAMint = new Account();
var fromAccount = new Account();
PublicKey associatedTokenAccount = AssociatedTokenAccountProgram.DeriveAssociatedTokenAccount(fromAccount.PublicKey, tokenAMint.PublicKey);
var transaction = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(fromAccount)
.AddInstruction(
SystemProgram.CreateAccount(
fromAccount,
tokenAMint,
devnetRpc.GetMinimumBalanceForRentExemption(TokenProgram.MintAccountDataSize).Result,
TokenProgram.MintAccountDataSize,
TokenProgram.ProgramIdKey))
.AddInstruction(
TokenProgram.InitializeMint(
tokenAMint,
0,
fromAccount,
fromAccount))
.AddInstruction(
AssociatedTokenAccountProgram.CreateAssociatedTokenAccount(
fromAccount,
fromAccount.PublicKey,
tokenAMint.PublicKey))
.AddInstruction(
TokenProgram.MintTo(
tokenAMint.PublicKey,
associatedTokenAccount,
1,
fromAccount.PublicKey))
.Build(new List<Account>()
{
fromAccount,
tokenAMint
});
Here is the partial transaction: https://solscan.io/tx/3KCg8GmNMXRh1GaHUUnGs5GjeDFfNdEiF5DthdW313TJC4RGw5eXVsQ9mTyJvLkg1PC8SRGSBDfLyfzgMos1sH26?cluster=devnet
I am now stuck on calling the Metaplex NFT Candy Machine V2, I have not found the functionality to do this. Is it possible to do this with the current version of solnet.metaplex? Otherwise anyone has any suggestions, tips to implement it?
Describe the bug
{"Specified argument was out of the range of valid values. (Parameter 'offset')"} exception in ParseData
.
Reproduce
Create nft without creators
but with primarySaleHappened
.
Why
(binData.GetU16(MetadataAccountLayout.creatorsOffset)
gives 256
MetadataAccountLayout
creatorsOffset must be 321
, not 322
creators
is optional field.Also, next fields missing
P.S.
Current used manual deserializing is so bad, better use schema (like here), possible also code generator.
if i update library i have this error:
AccountMeta.ReadOnly(SystemProgram.SysVarRentKey, false)
SystemProgram.SysVarRentKey not found
Describe the bug
Getting the following excepton:
Unhandled exception. System.TypeLoadException: Could not load type 'Solnet.Rpc.Utilities.AddressExtensions' from assembly 'Solnet.Rpc, Version=6.0.6.0, Culture=neutral, PublicKeyToken=null'.
at Solana.Metaplex.MetadataAccount.GetAccount(IRpcClient client, PublicKey pk)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Solana.Metaplex.MetadataAccount.GetAccount(IRpcClient client, PublicKey pk)
To Reproduce
var rpcClient = ClientFactory.GetClient(Cluster.DevNet, null);
var tokenAccounts = rpcClient.GetTokenAccountsByOwner("A4dqTiSyoQPYaYKgz7KMC4KbsA7Hw4o1W9edXa949zzT", null,
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
Task.Run(async () =>
{
foreach (TokenAccount accountPk in tokenAccounts.Result.Value)
{
var mint = accountPk.Account.Data.Parsed.Info.Mint;
var account = await MetadataAccount.GetAccount(rpcClient, new PublicKey(mint));
}
}).GetAwaiter().GetResult();
Installed versions:
Expected behavior
Not to crash.
Desktop (please complete the following information):
Macbook Pro latest OS.
v1.1.0 introduced a lot of additions to metadata account data and some deprecations. We need a to add
I did not find an example of how exactly to use UpdateMetadataAccount correctly and tried it out.
In MetadataProgramData.cs Line 171
should maybe be
writer.Write( (byte) MetadataProgramInstructions.Values.UpdateMetadataAccount );
instead of
writer.Write( (byte) MetadataProgramInstructions.Values.CreateMetadataAccount );
?
I tried it out using
var tx = MetadataProgram.UpdateMetadataAccount(mintMetadataPublicKey, updateAuthority, updateAuthority, new MetadataParameters()
{
creators = new List<Solnet.Metaplex.Creator>()
{
new Solnet.Metaplex.Creator(updateAuthority, 100)
},
name = "customname",
sellerFeeBasisPoints = 200,
symbol = "",
uri = "customurl"
}, false);
var blockHash = _client.GetRecentBlockHash();
byte[] TX1 = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
.AddInstruction(tx)
.Build(new List<Account> { wallet.Account });
var txSim = _client.SimulateTransaction(TX1);
and I get following error:
{"jsonrpc":"2.0","result":{"context":{"slot":99070261},"value":{"accounts":null,"err":{"InstructionError":[0,"InvalidError"]},"logs":["Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]","Program log: Error: BorshIoError","Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 3732 of 200000 compute units","Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: program returned invalid error code"]}},"id":3}
What I'm doint wrong and could you please share an working example?
Transaction sim:
{"jsonrpc":"2.0","error":{"code":-32003,"message":"Transaction signature verification failure"},"id":1}
I cant mint nft.
This is my code:
`
var rpcClient = ClientFactory.GetClient(Cluster.MainNet);
var blockHash = rpcClient.GetRecentBlockHash();
var wallet = new Wallet(MnemonicWords);
var fromAccount = wallet.Account;
var mintAccount = wallet.GetAccount(0);
var tokenAccount = wallet.GetAccount(0);
byte[] metadataAddress = new byte[32];
int nonce;
AddressExtensions.TryFindProgramAddress(
new List<byte[]>() {
Encoding.UTF8.GetBytes("metadata"),
MetadataProgram.ProgramIdKey,
mintAccount.PublicKey
},
MetadataProgram.ProgramIdKey,
out metadataAddress,
out nonce
);
Console.WriteLine($"PDA METADATA: {new PublicKey(metadataAddress)}");
byte[] masterEditionAddress = new byte[32];
//int nonce;
AddressExtensions.TryFindProgramAddress(
new List<byte[]>() {
Encoding.UTF8.GetBytes("metadata"),
MetadataProgram.ProgramIdKey,
mintAccount.PublicKey
},
MetadataProgram.ProgramIdKey,
out masterEditionAddress,
out nonce
);
Console.WriteLine($"PDA MASTER: {new PublicKey(masterEditionAddress)}");
var c1 = new Creator(fromAccount.PublicKey, 100);
var data = new MetadataParameters()
{
name = "Test 2",
symbol = "",
image = "https://i.resmim.net/hddxqQ.jpg",
uri = "http://foodi.com",
creators = new List<Creator>() { c1 },
sellerFeeBasisPoints = 5
};
byte[] TX2 = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(fromAccount)
.AddInstruction(
MetadataProgram.CreateMetadataAccount(
new PublicKey(metadataAddress), //PDA
mintAccount.PublicKey, //MINT
fromAccount.PublicKey, //mint AUTHORITY
fromAccount.PublicKey, //PAYER
fromAccount.PublicKey,
data, //DATA
true,
false //ISMUTABLE
)
)
.AddInstruction(
MetadataProgram.PuffMetada(
new PublicKey(metadataAddress)
)
)
.AddInstruction(
MetadataProgram.CreateMasterEdition(
1,
new PublicKey(masterEditionAddress),
mintAccount.PublicKey,
fromAccount.PublicKey,
fromAccount.PublicKey,
fromAccount.PublicKey,
new PublicKey(metadataAddress)
)
)
.Build(new List<Account> { fromAccount, wallet.GetAccount(0) });
var txSim2 = rpcClient.SendTransaction(TX2);
Console.WriteLine($"Transaction sim: \n { txSim2.RawRpcResponse }");`
When do you plan to publish the first version to nuget?
Is there an example of creating an NFT with this library?
Can i mint multiple NFT with this library and how can i do?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.