toBlobs
Transforms arbitrary data into blobs for EIP-4844 transactions
Loading...
Transforms arbitrary data into blobs for EIP-4844 transactions
Transforms arbitrary data into blobs for EIP-4844 transactions. Each blob is exactly 131,072 bytes (128 KB).
:::warning[Warning]
This function transforms data into viem-go-shaped blobs. It is designed to be used with FromBlobs to convert back to the original data.
:::
import "github.com/ChefBingbong/viem-go/utils/blob"import "github.com/ChefBingbong/viem-go/utils/blob"
// Transform data into blobsblobs, err := blob.ToBlobs([]byte("hello world"))if err != nil { log.Fatal(err)}// Returns one or more 131072-byte blobs
// Transform hex data into blobsblobs, err = blob.ToBlobsFromHex("0x68656c6c6f20776f726c64")if err != nil { log.Fatal(err)}
// Get blobs as hex stringshexBlobs, err := blob.ToBlobsHex([]byte("hello world"))if err != nil { log.Fatal(err)}// []string{"0x...", ...}([][]byte, error) for ToBlobs, ([]string, error) for ToBlobsHexAn array of blobs. Each blob is exactly 131,072 bytes (128 KB).
[]byte for ToBlobs, string for ToBlobsFromHexThe data to transform into blobs. Maximum size is 2,097,152 bytes (2 MB) per transaction.
// Transform bytes into blobsblobs, _ := blob.ToBlobs([]byte("hello world"))
// Transform hex string into blobsblobs, _ = blob.ToBlobsFromHex("0x68656c6c6f20776f726c64")The encoding follows EIP-4844 requirements:
0x00 byte to prevent overflow0x80) marks the end of the dataTransforms bytes into blobs:
blobs, _ := blob.ToBlobs([]byte("hello world"))
Transforms bytes into hex-encoded blobs:
hexBlobs, _ := blob.ToBlobsHex([]byte("hello world"))
Transforms hex-encoded data into blobs:
blobs, _ := blob.ToBlobsFromHex("0x68656c6c6f20776f726c64")