Insanely expensive 2kb storage

I have a javascript UInt8Array that is a compressed patch list that has already been made binary trough a custom encoder to save space.


    struct MyData {
        string username;
        uint256 creationDate;
        string country;
        string language;
        uint64[][] records;
    }

    mapping(address => uint64) public userIds;

    mapping(uint64 => MyData) private records;

    function addPatches( uint64[] memory data) public returns (bool  ok) {
        require(userIds[msg.sender] > 0, "must Be registered");
        uint64 id =  userIds[msg.sender];
        records[id].records.push(data);
        ok = true;
        return ok;
    }


Using TronWeb, when I simply execute the contract:

const data = generateParameters()
contract.addPatches(data)

I also reduced the array size by transforming the Uint8Array into a BigInt64Array,

When simulating with a user that is new to Tron, and not aware of Energy & bandwidth, the transaction costs:


const data: BigUint64Array = generateParameters()

console.log(data.length); 
// outputs => 35
contract.addPatches(data)

So When clicking on Sign, without looking… it becomes quite expensive and can drain the wallet significantly.

Maybe TronLInk needs a warning when the amount goes over 5TRX.

Am I close to reality, or is it my implementation that is just incorrect?

2 Likes

Smartcontract not is a storage layer. Please using Merkle Proofs

1 Like

Thanks for replying to me.
For the storage layer, I am already using Arweave.

here I am storing 70 Uint64 in an array, and it cost 50US$.

Are you telling me this is normal?

It is nearly 1US$ per UINT64.

There must be something that can be done in my solidity code to reduce that cost.

Also, if not for storage, what are smart contracts used for really ?

AFAIK, they store values, and execute routines on those stored values, to produce outputs.

2 Likes

It’s normal, you must rent energy for reduce cost. Some suggest from me.
Encode your input into parameter, one bytes. Using merkle tree and offchain storage. Smartcontract only verify for save cost.

2 Likes

thank you so much,

I wasn;t sure if it was possible or not.

What you are suggesting is storing a hash dictionary on chain containing the url of the arweave storage, correct?

1 Like

You can do that, but can store base url and each user have short hash link for save cost.

1 Like

no I don’t see how I can - this requires a centralized intermediary that synchronize Arweave and tron contract calls.

2 Likes

You are right. In this case, you have to burn almost 252 TRX (approximately 60 USD), which is a insane amount.



https://tronscan.org/#/tools/tronstation

If you rent energy from JustLend DAO, you have to prepay 145 TRX (34.32 USD) to get the required energy for this transaction, and approximately 94 TRX (22.25 USD) will be refunded if the rental is ended on time. This means your cost will be reduced to 34.32 - 22.25 = 12.07 USD from the initial 60 USD, which is approximately an 80% cost saving.


JustLend DAO | JustLend DAO is the first official lending platform on TRON where users can borrow, lend, deposit assets and earn interests.

1 Like

Hello, yes, rental energy is an option.

Thank you for the detailed screencast.

I have been considering tron to host voting data in the new iteration - because I won a price last year , and they gave me feedback, and I really want to give that back.

So my user, typically, is not crypto aware.

And when my user wants to persist his votes, I will have to design a series of screens just to teach a crypto unaware user how to do stuff.

Let’s compare 3 scenarios: TRX, another solidity based chain, traditional backend architecture

Let’s assume a regular user, 10 visits with 1 contract call at each visit.

TRX - 100$

0 - Enter Username
1 - Install TronLink (most people will leave here - Permissions: Wallet can read everything you input in all your browser’s tabs, passwords, bank cards, emails…)
2 - Buy TRX (most people will leave here - they are not ready to spend money today - and they’ll never come back - because web3 doesn’t support sending emails yet - for customer engagement, reminder)
3 - Read a lot of complicated stuff (for the average Joe) : Understand the concept of Energy & Bandwidth
4 - Get them to rent energy + bandwidth before they click Sign - otherwise they lose ALL THEIR MONEY
5 - repeat Step 4 every time they sync their community votes

Traditional Backend - FREE

0 - Enter UserName
1 - Done

Other solidity Chain 0.1$

0 - Enter Username
1 - Install Wallet (most people will leave here - Permissions: Wallet can read everything you input in all your browser’s tabs, passwords, bank cards, emails…)
2 - Buy Crypto (most people will leave here - they are not ready to spend money today - and they’ll never come back - because web3 doesn’t support sending emails yet - for customer engagement, reminder)
3 - Done

A truely decentralized Public Library is free

Using Arweave as a storage layer, I don’t need the user to have a wallet installed to browse the Library.
But as soon as I a user agrees to publish his Library usage as a public domain data, he also needs to pay quite a lot with time & resources.

The Library is a free service for all, and not targeted to elite rich people.

With years of experience across industries, I realized that those in power are not necessarly the most intelligent / wise / clever of the pack. But they are really good at presenting themself as such. This is how we mostly end up with that messy world and with the privilege to witness the end of the 6th greatest mass extinction event on our planet.

The Library goal is to provide universal knowledge on how to heal and undo the damages done by providing solutions that allows anyone to make a living while repairing the environment.

Because of that, the Library content cannot be managed by the same people who are responsible for the destruction of the planet in exchange of $.

Adapt or die*

Someone famous said that. (me ?)

How to adapt

Here are some of my options:

  • Find how to reduce the gaz by 100x cost by tuning the solidity code (What I am doing here - with no luck)
  • Create several crypto clubs. One club by crypto chain, and place TRX club in the Elite club - only for rich people who are into environmental restoration - and get the less rich (but very often more clever) to rate their suggestions trough another chain.
  • Get a backend (web2) service to sync the chains to allow an unidirectional review.
    which I really don’t want to do - because that would break the web3 promise.

Any solidity suggestion ?

Is it all about money in this community?

I have read more about Merkle Tree at this link:

I understand the concept, but I don’t see how I can save costs:

A typical hash is 0x8de86150eaaafcb9367396f2bee0cfd657854c6c561b741f6f8ef4fb28e82e12

Whose length is way bigger than the actual uInt64 that I am storing.

How can I save space when the hash takes more space than the data being hashed?

Plus I don’t need to verify anything in the smart contract itself.

In this project, verification will be made trough human manual input - with a vote validation mechanism.

For example, let’s say you vote for Page X of Book Y :slight_smile:

It could be represented in solidity as

struct Vote {
  uint8 action
  uint16 bookId
  uint16 pageNumber
}

Which is actually compressed into a single uint64 from the client - before interacting with the contract (to save gaz).

Let’s say I store that vote in a mapping

mapping(uint16 => uint64[]) public votes

Adding one record to that mapping cost 1$. (around 30cents using energy renting)

Is it correct than storing ONE uint64 in TRON is that expensive?

I also noticed that solidity is not a very a sociable community - in the programming world. Going on stack overflow brings no quality answers - (which are now mostly generated by low quality AI agents). I remember back in the days, when I was asking question on SO - I would get quality answers quite immediately, whatever language - be JS, PHP or GO… But asking questions about solidity… and it is becomes radio silence. Asking google, and I only get the docs. And when asking very specific questions that needs expertise to solve, there is absolutly nothing.

is there an active community of solidity developer that help each others in their spare time that I don’t know of ?

Hello! Just arrived to the conversation. I really need to learn more about renting energy. Clearly has a great impact on the budget. I will deep dive into this topic as I will need to deploy a smart contract in the following months.

1 Like