Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cNft Burn anchor example #65

Merged
merged 11 commits into from
Jan 16, 2024
Merged

Conversation

pratikbuilds
Copy link
Contributor

No description provided.

@pratikbuilds
Copy link
Contributor Author

@beeman I have created the PR again here

@Woody4618
Copy link
Collaborator

The tests fail with:
error[E0658]: use of unstable library feature 'build_hasher_simple_hash_one'
--> src/random_state.rs:463:5
|
463 | / fn hash_one<T: Hash>(&self, x: T) -> u64 {
464 | | RandomState::hash_one(self, x)
465 | | }
| |_____^
|
= note: see issue #86161 rust-lang/rust#86161 for more information
= help: add #![feature(build_hasher_simple_hash_one)] to the crate attributes to enable

@Woody4618
Copy link
Collaborator

Woody4618 commented Jan 11, 2024

Can you please add a readme that explains what the example does and how to run it? Does the tree need to be created? What should the burned asset id be? How to find it? Can you run it with local host?
Also probably need to add a section for RPC, since i think the default rpc doesnt support cNFTs?
I cant build the example because of the error above.

@pratikbuilds
Copy link
Contributor Author

The tests fail with: error[E0658]: use of unstable library feature 'build_hasher_simple_hash_one' --> src/random_state.rs:463:5 | 463 | / fn hash_one<T: Hash>(&self, x: T) -> u64 { 464 | | RandomState::hash_one(self, x) 465 | | } | |_____^ | = note: see issue #86161 rust-lang/rust#86161 for more information = help: add #![feature(build_hasher_simple_hash_one)] to the crate attributes to enable

yes its because of this https://solana.stackexchange.com/questions/8800/cant-build-hello-world i will test at my end as well and see if it's working

@pratikbuilds
Copy link
Contributor Author

I have added the README let me know if i missed something and the program works i have added a sample tx sig link as well to the deployed program on devnet. the error you are getting is well known if you are using anchor 0.29.0 i have added the stackExchange link above on how to fix that.

@Woody4618
Copy link
Collaborator

Woody4618 commented Jan 12, 2024

Thank you for updating this. Adding
ahash = "=0.8.6"
to the cargo toml fixes the compiler issue. Can you please add that?

When running the tests im getting this error now:

cnft-burn
1) Burn cNft!

0 passing (850ms)
1 failing

  1. cnft-burn
    Burn cNft!:

Error:
at Function.parse (node_modules/@coral-xyz/anchor/src/error.ts:249:14)
at translateError (node_modules/@coral-xyz/anchor/src/error.ts:281:37)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:35:29)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

error Command failed with exit code 1.

@pratikbuilds
Copy link
Contributor Author

ahash = "=0.8.6"

did you change the rpc url ? and you also need to make sure to create a tree and a cNFT before u run that

@Woody4618
Copy link
Collaborator

Yes i replaced the rpc url. Im still getting the same error when i run the tests. Can you please add the code to create the tree and the asset in the setup of the test? Tests should run without any prior setup. Otherwise CI for testing the examples will not work.

@pratikbuilds
Copy link
Contributor Author

got it will do that

@pratikbuilds
Copy link
Contributor Author

@Woody4618 i have made the changes now the test should be running on anchor run test without any additional steps

@Woody4618
Copy link
Collaborator

Thank you for the changes.
Please replace hardcoded keypair in createAndMint.ts with anchor provider wallet.
After that change the tests run, but there is still an error "Custom": 4100 during the burn.

Test Output:
Payer address: 5vJwnLeyjV8uNJSp1zn7VLW8GwiQbcsQbGaVSwRmkE4r
Creating a new Merkle tree...
treeAddress: CQrjjyg4rnUEhj554924r18qFUkYboSF9doVLNdDWv7W
treeAuthority: C11td6AfbeKgai5UGAU8LeRA1bK8UFWgw1ChXfhNecXA

Merkle tree created successfully!
https://explorer.solana.com/tx/AFmbYvQ3wVekF2zPKhss7P8meBuYA7zSZ368LzoYpiYc7dQ859FfBUpuutwZCYT7CWmUG9FJnJf1RFhKEhALE2v?cluster=devnet

Creating the collection's mint...
Mint address: 9x4rQhXNHFdeecfdsvzdiuuWgNP7XKeLb1tvZ2AvQX2U
Creating a token account...
Token account: 5d3BZ93yv64xLe8DVUqGM8Mt7KUFHuPsdCCAvN7AXBro
Minting 1 token for the collection...
Metadata account: HEbx9UXrF3qxCtPCkxiJcYXSCu26gA3UvUW1sTAbe2SQ
Master edition account: De4FR318eY1MgVdxFS3SbX4p7YVkhaiaSqbGaGGU4SQ4

Collection successfully created!
https://explorer.solana.com/tx/3FBpGA1y5dcp9P87obQvkCLDMMMdR6bEPqSxorTptsVxZ2ohLy4fFYiWLyi2UHgtuWaZ382ogecifvYfL8Kr3HuZ?cluster=devnet

