Client Methods
The client methods submodule provides functionality for interacting with Starknet nodes.
Block Methods
Get Block by Number
block, err := client.GetBlockByNumber(blockNumber)
if err != nil {
// Handle error
}
Get Block by Hash
block, err := client.GetBlockByHash(blockHash)
if err != nil {
// Handle error
}
Get Latest Block
block, err := client.GetLatestBlock()
if err != nil {
// Handle error
}
Transaction Methods
Get Transaction by Hash
tx, err := client.GetTransactionByHash(txHash)
if err != nil {
// Handle error
}
Get Transaction Receipt
receipt, err := client.GetTransactionReceipt(txHash)
if err != nil {
// Handle error
}
Send Transaction
txHash, err := client.SendTransaction(tx)
if err != nil {
// Handle error
}
Contract Methods
Get Contract Code
code, err := client.GetContractCode(contractAddress)
if err != nil {
// Handle error
}
Get Contract Storage
storage, err := client.GetContractStorage(contractAddress, key)
if err != nil {
// Handle error
}
Call Contract
result, err := client.CallContract(contractAddress, entryPointSelector, calldata)
if err != nil {
// Handle error
}
Example Usage
// Get the latest block
block, err := client.GetLatestBlock()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Latest block number: %d\n", block.Number)
fmt.Printf("Latest block hash: %s\n", block.Hash)
// Get a transaction
tx, err := client.GetTransactionByHash("0x123...")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Transaction type: %s\n", tx.Type)
fmt.Printf("Transaction status: %s\n", tx.Status)
// Call a contract
result, err := client.CallContract(
"0x456...", // contract address
"0x789...", // entry point selector
[]string{"0xabc..."}, // calldata
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Call result: %s\n", result)