Offloading expensive computation to off-chain for saving gas, as simple & fast as possiblePhoto by Shubham Dhage on Unsplash, more artworks at http://guerrillabuzz.com/ Table of Contents i. Introductionii. Practical exampleiii. Conclusion Introduction Ethereum’s high gas problem should not be unfamiliar to you, as a crypto trader, a blockchain developer, or just an enthusiast in the space. With Ether's price standing strong in the $3000 area and gas price on the rise averaging 50–70 Gwei, the gas fee for every transaction is getting more expensive and takes about $4 USD for a simple transfer. There is a way to go around the gas problem, is to put this computation off-chain and let the server do the work. A lot of tutorials online teaching ECDSA involves the use of maths, something about s, r, v, which we all developers (code monkeys) can agree, is boring and difficult to implement without bugs. So in this article, we are just gonna use the built-in functions from contracts written by OpenZeppelin and Ethers.js to build this feature. Practical example In this project, we are going to use a common use case for ECDSA to demonstrate the method, which is setting up a whitelist for an NFT project, and include code snippets to help you get started. This project is written in JavaScript and Solidity. 1. Setup To prepare for ECDSA, you should create a new wallet and use it only for this project as the signature signer. Do not use this wallet for any other purpose but only for signing the message in this project. After creating the wallet, save its private key for later use. 2. Off-chain Signature 2.1. To get started, we will need to first install Ether.js by running: npm run ethers and importing it into the project by: import ethers from ethers 2.2. Then we can initialize the signer instance by creating a new Wallet using the library: const signer = new ethers.Wallet("0x" + "<your private key>"); Remember to add 0x in the prefix of your private key if you exported directly from Metamask. 2.3. Pack the message together, and we can try to pack the address and the nonce for whitelisting: let message = ethers.utils.solidityPack(["address", "uint256"], ["0xabc", "0"]); This is to concatenate the message together to be hashed in the next section. Ethers.js supports a wide range of variables, including string and array like uint256[]: 2.4. Hash the message with keccak256 and sign with the signer wallet: message = ethers.utils.solidityKeccak256(["bytes"], [message]);const signature = await signer.signMessage(ethers.utils.arrayify(message)); This signature is the signature signed for the message with the signer's private key. We can pass this signature along with the verified parameters into the blockchain to ensure that the parameters are valid. The whole code snippet:https://medium.com/media/b7bf0931c9291dc5ff9d222c2f8a4753/href 3. On-chain Verification 3.1. To verify the signature on-chain, we can make use of the contract EDCSA written by OpenZeppelin. To use it, install Openzepplin locally or use it in Remix: npm install @openzeppelin/contracts 3.2. Set up the storage for signer on-chain with a setter: address signer; function setSigner(address _signer) external { signer = _signer;} 3.3. Then pack the values together by abi.encodePacked and hash it with keccack256: bytes32 hash = keccak256(abi.encodePacked(msg.sender, nonce)); 3.4. Turn the signature to an Ethereum signed message: bytes32 message = ECDSA.toEthSignedMessageHash(hash); 3.5. Recover the signer address from the signature: address receivedAddress = ECDSA.recover(message, signature); 3.6. Check if the signer of the message matches the signer store on-chain, only approve if the signer matches: require(receivedAddress != address(0) && receivedAddress == signer); The whole code snippet is:https://medium.com/media/9d470e1a4f48d90b838f2c876555677c/href Conclusion And now you learned how to use ECDSA as simply as possible, without the use of any complex maths. However, there are also tradeoffs of putting computation off-chain but that is beyond the scope of this article. I am going to explain more on this so follow to stay tuned! Want to Connect? You can find me at Twitter Github Discord. Verify Off-chain Results and Whitelist With ECDSA in Solidity Using OpenZeppelin and Ethers.js was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this storyOffloading expensive computation to off-chain for saving gas, as simple & fast as possiblePhoto by Shubham Dhage on Unsplash, more artworks at http://guerrillabuzz.com/ Table of Contents i. Introductionii. Practical exampleiii. Conclusion Introduction Ethereum’s high gas problem should not be unfamiliar to you, as a crypto trader, a blockchain developer, or just an enthusiast in the space. With Ether's price standing strong in the $3000 area and gas price on the rise averaging 50–70 Gwei, the gas fee for every transaction is getting more expensive and takes about $4 USD for a simple transfer. There is a way to go around the gas problem, is to put this computation off-chain and let the server do the work. A lot of tutorials online teaching ECDSA involves the use of maths, something about s, r, v, which we all developers (code monkeys) can agree, is boring and difficult to implement without bugs. So in this article, we are just gonna use the built-in functions from contracts written by OpenZeppelin and Ethers.js to build this feature. Practical example In this project, we are going to use a common use case for ECDSA to demonstrate the method, which is setting up a whitelist for an NFT project, and include code snippets to help you get started. This project is written in JavaScript and Solidity. 1. Setup To prepare for ECDSA, you should create a new wallet and use it only for this project as the signature signer. Do not use this wallet for any other purpose but only for signing the message in this project. After creating the wallet, save its private key for later use. 2. Off-chain Signature 2.1. To get started, we will need to first install Ether.js by running: npm run ethers and importing it into the project by: import ethers from ethers 2.2. Then we can initialize the signer instance by creating a new Wallet using the library: const signer = new ethers.Wallet("0x" + "<your private key>"); Remember to add 0x in the prefix of your private key if you exported directly from Metamask. 2.3. Pack the message together, and we can try to pack the address and the nonce for whitelisting: let message = ethers.utils.solidityPack(["address", "uint256"], ["0xabc", "0"]); This is to concatenate the message together to be hashed in the next section. Ethers.js supports a wide range of variables, including string and array like uint256[]: 2.4. Hash the message with keccak256 and sign with the signer wallet: message = ethers.utils.solidityKeccak256(["bytes"], [message]);const signature = await signer.signMessage(ethers.utils.arrayify(message)); This signature is the signature signed for the message with the signer's private key. We can pass this signature along with the verified parameters into the blockchain to ensure that the parameters are valid. The whole code snippet:https://medium.com/media/b7bf0931c9291dc5ff9d222c2f8a4753/href 3. On-chain Verification 3.1. To verify the signature on-chain, we can make use of the contract EDCSA written by OpenZeppelin. To use it, install Openzepplin locally or use it in Remix: npm install @openzeppelin/contracts 3.2. Set up the storage for signer on-chain with a setter: address signer; function setSigner(address _signer) external { signer = _signer;} 3.3. Then pack the values together by abi.encodePacked and hash it with keccack256: bytes32 hash = keccak256(abi.encodePacked(msg.sender, nonce)); 3.4. Turn the signature to an Ethereum signed message: bytes32 message = ECDSA.toEthSignedMessageHash(hash); 3.5. Recover the signer address from the signature: address receivedAddress = ECDSA.recover(message, signature); 3.6. Check if the signer of the message matches the signer store on-chain, only approve if the signer matches: require(receivedAddress != address(0) && receivedAddress == signer); The whole code snippet is:https://medium.com/media/9d470e1a4f48d90b838f2c876555677c/href Conclusion And now you learned how to use ECDSA as simply as possible, without the use of any complex maths. However, there are also tradeoffs of putting computation off-chain but that is beyond the scope of this article. I am going to explain more on this so follow to stay tuned! Want to Connect? You can find me at Twitter Github Discord. Verify Off-chain Results and Whitelist With ECDSA in Solidity Using OpenZeppelin and Ethers.js was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story

