Education

The New Art Blocks Smart Contract

by Art Blocks Engineering

No items found.

As part of the series of our recent Art Blocks updates, we have released a new ERC-721 smart contract that saves collectors approximately 67% of their transaction costs (gas) when minting new projects, and saves artists approximately 67% of their transaction costs when uploading their project scripts to the blockchain.

In this article, we provide a technical overview of some of the smart contract changes that led to these efficiency gains, and why we think these innovations will benefit the entire NFT space.

Minting Gas Efficiency: Reducing costs for collectors

For most users, we think the most exciting part of our new contract will be the major reduction in gas costs when minting new pieces. Depending on network conditions, at times, the gas cost of minting a new Art Blocks NFT has historically been a sizable portion of the total cost. Improving gas efficiency is one way we can help reduce the portion of a purchase spent on transaction fees.

The first optimization we’ve made is utilizing storage data packing to minimize the quantity of 32-byte storage slots accessed and written to during mint transactions. What is data packing? In a simple example, consider the case in which, instead of using 32 bytes to store an unsigned integer that has a value between 0 and 100, the same information can be stored in  only 1 byte (since 2⁸ is greater than 100). If that process is repeated for all variables in a contract, a much lower overall storage footprint can be achieved, and therefore, significantly less gas required! When implemented correctly, this can be a very powerful way to reduce transaction costs on the Ethereum blockchain.

Second, we switched from deriving from OpenZeppelin’s ERC721Enumerable token contract to our own forked version of OpenZeppelin’s ERC721 token contract. Major improvements in the robustness of blockchain indexing technology, such as our public, decentralized subgraph, have made implementation of OpenZeppelin’s gas-hungry Enumerable extension suboptimal. Most NFT contracts do not implement ERC721Enumerable, and it is not part of the ERC-721 token standard. Additionally, while searching for unused storage space in OpenZeppelin’s ERC721 implementation, we found 12 unused bytes adjacent to each token’s owner address. While project scripts expect a token’s hash to be 32 bytes, math says that 12 bytes of randomness is sufficient to avoid hash collisions in our maximum allowed project edition size of one million tokens. Additionally, a 12 byte stored hash “seed” can be hashed to generate a backwards-compatible 32 byte token hash, all without sacrificing any uniqueness properties of tokens across a project. We decided to fork OpenZeppelin’s ERC721 implementation and pack each token’s on-chain hash seed in those 12 unused bytes, which reduced mint costs by approximately 15% alone!

Third, we re-organized logic throughout our mint transaction to maximize use of (cheap) data in memory, and minimize use of (expensive) data retrieval from storage or other contracts. This is quite straightforward, but can lead to meaningful gas performance improvements.

These three types of changes were responsible for most of our mint transaction efficiency gains, and we hope other developers can use these types of patterns to improve their own NFT contract implementations.

Artist Script Upload Gas Efficiency: Reducing costs for artists

At Art Blocks, we aim to provide the artists releasing on our platform the best set of tools for uploading and preserving their artwork via blockchain technology. Among other things, but perhaps most paramount, we are entrusted with storing an artist’s generative art script in such a way that it is immutable, accessible, and indefinitely available: we empower the creation of “eternal artworks.” Until this update, our contracts utilized consecutive 32-byte contract storage slots to store art scripts as string data. This is the data storage method currently used for nearly all production smart contracts looking to store large byte arrays or strings on the Ethereum blockchain.

Recently, we were inspired by some smart folks at 0xsequence who came up with a very novel concept of using contract bytecode as a blob-storage mechanism for smart contracts. Their SSTORE2 library was the inspiration for our new BytecodeStorage library. Our BytecodeStorage library makes on-chain storage of artist’s scripts about 67% more gas efficient! We added some new, innovative capabilities such as enabling self-destruction of script-bytecode contracts (to do our part in reducing chain state bloat) and recording the contract which deployed the script-bytecode storage contract in its bytecode.

We think our new BytecodeStorage library helps push the entire NFT space forward by making on-chain data storage cheaper, and changing the perception of how large chunks of data may be stored. We hope the implementation inspires others to continue to innovate in this space.

