NFT Wrapping

Stash offers a way to make NFTs rent-compliant even without implementing the necessary protocols inside NFT contract. It is achieved by making use of a methodology called NFT wrapping, which is based on escrowing the original NFT in the wrapper factory contract and minting a new wrapped NFT (WNFT) that is totally rent-compliant.

Here is an illustration of how NFT wrapping actually works:


Wrapping Visualization

Normally, the SDK takes care of the wrapping operations in case it's needed while lending an NFT. However, it's also possible to wrap the NFTs on your own by making use of Stash Wrapper Factory Contract.

Here are the steps to follow for wrapping NFTs manually:

1. Retrieve Wrapper Factory Contract:

Firstly you need to access to the Wrapper Factory contract:

const contracts = stash.contracts;
const factory = contracts.wrapperFactory;

2. Call Wrap Function:

Call wrap function to initiate the wrapping operation:

const wrapTxn = await factory.wrap(
                            amount, // 1 for 721-NFTs
                (response) : any => {
                    // On success
                  console.log('Successful', response);
                  // Retrieve wrapped NFT address
                  const wrappedAddress = response.args.wrappedAddress;
                  console.log('Wrapped address', wrappedAddress);
                (error) : any => {
                    // On error
                  console.log('Failed', error);

If any error occurs (e.g. user declines approval request or contract call fails) during the process, the error object error contains respective information about the reason of the failure. You can find more information about the error structure under Error Handling section in Integration docs.

If the wrapping has been successfully performed, then the success callback is called where the response object has the respective wrappedAddress in its extra args. You might want to store this address, because it should be used instead of the original NFT address while performing further operations (e.g. lending and renting) on the NFT.

Next up

Now that you made sure your NFTs are compatible for renting, you can start implementing some operations on the assets. Before that, you can also check out the Play & Earn reward share implementation