NXTER.ORG

DeFiMAGIC Twitter BOT: The new NFT function

by on 

The purpose of this post is to explain how the new NFT capability of the DeFiMAGIC Twitter BOT works.

For a brief overview of all the other DeFiMAGIC functionalities refer to this forum topic: https://ardor.rocks/groups/defi/forum/topic/deadfish-bots-parody-but-not-too-much/

The original idea of the DeFiMAGIC bot was to create a parody version of other more established projects, mainly on Ethereum, around the DeFi (Decentralized Finance) phenomenon that was the big buzzword in the crypto space in 2020.

The whole thing started with our friend Zark when he issued the DeFi (DeadFish) asset token on Ardor and started distributing the DeFi on Twitter. Then we started teaching the bot how to take care of things automatically. For things like Yield Farming that gives a passive income we created #DeFiMAGIC DEPOSIT. Or for Loans we created #DeFiMAGIC BORROW. And more and more.

People can also #DeFiMAGIC SEND DeadFish tokens to each other on Twitter and the bot takes care of all the rest. For example if the receiving user doesn’t have an Ardor account, the bot will automatically create one for that specific Twitter user and then transfer the amount defined in the SEND action.

But back to the NFT.

My first #NFTart

2020 was also the year of NFTs or Non-Fungible Tokens. These tokens can represent art pieces registered on the blockchain, mainly on Ethereum. I saw the value of registering goods or art pieces on the blockchain, but the perception I had of NFTs was of very low-resolution designs that certainly had some art within, but still were very pixelated. 
Therefore, to make a parody version of this phenomenon, I was picturing an extremely pixelated circle or triangle or square. Basic forms that would take the pixelated NFTs I’ve seen in the space to an extreme in terms of simplicity. But how to do that on Ardor?

Ardor has an awesome feature that suits the representation of unique entities perfectly: the Singleton Asset. An asset is like an ERC20 token on Ethereum, a singleton asset is an asset with only 1 unit that can be traded on the Asset Exchange or transferred from the owner to another Ardor account.

I needed to store the picture somewhere, so why not try to squeeze it into the blockchain as anyway an extremely pixelated circle should not be too much data? I though of converting my extremely pixelated circle into a base64 string and store it in the description of the asset which can maximum store 1000 characters. 1kb for a picture with all the base64 formatting overhead is pretty small. But I managed to squeeze it in and it worked!

Once the data is available, the twitter bot, when asked, fetches the base64 data from the asset description and converts it into an image one can actually see on twitter. I did like the idea of creating also a triangle and a square, but I was wondering if we could squeeze more data inside an asset.

Storing larger images on blockchain

I was trying to play a bit with Ardor’s Data Cloud feature, when Sergi from Jelurida gave an awesome suggestion of how to create the permanent bond between asset and data-cloud: store the FullHash of the data-cloud data into the Asset description. Voilà! As the description of an asset can never be changed after it has been issued, there we had a solution to store 42kb of data instead of 1kb.

That’s a massive improvement. – But a FullHash is always 64 bytes and a base64 encoded image is a string, so why not split that string into more data-cloud chunks so that we can have even more than 42kb data available? If the description of an Asset can contain 1000 bytes it means that we can store in the description up to: 1000 / 64 * 42kb = 630kb

Now the awesome Ardor community provided me with outstanding designs between 70kb and 500kb which could all be stored on the Ardor blockchain.

Let’s take the NFT1 token as an example:

As you can see, the description contains several 64 byte FullHashes one after the other referring to the data-cloud chunks of 42kb (actually I made them 40-41kb so there’s space for the other metadata).

Let’s take the first FullHash as an example:

This was uploaded using the client test page. (Sorry, I’m using another data-chunk in the screenshot below instead of the NFT1, but it’s the same concept. Imagine the name being NFTA01 and the data starting with data:image/jpeg;base64,/9j/4AAQS…) :

The next chunks of the base64 data were uploaded in the same way with names NFTA02, NFTA03, etc.

Showing NFT art inside Twitter posts