Conclusion

Our new smart contract delivers meaningful gas efficiency gains for users and artists on the Art Blocks platform. We are proud to push the space forward with innovative solutions such as packing token hash seeds in the same slot as token owners and utilizing contract bytecode as an efficient form of script storage.

Finally, we hope you are as enthusiastic as we are about continuing to innovate and improve the Art Blocks product! We are still early 😄,  and there are many exciting blockchain scaling technologies in everyone’s future! (Danksharding anyone?)

Want More?

At Art Blocks, we design all of our smart contracts in public. This is in line with our core values of transparency and decentralization. It also enables us to engage in high quality discussions and to receive expert feedback from many great developer teams from the greater Ethereum community. An entire history of the new V3 core development process is available in our open source GitHub artblocks-contracts repository.

As part of the series of our recent Art Blocks updates, we have released a new ERC-721 smart contract that saves collectors approximately 67% of their transaction costs (gas) when minting new projects, and saves artists approximately 67% of their transaction costs when uploading their project scripts to the blockchain.

In this article, we provide a technical overview of some of the smart contract changes that led to these efficiency gains, and why we think these innovations will benefit the entire NFT space.

Minting Gas Efficiency: Reducing costs for collectors

For most users, we think the most exciting part of our new contract will be the major reduction in gas costs when minting new pieces. Depending on network conditions, at times, the gas cost of minting a new Art Blocks NFT has historically been a sizable portion of the total cost. Improving gas efficiency is one way we can help reduce the portion of a purchase spent on transaction fees.

The first optimization we’ve made is utilizing storage data packing to minimize the quantity of 32-byte storage slots accessed and written to during mint transactions. What is data packing? In a simple example, consider the case in which, instead of using 32 bytes to store an unsigned integer that has a value between 0 and 100, the same information can be stored in  only 1 byte (since 2⁸ is greater than 100). If that process is repeated for all variables in a contract, a much lower overall storage footprint can be achieved, and therefore, significantly less gas required! When implemented correctly, this can be a very powerful way to reduce transaction costs on the Ethereum blockchain.

Second, we switched from deriving from OpenZeppelin’s ERC721Enumerable token contract to our own forked version of OpenZeppelin’s ERC721 token contract. Major improvements in the robustness of blockchain indexing technology, such as our public, decentralized subgraph, have made implementation of OpenZeppelin’s gas-hungry Enumerable extension suboptimal. Most NFT contracts do not implement ERC721Enumerable, and it is not part of the ERC-721 token standard. Additionally, while searching for unused storage space in OpenZeppelin’s ERC721 implementation, we found 12 unused bytes adjacent to each token’s owner address. While project scripts expect a token’s hash to be 32 bytes, math says that 12 bytes of randomness is sufficient to avoid hash collisions in our maximum allowed project edition size of one million tokens. Additionally, a 12 byte stored hash “seed” can be hashed to generate a backwards-compatible 32 byte token hash, all without sacrificing any uniqueness properties of tokens across a project. We decided to fork OpenZeppelin’s ERC721 implementation and pack each token’s on-chain hash seed in those 12 unused bytes, which reduced mint costs by approximately 15% alone!

Third, we re-organized logic throughout our mint transaction to maximize use of (cheap) data in memory, and minimize use of (expensive) data retrieval from storage or other contracts. This is quite straightforward, but can lead to meaningful gas performance improvements.

These three types of changes were responsible for most of our mint transaction efficiency gains, and we hope other developers can use these types of patterns to improve their own NFT contract implementations.

Artist Script Upload Gas Efficiency: Reducing costs for artists

At Art Blocks, we aim to provide the artists releasing on our platform the best set of tools for uploading and preserving their artwork via blockchain technology. Among other things, but perhaps most paramount, we are entrusted with storing an artist’s generative art script in such a way that it is immutable, accessible, and indefinitely available: we empower the creation of “eternal artworks.” Until this update, our contracts utilized consecutive 32-byte contract storage slots to store art scripts as string data. This is the data storage method currently used for nearly all production smart contracts looking to store large byte arrays or strings on the Ethereum blockchain.

