FmtCallDataCairo0
Formats function calls into calldata for Cairo 0 contracts.
Function Signature
func FmtCallDataCairo0(callArray []rpc.FunctionCall) []*felt.FeltSource: account.go
Parameters
callArray- Slice of function calls to format
Returns
[]*felt.Felt- Formatted calldata array for Cairo 0 contracts
Usage Example
package main
import (
"fmt"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/account"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/NethermindEth/starknet.go/utils"
)
func main() {
// Define contract address and entry point
contractAddress, _ := utils.HexToFelt("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7")
entryPointSelector := utils.GetSelectorFromNameFelt("transfer")
// Create recipient address
recipient, _ := new(felt.Felt).SetString("0x1234567890abcdef")
// Create function calls
functionCalls := []rpc.FunctionCall{
{
ContractAddress: contractAddress,
EntryPointSelector: entryPointSelector,
Calldata: []*felt.Felt{
recipient, // recipient
new(felt.Felt).SetUint64(100), // amount low
new(felt.Felt).SetUint64(0), // amount high
},
},
}
// Format calldata for Cairo 0
calldata := account.FmtCallDataCairo0(functionCalls)
fmt.Printf("Formatted calldata length: %d\n", len(calldata))
// Display the formatted calldata structure
fmt.Println("\nCalldata structure:")
fmt.Printf(" Number of calls: %s\n", calldata[0])
if len(calldata) > 1 {
fmt.Printf(" First call contract: %s\n", calldata[1])
}
if len(calldata) > 2 {
fmt.Printf(" First call selector: %s\n", calldata[2])
}
// Display all calldata elements
fmt.Println("\nFull calldata array:")
for i, data := range calldata {
fmt.Printf(" [%d]: %s\n", i, data)
}
}Error Handling
This function doesn't return an error. Ensure the function calls array is properly populated before calling.
if len(functionCalls) == 0 {
log.Fatal("No function calls to format")
}
calldata := account.FmtCallDataCairo0(functionCalls)
// Safe to use calldataCommon Use Cases
- Format calldata for multi-call transactions on Cairo 0 accounts
- Prepare calldata for legacy contract interactions
- Convert function calls to the Cairo 0 calldata format required by older account contracts
- Use when interacting with Cairo 0 account contracts that expect the legacy calldata structure

