In Sway, the b512 type is commonly used to handle public keys and signatures. This guide will explain how the b512 type is defined in Sway, how to visualize a b512 value using the SDK, and how to interact with a contract function that accepts a b512 parameter.
The b512 type in Sway is a wrapper around two b256 types, allowing for the representation of 64-byte values. It is defined as a struct:
Let's consider a contract function that accepts a b512 parameter and returns the same value:
fnecho_b512(input:B512) ->B512 { input}
To call this function and validate the returned value, follow these steps:
const b512 = wallet.publicKey;const { value } =await contract.functions.echo_b512(b512).simulate();expect(value).toEqual(b512);
In this example, we generate a wallet, use its public key as the b512 input, call the echo_b512 contract function, and expect the returned value to match the original input.