Recently, we were inspired by some smart folks at 0xsequence who came up with a very novel concept of using contract bytecode as a blob-storage mechanism for smart contracts. Their SSTORE2 library was the inspiration for our new BytecodeStorage library. Our BytecodeStorage library makes on-chain storage of artist’s scripts about 67% more gas efficient! We added some new, innovative capabilities such as enabling self-destruction of script-bytecode contracts (to do our part in reducing chain state bloat) and recording the contract which deployed the script-bytecode storage contract in its bytecode.

We think our new BytecodeStorage library helps push the entire NFT space forward by making on-chain data storage cheaper, and changing the perception of how large chunks of data may be stored. We hope the implementation inspires others to continue to innovate in this space.

Conclusion

Our new smart contract delivers meaningful gas efficiency gains for users and artists on the Art Blocks platform. We are proud to push the space forward with innovative solutions such as packing token hash seeds in the same slot as token owners and utilizing contract bytecode as an efficient form of script storage.

Finally, we hope you are as enthusiastic as we are about continuing to innovate and improve the Art Blocks product! We are still early 😄,  and there are many exciting blockchain scaling technologies in everyone’s future! (Danksharding anyone?)

Want More?

At Art Blocks, we design all of our smart contracts in public. This is in line with our core values of transparency and decentralization. It also enables us to engage in high quality discussions and to receive expert feedback from many great developer teams from the greater Ethereum community. An entire history of the new V3 core development process is available in our open source GitHub artblocks-contracts repository.

As part of the series of our recent Art Blocks updates, we have released a new ERC-721 smart contract that saves collectors approximately 67% of their transaction costs (gas) when minting new projects, and saves artists approximately 67% of their transaction costs when uploading their project scripts to the blockchain.

In this article, we provide a technical overview of some of the smart contract changes that led to these efficiency gains, and why we think these innovations will benefit the entire NFT space.

Minting Gas Efficiency: Reducing costs for collectors

For most users, we think the most exciting part of our new contract will be the major reduction in gas costs when minting new pieces. Depending on network conditions, at times, the gas cost of minting a new Art Blocks NFT has historically been a sizable portion of the total cost. Improving gas efficiency is one way we can help reduce the portion of a purchase spent on transaction fees.

The first optimization we’ve made is utilizing storage data packing to minimize the quantity of 32-byte storage slots accessed and written to during mint transactions. What is data packing? In a simple example, consider the case in which, instead of using 32 bytes to store an unsigned integer that has a value between 0 and 100, the same information can be stored in  only 1 byte (since 2⁸ is greater than 100). If that process is repeated for all variables in a contract, a much lower overall storage footprint can be achieved, and therefore, significantly less gas required! When implemented correctly, this can be a very powerful way to reduce transaction costs on the Ethereum blockchain.

Second, we switched from deriving from OpenZeppelin’s ERC721Enumerable token contract to our own forked version of OpenZeppelin’s ERC721 token contract. Major improvements in the robustness of blockchain indexing technology, such as our public, decentralized subgraph, have made implementation of OpenZeppelin’s gas-hungry Enumerable extension suboptimal. Most NFT contracts do not implement ERC721Enumerable, and it is not part of the ERC-721 token standard. Additionally, while searching for unused storage space in OpenZeppelin’s ERC721 implementation, we found 12 unused bytes adjacent to each token’s owner address. While project scripts expect a token’s hash to be 32 bytes, math says that 12 bytes of randomness is sufficient to avoid hash collisions in our maximum allowed project edition size of one million tokens. Additionally, a 12 byte stored hash “seed” can be hashed to generate a backwards-compatible 32 byte token hash, all without sacrificing any uniqueness properties of tokens across a project. We decided to fork OpenZeppelin’s ERC721 implementation and pack each token’s on-chain hash seed in those 12 unused bytes, which reduced mint costs by approximately 15% alone!