Verify Off-chain Results and Whitelist With ECDSA in Solidity Using OpenZeppelin and Ethers.js

2025/09/09 21:02
4 min read

Offloading expensive computation to off-chain for saving gas, as simple & fast as possible

Photo by Shubham Dhage on Unsplash, more artworks at http://guerrillabuzz.com/
Table of Contents
i.   Introduction
ii. Practical example
iii. Conclusion

Introduction

Ethereum’s high gas problem should not be unfamiliar to you, as a crypto trader, a blockchain developer, or just an enthusiast in the space. With Ether's price standing strong in the $3000 area and gas price on the rise averaging 50–70 Gwei, the gas fee for every transaction is getting more expensive and takes about $4 USD for a simple transfer.

There is a way to go around the gas problem, is to put this computation off-chain and let the server do the work.

A lot of tutorials online teaching ECDSA involves the use of maths, something about s, r, v, which we all developers (code monkeys) can agree, is boring and difficult to implement without bugs. So in this article, we are just gonna use the built-in functions from contracts written by OpenZeppelin and Ethers.js to build this feature.

Practical example

In this project, we are going to use a common use case for ECDSA to demonstrate the method, which is setting up a whitelist for an NFT project, and include code snippets to help you get started.

This project is written in JavaScript and Solidity.

1. Setup

To prepare for ECDSA, you should create a new wallet and use it only for this project as the signature signer. Do not use this wallet for any other purpose but only for signing the message in this project.

After creating the wallet, save its private key for later use.

2. Off-chain Signature

2.1. To get started, we will need to first install Ether.js by running:

npm run ethers

and importing it into the project by:

import ethers from ethers

2.2. Then we can initialize the signer instance by creating a new Wallet using the library:

const signer = new ethers.Wallet("0x" + "<your private key>");

Remember to add 0x in the prefix of your private key if you exported directly from Metamask.

2.3. Pack the message together, and we can try to pack the address and the nonce for whitelisting:

let message = ethers.utils.solidityPack(["address", "uint256"], ["0xabc", "0"]);

This is to concatenate the message together to be hashed in the next section. Ethers.js supports a wide range of variables, including string and array like uint256[]:

2.4. Hash the message with keccak256 and sign with the signer wallet:

message = ethers.utils.solidityKeccak256(["bytes"], [message]);
const signature = await signer.signMessage(ethers.utils.arrayify(message));

