I’m trying to set up several NFT collections for a single wallet but I’m running into issues. The collections are overwriting each other. I’m using the standard nft-collection.fc file and its TypeScript wrapper.
Here are my main questions:
- How does TON generate the collection address?
- What changes do I need to make to create a new collection with a different address?
I’ve looked at the default file but I’m stumped. Any help would be great! I’m new to this and want to understand how to make each collection unique.
// Example code snippet (not actual implementation)
const createCollection = (owner: Address, content: Cell) => {
// How to make this generate a unique address for each collection?
const collection = new NftCollection(owner, content);
return collection.address;
}
Has anyone dealt with this before? What’s the trick to making multiple collections work?
yo dancingcloud, i’ve dealt with this before. the trick is to add a unique identifier in ur initial data when creating the collection. try something like this:
const createCollection = (owner, content, uniqueId) => {
const data = beginCell().storeAddress(owner).storeRef(content).storeUint(uniqueId, 64).endCell();
return new NftCollection(data).address;
}
this should give u different addresses for each collection. lmk if it works!
hey there dancingcloud! i’m pretty new to ton myself but i’ve been playing around with nfts lately. from what i understand, the collection address is generated based on the initial data you provide when creating it. so to get different addresses, you’d need to change something in that initial setup
have you tried adding a unique identifier to each collection? maybe something like:
const createCollection = (owner: Address, content: Cell, uniqueId: string) => {
const initialData = beginCell()
.storeAddress(owner)
.storeRef(content)
.storeString(uniqueId)
.endCell();
const collection = new NftCollection(initialData);
return collection.address;
}
this way, each collection would have a different initial state and thus a different address. just an idea tho, i’m not 100% sure if this is the best way to do it
what kind of collections are you trying to make? sounds like an interesting project! have you thought about using different content for each one too? that could help make them unique
The key to creating multiple NFT collections with unique addresses lies in the initial data provided when instantiating each collection. TON generates collection addresses based on this state. To create distinct addresses, you must incorporate a unique element—such as a timestamp, counter, or unique identifier—into this initial setup.
Below is a modified version of your code:
const createCollection = (owner: Address, content: Cell, uniqueId: number) => {
const initialData = beginCell()
.storeAddress(owner)
.storeRef(content)
.storeUint(uniqueId, 64)
.endCell();
const collection = new NftCollection(initialData);
return collection.address;
}
By incrementing the uniqueId for each collection, you ensure each one possesses a unique state and, consequently, a unique address.