When the bot is asked for information about NFT1 (#DeFiMAGIC INFO NFT1) or the NFT is being bought (#DeFiMAGIC BUY NFT1) what happens is that the bot:

  • fetches the assetID of the NFT1
  • splits the description in 64 byte pieces (transaction FullHashes)
  • gathers sequentially the data-cloud data using the FullHashes above and concatenates them to create the full base64 image data
  • converts the base64 data to visible image in real-time

The beauty of this is that there is no external DB to store this data. It’s all on the blockchain.

At the moment all the uploading part of the image is done manually. That is to convert the image to base64, split the string into 41kb chunks, upload them to the client, collect the FullHashes and create the singleton Asset. But this could be all automatic with a simple user interface. That would also help to avoid human mistakes.

And what about the NFT’s value?

In Ardor we cannot trade an Asset for another Asset via the exchange API, and we want to sell 1 NFT (singleton asset) for some amount of DeFi (DeadFish) assets. So to do that, each BUY transaction (which triggers a transfer of the NFT asset from one user to the other) has an unencrypted message attached with the current NFT value:

When the next BUY happens, the bot takes the previous value, adds 10% and attaches this new value to the following asset transfer transaction. Because this project is for fun only, there is no real trading possible but only buying, so this trick came in handy. The NFT assets are under asset control so the main bot’s Ardor account has to approve all transactions and the user who owns the asset cannot go on the Asset Exchange and try to sell the NFT for Ignis or any other Ardor child chain currency. Instead, with the BUY action, the buyer simply transfers the asked amount of DeFi assets to the previous NFT owner – and receives the NFT.

The approval model causes the BUY action to take some extra time, causing new buyers to have to wait about 5 minutes until the asset transfer is complete and therefore ready for the next transfer. Why is that? Because the Twitter bot cannot have multiple streams with the API account there had to be a solution not to wait for the transactions to be confirmed and approved by the main bot ardor account. The solution workaround is the following:

  1. userA BUYs NFT1 from userB
  2. userB initiates the NFT1 asset transfer transaction towards userA. At the same time userA initiates the DeFi asset transfer towards userB
  3. the NFT1 asset transfer needs to be approved by the main bot account and therefore the transaction of the NFT1 asset transfer is stored in a mysql table together with the other transaction needing approval. This allows the bot to continue to listen to other requests instead of waiting for things to happen in the background and cause response delays to the users on twitter
  4. a separate cronjob script runs every 5 minutes and checks the mysql table for the presence of transactions to be approved
  5. the script gets the first transaction in the database, waits for it to be confirmed once, then issues an transaction approval transaction that will take another minute more or less

During this time the NFT asset is still “on the move” and therefore it cannot be bought by another user. A user who tries to BUY during this time will get a reply with a warning.
The reason for the 5 minutes instead of 2, for example, is to allow the blockchain to have some delays to the expected 1 minute block and to allow the confirmation to happen which can also take 1-2 minutes.

Enough with technicalities… how much does it cost in terms of fees to do all this?

And the cost…

In this example of NFT1, we have the following transactions (I’m excluding the asset approval ones as those are maybe not so interesting for people wanting to use this not with a micro-managing bot):

  • Asset creation: 100 ARDR for assets with description over 160 bytes or 1 ARDR + 1 ARDR for each 32 bytes for descriptions under 160 bytes
  • Data Cloud upload: 0.5 ARDR x data chunk. In this specific case 6×0.5 = 3 ARDR.

But this could be massively optimized if we would:

  • Create a singleton asset with description containing only 1 data cloud FullHash
  • The first data cloud would then contain the FullHashes of the image data
  • Create the image data data-cloud

That would bring the cost of the above example to: 1 + 2 + 0.5 x 7 = 6.5 ARDR, which at the current market price would be 50 cents and would allow files up to 27MB as the space to store FullHashes of data is no longer 1000 bytes but 42kb.

This NFT experiment started as a joke but is showing some massive potentials. The possibility to do all this with costs that are close to zero is just amazing, and I’m sure that together with a little help from friends this will not remain a joke for long.

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x