Minting a single compressed NFT to 5vJwnLeyjV8uNJSp1zn7VLW8GwiQbcsQbGaVSwRmkE4r...
computedDataHash: BMB6Qb31K6ZLy8GYUWAZ83N9YhcFrQfk48WPjWm5GLF9
computedCreatorHash: HFTLV3itUfSPL1iqj3h8ivDXbfyxnfs8Yxy5dtujaGT

Successfully minted the compressed NFT!
https://explorer.solana.com/tx/4uZuUPzwCMdop3Tp6qsMDA9T8ZMCX7LRPvKKXVuriKaZAJqwSUtTGXpajoQTR5PUgfXfNcEexRauUBP8c52HipkX?cluster=devnet

===============================
Total cost: 0.4734089600 SOL

Collection mint: 9x4rQhXNHFdeecfdsvzdiuuWgNP7XKeLb1tvZ2AvQX2U

===============================================

Getting all assets by the 'collection' group...
Total assets returned: 1

===============================================
assetId: 8R1MXsXSqa2q3DjvdkfGZW66H4mW8KByjj5kWdVvGqok
ownership: {
frozen: false,
delegated: false,
delegate: null,
ownership_model: 'single',
owner: '5vJwnLeyjV8uNJSp1zn7VLW8GwiQbcsQbGaVSwRmkE4r'
}
compression: {
eligible: false,
compressed: true,
data_hash: '74UK2NQuJx2Zre4KYbdDsC12jsN2UVxeTTuXPhbQfmFs',
creator_hash: 'HFTLV3itUfSPL1iqj3h8ivDXbfyxnfs8Yxy5dtujaGT',
asset_hash: 'Dm8LpDQn42kjXJp69htX4Y6LRbC8ejasshKeGyx9aqkW',
tree: 'CQrjjyg4rnUEhj554924r18qFUkYboSF9doVLNdDWv7W',
seq: 1,
leaf_id: 0
}
assetId: 8R1MXsXSqa2q3DjvdkfGZW66H4mW8KByjj5kWdVvGqok
fetchcNFTs [ '8R1MXsXSqa2q3DjvdkfGZW66H4mW8KByjj5kWdVvGqok' ]
✔ Should create the tree and mint a cnft (3259ms)
1) Burn cNft!

1 passing (4s)
1 failing

  1. cnft-burn
    Burn cNft!:
    Error: the object {
    "InstructionError": [
    0
    {
    "Custom": 4100
    }
    ]
    } was thrown, throw an Error :)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

error Command failed with exit code 1.

@pratikbuilds
Copy link
Contributor Author

so 4100 means The declared program id does not match the actual program id. are you deploying the program before use ?

@Woody4618
Copy link
Collaborator

I just replaced your hard coded keypair in createAndMint.ts with the anchor provider and try to run the test and the burn test fails with:
1 failing

  1. cnft-burn
    Burn cNft!:

Error:
at Function.parse (node_modules/@coral-xyz/anchor/src/error.ts:249:14)
at translateError (node_modules/@coral-xyz/anchor/src/error.ts:281:37)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:35:29)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

error Command failed with exit code 1.

@pratikbuilds
Copy link
Contributor Author

I just replaced your hard coded keypair in createAndMint.ts with the anchor provider and try to run the test and the burn test fails with: 1 failing

  1. cnft-burn
    Burn cNft!:

Error: at Function.parse (node_modules/@coral-xyz/anchor/src/error.ts:249:14) at translateError (node_modules/@coral-xyz/anchor/src/error.ts:281:37) at MethodsBuilder.rpc [as _rpcFn] (node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:35:29) at processTicksAndRejections (node:internal/process/task_queues:95:5)

error Command failed with exit code 1.

GM ser this error itself is not that clear on what's wrong as it says the errors is in node_modules i have it running on my end and if you could provide me the steps that u folllowed i might be able to figure out why u are getting this error.
Screenshot 2024-01-16 at 2 31 20 PM

@Woody4618
Copy link
Collaborator

Maybe it works only with your keypair. Can you try with a new one?
image

@pratikbuilds
Copy link
Contributor Author

I tried with a new keypair and its seams to be working fine

cnft-burn
Payer address: FwE55ngcQhYE4ciMtbqwDzQpZFTsFxA7vJPvGjjzygp1
(node:76419) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use node --trace-warnings ... to show where the warning was created)
Creating a new Merkle tree...
treeAddress: 2E2tTbLDU88744xMa3qH2T9C4YRGQquGKJBBbmFYPVEY
treeAuthority: 8dKkeUdTGb5Cs62vPwbRYUEmDAZFnR46gnBqGK3p1eYq

Merkle tree created successfully!
https://explorer.solana.com/tx/5fqXApF4VnBEadDuNHjgz2WsDtY6Ro276TbFj8tnp6a5Xjv1yC2W9jLXE5Ctb1y4x8TxLEZfN9FvHoepR4xSQoFT?cluster=devnet