This signature is the signature signed for the message with the signer's private key.

We can pass this signature along with the verified parameters into the blockchain to ensure that the parameters are valid.

The whole code snippet:

https://medium.com/media/b7bf0931c9291dc5ff9d222c2f8a4753/href

3. On-chain Verification

3.1. To verify the signature on-chain, we can make use of the contract EDCSA written by OpenZeppelin. To use it, install Openzepplin locally or use it in Remix:

npm install @openzeppelin/contracts

3.2. Set up the storage for signer on-chain with a setter:

address signer;
function setSigner(address _signer) external { 
signer = _signer;
}

3.3. Then pack the values together by abi.encodePacked and hash it with keccack256:

bytes32 hash = keccak256(abi.encodePacked(msg.sender, nonce));

3.4. Turn the signature to an Ethereum signed message:

bytes32 message = ECDSA.toEthSignedMessageHash(hash);

3.5. Recover the signer address from the signature:

address receivedAddress = ECDSA.recover(message, signature);

3.6. Check if the signer of the message matches the signer store on-chain, only approve if the signer matches:

require(receivedAddress != address(0) && receivedAddress == signer);

The whole code snippet is:

https://medium.com/media/9d470e1a4f48d90b838f2c876555677c/href

Conclusion

And now you learned how to use ECDSA as simply as possible, without the use of any complex maths. However, there are also tradeoffs of putting computation off-chain but that is beyond the scope of this article. I am going to explain more on this so follow to stay tuned!

Want to Connect?
You can find me at Twitter Github Discord.

Verify Off-chain Results and Whitelist With ECDSA in Solidity Using OpenZeppelin and Ethers.js was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.

Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact service@support.mexc.com for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.

You May Also Like

XRP Ignites As Spot Volume Skyrockets

XRP Ignites As Spot Volume Skyrockets

XRP surprised this weekend with a sudden surge of +2,860% on its spot flows in barely eight hours. This historic peak, occurring in a quiet market, reignites speculation
Share
Coinstats2026/02/09 05:05
Bitcoin-themed tram rolls out in Milan, Italy

Bitcoin-themed tram rolls out in Milan, Italy

The post Bitcoin-themed tram rolls out in Milan, Italy appeared on BitcoinEthereumNews.com. Key Takeaways A Bitcoin-themed tram is running in Milan, Italy, promoting the upcoming Lugano Plan B Forum. The tram features notable Bitcoin branding as it traverses the city, serving as a public promotion of cryptocurrency adoption. A Bitcoin-themed tram has been revealed by Tether CEO Paolo Ardoino as operating in Milan, Italy, promoting the upcoming Lugano Plan B Forum and highlighting the region’s growing embrace of digital assets. The tram features Bitcoin branding and imagery as it travels through the Italian city. Milan has increasingly become a showcase for blockchain-related events and promotions, reflecting Italy’s growing interest in digital assets. Major Italian cities have hosted conferences and industry gatherings that highlight the country’s ambition to play a role in Europe’s digital asset ecosystem. Local adoption of crypto payments has been steadily increasing, supported by Italy’s fintech and innovation agenda. Source: https://cryptobriefing.com/bitcoin-themed-tram-lugano-switzerland/
Share
BitcoinEthereumNews2025/09/18 20:07
United States Initial Jobless Claims 4-week average fell from previous 240.5K to 240K in September 12

United States Initial Jobless Claims 4-week average fell from previous 240.5K to 240K in September 12

The post United States Initial Jobless Claims 4-week average fell from previous 240.5K to 240K in September 12 appeared on BitcoinEthereumNews.com. Information on these pages contains forward-looking statements that involve risks and uncertainties. Markets and instruments profiled on this page are for informational purposes only and should not in any way come across as a recommendation to buy or sell in these assets. You should do your own thorough research before making any investment decisions. FXStreet does not in any way guarantee that this information is free from mistakes, errors, or material misstatements. It also does not guarantee that this information is of a timely nature. Investing in Open Markets involves a great deal of risk, including the loss of all or a portion of your investment, as well as emotional distress. All risks, losses and costs associated with investing, including total loss of principal, are your responsibility. The views and opinions expressed in this article are those of the authors and do not necessarily reflect the official policy or position of FXStreet nor its advertisers. The author will not be held responsible for information that is found at the end of links posted on this page. If not otherwise explicitly mentioned in the body of the article, at the time of writing, the author has no position in any stock mentioned in this article and no business relationship with any company mentioned. The author has not received compensation for writing this article, other than from FXStreet. FXStreet and the author do not provide personalized recommendations. The author makes no representations as to the accuracy, completeness, or suitability of this information. FXStreet and the author will not be liable for any errors, omissions or any losses, injuries or damages arising from this information and its display or use. Errors and omissions excepted. The author and FXStreet are not registered investment advisors and nothing in this article is intended…
Share
BitcoinEthereumNews2025/09/19 02:11