Third, we re-organized logic throughout our mint transaction to maximize use of (cheap) data in memory, and minimize use of (expensive) data retrieval from storage or other contracts. This is quite straightforward, but can lead to meaningful gas performance improvements.

These three types of changes were responsible for most of our mint transaction efficiency gains, and we hope other developers can use these types of patterns to improve their own NFT contract implementations.

Artist Script Upload Gas Efficiency: Reducing costs for artists

At Art Blocks, we aim to provide the artists releasing on our platform the best set of tools for uploading and preserving their artwork via blockchain technology. Among other things, but perhaps most paramount, we are entrusted with storing an artist’s generative art script in such a way that it is immutable, accessible, and indefinitely available: we empower the creation of “eternal artworks.” Until this update, our contracts utilized consecutive 32-byte contract storage slots to store art scripts as string data. This is the data storage method currently used for nearly all production smart contracts looking to store large byte arrays or strings on the Ethereum blockchain.

Recently, we were inspired by some smart folks at 0xsequence who came up with a very novel concept of using contract bytecode as a blob-storage mechanism for smart contracts. Their SSTORE2 library was the inspiration for our new BytecodeStorage library. Our BytecodeStorage library makes on-chain storage of artist’s scripts about 67% more gas efficient! We added some new, innovative capabilities such as enabling self-destruction of script-bytecode contracts (to do our part in reducing chain state bloat) and recording the contract which deployed the script-bytecode storage contract in its bytecode.

We think our new BytecodeStorage library helps push the entire NFT space forward by making on-chain data storage cheaper, and changing the perception of how large chunks of data may be stored. We hope the implementation inspires others to continue to innovate in this space.

Conclusion

Our new smart contract delivers meaningful gas efficiency gains for users and artists on the Art Blocks platform. We are proud to push the space forward with innovative solutions such as packing token hash seeds in the same slot as token owners and utilizing contract bytecode as an efficient form of script storage.

Finally, we hope you are as enthusiastic as we are about continuing to innovate and improve the Art Blocks product! We are still early 😄,  and there are many exciting blockchain scaling technologies in everyone’s future! (Danksharding anyone?)

Want More?

At Art Blocks, we design all of our smart contracts in public. This is in line with our core values of transparency and decentralization. It also enables us to engage in high quality discussions and to receive expert feedback from many great developer teams from the greater Ethereum community. An entire history of the new V3 core development process is available in our open source GitHub artblocks-contracts repository.

As part of the series of our recent Art Blocks updates, we have released a new ERC-721 smart contract that saves collectors approximately 67% of their transaction costs (gas) when minting new projects, and saves artists approximately 67% of their transaction costs when uploading their project scripts to the blockchain.

In this article, we provide a technical overview of some of the smart contract changes that led to these efficiency gains, and why we think these innovations will benefit the entire NFT space.

Minting Gas Efficiency: Reducing costs for collectors

For most users, we think the most exciting part of our new contract will be the major reduction in gas costs when minting new pieces. Depending on network conditions, at times, the gas cost of minting a new Art Blocks NFT has historically been a sizable portion of the total cost. Improving gas efficiency is one way we can help reduce the portion of a purchase spent on transaction fees.

The first optimization we’ve made is utilizing storage data packing to minimize the quantity of 32-byte storage slots accessed and written to during mint transactions. What is data packing? In a simple example, consider the case in which, instead of using 32 bytes to store an unsigned integer that has a value between 0 and 100, the same information can be stored in  only 1 byte (since 2⁸ is greater than 100). If that process is repeated for all variables in a contract, a much lower overall storage footprint can be achieved, and therefore, significantly less gas required! When implemented correctly, this can be a very powerful way to reduce transaction costs on the Ethereum blockchain.