Creating the collection's mint...
Mint address: 5cpdUg5VCULuBQCcCGVYB9FhAKLeCzFY5VCnQfEU63pu
Creating a token account...
Token account: 2uwvjwG5WAy54BsXsav5zcEzeuCcfJrJm1RV4ZYeUXy9
Minting 1 token for the collection...
Metadata account: HCyiEhdMqqTCZsSTLznyjyGgtBWaT6mfr9LdoPMB78Me
Master edition account: 3XC268tpXF28XYr775m3Gz6DDSG5v1B2srWcRtf1xSCj

Collection successfully created!
https://explorer.solana.com/tx/5t6ws63M5tempqK9KSgoMtK1YfA5xhHq3aRJjps7JamJ4CQNV5Rbj41bU5LVizbLtSzwhzhCM8kPNx8qsQSLd14j?cluster=devnet

Minting a single compressed NFT to FwE55ngcQhYE4ciMtbqwDzQpZFTsFxA7vJPvGjjzygp1...
computedDataHash: HLfqLDh3S9GhyGxXFF91YYbjaGNnULmHsfVCA4j2e1zW
computedCreatorHash: DsQ8Q63rtUnxepTMZxv52k82VsndHhv1DFrtt9Js6yC

Successfully minted the compressed NFT!
https://explorer.solana.com/tx/4zfae5WGoUEQXjcgB9qtZwTyCxmY78nQkHLxNFqaSdovaoYwMaqaTCD6pT51wNmkgwDXi7zFxnhs3rvXUqymaVRz?cluster=devnet

===============================
Total cost: 0.4734089600 SOL

Collection mint: 5cpdUg5VCULuBQCcCGVYB9FhAKLeCzFY5VCnQfEU63pu

===============================================

Getting all assets by the 'collection' group...
Total assets returned: 1

===============================================
assetId: CS36VaL2Lb6LZKw3gH6JqotCUiifmxoN1NMeGo9wuke7
ownership: {
frozen: false,
delegated: false,
delegate: null,
ownership_model: 'single',
owner: 'FwE55ngcQhYE4ciMtbqwDzQpZFTsFxA7vJPvGjjzygp1'
}
compression: {
eligible: false,
compressed: true,
data_hash: 'ArJguzy98juUxhdZ4FtJuPfR2PMXn1h7sz5VaBFrJpss',
creator_hash: 'DsQ8Q63rtUnxepTMZxv52k82VsndHhv1DFrtt9Js6yC',
asset_hash: 'BBvxSQ7LiU6ZA7gwDza6xfkkXzj3jTUYMHZZe2SsfjXP',
tree: '2E2tTbLDU88744xMa3qH2T9C4YRGQquGKJBBbmFYPVEY',
seq: 1,
leaf_id: 0
}
assetId: CS36VaL2Lb6LZKw3gH6JqotCUiifmxoN1NMeGo9wuke7
fetchcNFTs [ 'CS36VaL2Lb6LZKw3gH6JqotCUiifmxoN1NMeGo9wuke7' ]
✔ Should create the tree and mint a cnft (8065ms)
Your transaction signature 4eC43PX1L6UywvPUJCXirjbL529ShVYQcheWj71ZwosyVRjw2mao4WwjneYS7vkXHjcNH8wwGeX6DyYn1giAfX9
✔ Burn cNft! (2397ms)

2 passing (10s)

✨ Done in 12.52s.

@Woody4618
Copy link
Collaborator

Ok nice, now after rebuilding, deploying and running it again it also works for me. Can you please fix the keypair part. Then its ready to go :)

@pratikbuilds
Copy link
Contributor Author

oh nice i have removed my path and made it generic. I am not sure on how to get that path from anchor.toml do you know how can we get that ?

@Woody4618
Copy link
Collaborator

You can not use ~ there.

Please use:
anchor.setProvider(anchor.AnchorProvider.env());

const program = anchor.workspace.CnftBurn as anchor.Program;
const provider = anchor.AnchorProvider.env();
const payerWallet = provider.wallet as anchor.Wallet;

// load it locally from the filesystem when available
const payer = payerWallet.payer;

@pratikbuilds
Copy link
Contributor Author

Thanks @Woody4618 I forgot on how we could get that finally got that fixed and pushed

compression/cnft-burn/tests/utils.ts Show resolved Hide resolved
compression/cnft-burn/tests/readApi.ts Outdated Show resolved Hide resolved
@Woody4618 Woody4618 merged commit 4366669 into solana-developers:main Jan 16, 2024
2 of 3 checks passed
@mikemaccana
Copy link
Contributor

FYI merging this broke tests: https://github.com/solana-developers/program-examples/actions/runs/7545772604/job/20542140953

@Woody4618
Copy link
Collaborator

Woody4618 commented Feb 8, 2024

Oh thanks, true @0xPratik could you please fix the linting? 🙏

@pratikbuilds
Copy link
Contributor Author

yes i will check that and a new PR for cnft update is coming soon as well

@Woody4618
Copy link
Collaborator

Awesome!! 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants