packetToBytes
Encodes an ENS name into a DNS packet ByteArray
Loading...
Encodes an ENS name into a DNS packet ByteArray
Encodes an ENS name into a DNS packet ByteArray. This is used for the off-chain resolution protocol (CCIP-Read).
import "github.com/ChefBingbong/viem-go/utils/ens"import "github.com/ChefBingbong/viem-go/utils/ens"
// Encode ENS name to DNS packetbytes := ens.PacketToBytes("vitalik.eth")// []byte{7, 'v', 'i', 't', 'a', 'l', 'i', 'k', 3, 'e', 't', 'h', 0}
// Get as hex stringhex := ens.PacketToBytesHex("vitalik.eth")// "0x077669746c696b0365746800"[]byte for PacketToBytes, string for PacketToBytesHexThe DNS packet as bytes or hex string.
stringThe ENS name to encode as a DNS packet.
bytes := ens.PacketToBytes("vitalik.eth")// []byte{7, 'v', 'i', 't', 'a', 'l', 'i', 'k', 3, 'e', 't', 'h', 0}The DNS packet format follows DNS encoding:
Example: "vitalik.eth" becomes:
[7] 'v' 'i' 't' 'a' 'l' 'i' 'k' [3] 'e' 't' 'h' [0]
Encodes an ENS name to DNS packet bytes:
bytes := ens.PacketToBytes("vitalik.eth")
Encodes an ENS name to DNS packet hex string:
hex := ens.PacketToBytesHex("vitalik.eth")
[]byte{0}