safewallet

package
v0.0.0-...-9bc3b21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EIP712_SAFE_TX_TYPE = "" /* 164-byte string literal not displayed */
)

EIP712 domain and type constants for Safe transactions

Variables

View Source
var ABI_SafeWallet = `` /* 1684-byte string literal not displayed */

Functions

func CalcSafeAddress

func CalcSafeAddress(
	safe,
	safeL2,
	compatibilityFallbackHandler,
	safeToL2Setup,
	safeProxyFactory common.Address,
	creationCode string,
	accounts []common.Address,
	threshold *big.Int,
	nonce *big.Int,
	paymentReceiver common.Address,
) (common.Address, error)

func ExampleExecTransaction

func ExampleExecTransaction()

ExampleExecTransaction demonstrates how to use ExecTransactionData and ParseExecTransactionResult functions

func ExampleExecTransactionWithSignature

func ExampleExecTransactionWithSignature()

ExampleExecTransactionWithSignature demonstrates how to use the signature with execTransaction

func ExampleGetNonce

func ExampleGetNonce()

ExampleGetNonce demonstrates how to use GetNonceData and ParseNonceResult functions

func ExampleMultipleSigners

func ExampleMultipleSigners()

ExampleMultipleSigners demonstrates how to collect signatures from multiple owners

func ExampleSignSafeTransaction

func ExampleSignSafeTransaction()

ExampleSignSafeTransaction demonstrates how to sign a Safe transaction using a private key

func ExampleUseNonce

func ExampleUseNonce()

ExampleUseNonce shows how to use the nonce value in a transaction

func ExecTransactionData

func ExecTransactionData(
	to common.Address,
	value *big.Int,
	txData []byte,
	operation uint8,
	safeTxGas *big.Int,
	baseGas *big.Int,
	gasPrice *big.Int,
	gasToken common.Address,
	refundReceiver common.Address,
	signatures []byte,
) ([]byte, error)

ExecTransactionData generates contract call data for execTransaction function This function is used to execute a transaction through a Safe wallet to: destination address of the transaction value: ether value of the transaction txData: data payload of the transaction operation: operation type (0 = call, 1 = delegatecall) safeTxGas: gas that should be used for the safe transaction baseGas: gas costs for data used to trigger the safe transaction gasPrice: gas price that should be used for the payment calculation gasToken: token address (or 0 if ETH) that is used for the payment refundReceiver: address of receiver of gas payment (or 0 if tx.origin) signatures: packed signature data ({bytes32 r}{bytes32 s}{uint8 v})

func FormatSignatureBytes

func FormatSignatureBytes(signatures ...[]byte) []byte

FormatSignatureBytes formats multiple signatures into the format expected by the Safe contract Each signature should be 65 bytes (r, s, v) The signatures should be sorted by signer address (ascending order)

func GetNonce

func GetNonce(ctx context.Context, client *ethclient.Client, safeAddress common.Address, block *big.Int) (*big.Int, error)

func GetNonceData

func GetNonceData() ([]byte, error)

GetNonceData generates contract call data for nonce function This function is used to query the current nonce of a Safe wallet

func GetSafeTransactionHash

func GetSafeTransactionHash(safeAddress common.Address, chainId *big.Int, txData SafeTransactionData) (common.Hash, error)

GetSafeTransactionHash calculates the EIP712 hash of a Safe transaction safeAddress: the address of the Safe contract chainId: the chain ID of the network txData: the Safe transaction data

func GetSignerAddress

func GetSignerAddress(txHash common.Hash, signature []byte) (common.Address, error)

GetSignerAddress recovers the signer address from a signature and transaction hash txHash: the EIP712 hash of the Safe transaction signature: the 65-byte signature (r, s, v) Returns the address of the signer

func ParseExecTransactionResult

func ParseExecTransactionResult(result []byte) (bool, error)

ParseExecTransactionResult parses the result of an execTransaction call and returns the success status result: the raw result bytes from the contract call

func ParseNonceResult

func ParseNonceResult(result []byte) (*big.Int, error)

ParseNonceResult parses the result of a nonce call and returns the nonce as a big.Int result: the raw result bytes from the contract call

func SignSafeTransaction

func SignSafeTransaction(safeAddress common.Address, chainId *big.Int, txData SafeTransactionData, privateKey *ecdsa.PrivateKey) ([]byte, error)

SignSafeTransaction signs a Safe transaction using a private key safeAddress: the address of the Safe contract chainId: the chain ID of the network txData: the Safe transaction data privateKey: the private key to sign with Returns the signature in the format required by the Safe contract (65 bytes: r, s, v)

func SignSafeTransactionHash

func SignSafeTransactionHash(txHash common.Hash, privateKey *ecdsa.PrivateKey) ([]byte, error)

SignSafeTransactionHash signs a Safe transaction hash using a private key txHash: the EIP712 hash of the Safe transaction privateKey: the private key to sign with Returns the signature in the format required by the Safe contract (65 bytes: r, s, v)

Types

type SafeTransactionData

type SafeTransactionData struct {
	To             common.Address
	Value          *big.Int
	Data           []byte
	Operation      uint8
	SafeTxGas      *big.Int
	BaseGas        *big.Int
	GasPrice       *big.Int
	GasToken       common.Address
	RefundReceiver common.Address
	Nonce          *big.Int
}

SafeTransactionData represents the data of a Safe transaction

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL