Hello every body i get in trouble if someone can help me ...

I'm buying token with my smart contract, have a look :

enter image description here

Its is so clean to see my Tx and decode it .. because all adress are clear and this is the problem

I want make a clear Tx and encrypt it with that this can't be decoded like this one :

enter image description here

As you can see there is no way to know what is the token buy and the token use to buy that is a great encoded Tx that nobody can break.. So how can i proceed to do this please, need i encode my Tx or Self destruct it ?

This is my Solidity Smart Contract function to Buy :

 function Buy(address fromDECODED,address toDECODED,uint256 amountIn,address to) public {
uint256 amountOutMin = 0;

IERC20(fromDECODED).transferFrom(msg.sender, address(this), amountIn);
IERC20(fromDECODED).approve(ROUTER, amountIn);


And i call my function from my JS to execute a Buy order

  • The information should come from somewhere and the smart contract need to be able to decode it, which means everyone can decode it. if you are looking for privacy then look for aztec or polygon-nightfall
    – Majd TL
    Dec 31, 2022 at 13:00
  • Thanks for your answer, i make seach aztec is a network and nightfall is the a way too but i want learn how to do it into my solidity with an example..
    – forexmp45
    Dec 31, 2022 at 14:19

2 Answers 2

  • To obfuscate the input so that etherscan cannot decode it : YES.
  • To hide your contract's activity (ERC20 transfer): NO.

Although you can obfuscate and hide your input data, people can see your contract interacting with ERC20 address and use transfer & approve on that contract address. They can simply look at the Internal transactions or Log tab on etherscan to view it easily.

To obfuscate the input, it's actually quite simple, change your function name to some random string and change your function signature to use some encoded bytes. The simplest method for encode and decode is to use XOR operator. using the code below and do not submit ABI or source code to Etherscan, it would help you to avoid etherscan decoding your input.

    uint256 constant not_secret = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3;
    function random_obfuscated_string_0x1234567890(uint256  a, uint256 b) public{
        address real_addr_a = address(uint160(a ^ not_secret));
        address real_addr_b = address(uint160(b ^ not_secret));

To encode data you do the same thing , XORing with not_secret. As the name suggest, it's not a secret and its only purpose is to prevent etherscan. It also doesn't protect your contract from being revert engineered or disassembled by other users if they want to do it.

I would not recommend doing it though, because it doesn't help anything other than preventing the Input Data field from being decoded. People still can see "Token Transfered", "Internal Transactions", and "Logs". All these things clearly expose what your contract buy and sell.

Related question : How to obfuscate solidity smart contract

Update: OP asks for the step-by-step guide. So here it is (you have to understand these concepts (XOR cipher - symmetric encryption and the above description about what your contract can hide) before using it, otherwise it's very dangerous to copy and use online answers for solidity without understanding it fully:

Step 1. Choose a cipher key, it's the not_secret constant here. You can change it to any random number.

Step 2. Use the key to encrypt your input: Example:

  1. Token_1: 0x55d398326f99059ff775485246999027b3197955 Encrypt Token_1 using the key not_secret: Encrypted_token_1 = uint256(uint160(token2)) ^ not_secret = 50801780122331352337026042894364481186943364210072012998642427539196337619350

  2. Token 2: 0x2170Ed0880ac9A755fd29B2688956BD959F933F8 Encrypted_token_2 = uint256(uint160(token2)) ^ not_secret = 50801780122331352337026042894659144872731148500323806259612097858952170752827

Step 3. Use Encrypted_token_1 and Encrypted_token_2 as input of the function:

random_obfuscated_string_0x1234567890(50801780122331352337026042894364481186943364210072012998642427539196337619350, 50801780122331352337026042894659144872731148500323806259612097858952170752827)

Step 4. The contract decrypts the input data using the same key to get the original addresses 0x55d39... and 0x2170Ed... .

To encrypt and decrypt, it's better to write your own code because online services may use different padding, hard to guess how they implement. You can craft a local contract like this to test (e.g. on remix):

contract Test{
    uint256 constant not_secret = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3;
    function decrypt(uint256  a, uint256 b) public view returns (address, address) {
        address real_addr_a = address(uint160(a ^ not_secret));
        address real_addr_b = address(uint160(b ^ not_secret));
        return (real_addr_a, real_addr_b);
    function encrypt(address token1, address token2) public view returns (uint256, uint256){
        return (uint256(uint160(token1)) ^ not_secret, uint256(uint160(token2)) ^ not_secret);

I used encrypt function in this contract to produce the outputs in step 2 above.

Extra: Using uint160 for the key not_secret is considered simpler for the code and you may be able to use some online service to check encrypt-decrypt, you may try.


UPDATE : ok it work perfect and big thanks you but i make a mistake asking my question and i have the solution right now :

It work because we provide the address of token1 and token2 in the SOLIDITY

To change this tokens we need do like this :

Need to provide the token1 & token2 from the **JAVASCRIPT Script **

In JS need do this :

**1st Step ** call function encrypt(of my contract) to get the encrypted data >> await answer.

**2nd Step ** call function Buy(of my contract) to make the swap wished.

After many hour i don't find how to do this only in SOLIDITY i'm able to change token address only with the step above with JS :

So i need call 2 function actually in my JS to answer the question.

Maybe we can do it only in Solidity i don't find ?? after many test ... i mean :

  • Send from JS the true address to SOLIDITY CONTRACT .
  • CONTRACT encrypt it.
  • CONTRACT call Buy function with the decryption into the function Buy

Thanks you so much ! Please provide me donation address !

Sincerely Mike

  • I updated the answer, just hope that you and maybe your team read what is possible, what is not, and what are the related concepts. All the best.
    – minhhn2910
    Jan 2, 2023 at 4:52
  • Please mark my answer as correct, thank you :)
    – minhhn2910
    Jan 4, 2023 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.