Second, we switched from deriving from OpenZeppelin’s ERC721Enumerable token contract to our own forked version of OpenZeppelin’s ERC721 token contract. Major improvements in the robustness of blockchain indexing technology, such as our public, decentralized subgraph, have made implementation of OpenZeppelin’s gas-hungry Enumerable extension suboptimal. Most NFT contracts do not implement ERC721Enumerable, and it is not part of the ERC-721 token standard. Additionally, while searching for unused storage space in OpenZeppelin’s ERC721 implementation, we found 12 unused bytes adjacent to each token’s owner address. While project scripts expect a token’s hash to be 32 bytes, math says that 12 bytes of randomness is sufficient to avoid hash collisions in our maximum allowed project edition size of one million tokens. Additionally, a 12 byte stored hash “seed” can be hashed to generate a backwards-compatible 32 byte token hash, all without sacrificing any uniqueness properties of tokens across a project. We decided to fork OpenZeppelin’s ERC721 implementation and pack each token’s on-chain hash seed in those 12 unused bytes, which reduced mint costs by approximately 15% alone!

Third, we re-organized logic throughout our mint transaction to maximize use of (cheap) data in memory, and minimize use of (expensive) data retrieval from storage or other contracts. This is quite straightforward, but can lead to meaningful gas performance improvements.

These three types of changes were responsible for most of our mint transaction efficiency gains, and we hope other developers can use these types of patterns to improve their own NFT contract implementations.

Artist Script Upload Gas Efficiency: Reducing costs for artists

At Art Blocks, we aim to provide the artists releasing on our platform the best set of tools for uploading and preserving their artwork via blockchain technology. Among other things, but perhaps most paramount, we are entrusted with storing an artist’s generative art script in such a way that it is immutable, accessible, and indefinitely available: we empower the creation of “eternal artworks.” Until this update, our contracts utilized consecutive 32-byte contract storage slots to store art scripts as string data. This is the data storage method currently used for nearly all production smart contracts looking to store large byte arrays or strings on the Ethereum blockchain.

Recently, we were inspired by some smart folks at 0xsequence who came up with a very novel concept of using contract bytecode as a blob-storage mechanism for smart contracts. Their SSTORE2 library was the inspiration for our new BytecodeStorage library. Our BytecodeStorage library makes on-chain storage of artist’s scripts about 67% more gas efficient! We added some new, innovative capabilities such as enabling self-destruction of script-bytecode contracts (to do our part in reducing chain state bloat) and recording the contract which deployed the script-bytecode storage contract in its bytecode.

We think our new BytecodeStorage library helps push the entire NFT space forward by making on-chain data storage cheaper, and changing the perception of how large chunks of data may be stored. We hope the implementation inspires others to continue to innovate in this space.

Conclusion

Our new smart contract delivers meaningful gas efficiency gains for users and artists on the Art Blocks platform. We are proud to push the space forward with innovative solutions such as packing token hash seeds in the same slot as token owners and utilizing contract bytecode as an efficient form of script storage.

Finally, we hope you are as enthusiastic as we are about continuing to innovate and improve the Art Blocks product! We are still early 😄,  and there are many exciting blockchain scaling technologies in everyone’s future! (Danksharding anyone?)

Want More?

At Art Blocks, we design all of our smart contracts in public. This is in line with our core values of transparency and decentralization. It also enables us to engage in high quality discussions and to receive expert feedback from many great developer teams from the greater Ethereum community. An entire history of the new V3 core development process is available in our open source GitHub artblocks-contracts repository.

As part of the series of our recent Art Blocks updates, we have released a new ERC-721 smart contract that saves collectors approximately 67% of their transaction costs (gas) when minting new projects, and saves artists approximately 67% of their transaction costs when uploading their project scripts to the blockchain.

In this article, we provide a technical overview of some of the smart contract changes that led to these efficiency gains, and why we think these innovations will benefit the entire NFT space.

Minting Gas Efficiency: Reducing costs for collectors

For most users, we think the most exciting part of our new contract will be the major reduction in gas costs when minting new pieces. Depending on network conditions, at times, the gas cost of minting a new Art Blocks NFT has historically been a sizable portion of the total cost. Improving gas efficiency is one way we can help reduce the portion of a purchase spent on transaction fees.

The first optimization we’ve made is utilizing storage data packing to minimize the quantity of 32-byte storage slots accessed and written to during mint transactions. What is data packing? In a simple example, consider the case in which, instead of using 32 bytes to store an unsigned integer that has a value between 0 and 100, the same information can be stored in  only 1 byte (since 2⁸ is greater than 100). If that process is repeated for all variables in a contract, a much lower overall storage footprint can be achieved, and therefore, significantly less gas required! When implemented correctly, this can be a very powerful way to reduce transaction costs on the Ethereum blockchain.

Second, we switched from deriving from OpenZeppelin’s ERC721Enumerable token contract to our own forked version of OpenZeppelin’s ERC721 token contract. Major improvements in the robustness of blockchain indexing technology, such as our public, decentralized subgraph, have made implementation of OpenZeppelin’s gas-hungry Enumerable extension suboptimal. Most NFT contracts do not implement ERC721Enumerable, and it is not part of the ERC-721 token standard. Additionally, while searching for unused storage space in OpenZeppelin’s ERC721 implementation, we found 12 unused bytes adjacent to each token’s owner address. While project scripts expect a token’s hash to be 32 bytes, math says that 12 bytes of randomness is sufficient to avoid hash collisions in our maximum allowed project edition size of one million tokens. Additionally, a 12 byte stored hash “seed” can be hashed to generate a backwards-compatible 32 byte token hash, all without sacrificing any uniqueness properties of tokens across a project. We decided to fork OpenZeppelin’s ERC721 implementation and pack each token’s on-chain hash seed in those 12 unused bytes, which reduced mint costs by approximately 15% alone!

Third, we re-organized logic throughout our mint transaction to maximize use of (cheap) data in memory, and minimize use of (expensive) data retrieval from storage or other contracts. This is quite straightforward, but can lead to meaningful gas performance improvements.

These three types of changes were responsible for most of our mint transaction efficiency gains, and we hope other developers can use these types of patterns to improve their own NFT contract implementations.

Artist Script Upload Gas Efficiency: Reducing costs for artists

At Art Blocks, we aim to provide the artists releasing on our platform the best set of tools for uploading and preserving their artwork via blockchain technology. Among other things, but perhaps most paramount, we are entrusted with storing an artist’s generative art script in such a way that it is immutable, accessible, and indefinitely available: we empower the creation of “eternal artworks.” Until this update, our contracts utilized consecutive 32-byte contract storage slots to store art scripts as string data. This is the data storage method currently used for nearly all production smart contracts looking to store large byte arrays or strings on the Ethereum blockchain.

Recently, we were inspired by some smart folks at 0xsequence who came up with a very novel concept of using contract bytecode as a blob-storage mechanism for smart contracts. Their SSTORE2 library was the inspiration for our new BytecodeStorage library. Our BytecodeStorage library makes on-chain storage of artist’s scripts about 67% more gas efficient! We added some new, innovative capabilities such as enabling self-destruction of script-bytecode contracts (to do our part in reducing chain state bloat) and recording the contract which deployed the script-bytecode storage contract in its bytecode.

We think our new BytecodeStorage library helps push the entire NFT space forward by making on-chain data storage cheaper, and changing the perception of how large chunks of data may be stored. We hope the implementation inspires others to continue to innovate in this space.

Conclusion

Our new smart contract delivers meaningful gas efficiency gains for users and artists on the Art Blocks platform. We are proud to push the space forward with innovative solutions such as packing token hash seeds in the same slot as token owners and utilizing contract bytecode as an efficient form of script storage.

Finally, we hope you are as enthusiastic as we are about continuing to innovate and improve the Art Blocks product! We are still early 😄,  and there are many exciting blockchain scaling technologies in everyone’s future! (Danksharding anyone?)

Want More?

At Art Blocks, we design all of our smart contracts in public. This is in line with our core values of transparency and decentralization. It also enables us to engage in high quality discussions and to receive expert feedback from many great developer teams from the greater Ethereum community. An entire history of the new V3 core development process is available in our open source GitHub artblocks-contracts repository.

Latest from Spectrum