BuildInvokeTxn
Builds an invoke transaction for executing contract functions.
Function Signature
func BuildInvokeTxn(
functionCalls []rpc.FunctionCall,
opts *BuildOptions,
) (*rpc.InvokeTxnV3, error)Source: transactions.go
Parameters
functionCalls([]rpc.FunctionCall): Array of function calls to executeopts(*BuildOptions): Transaction build options including nonce, max fee, resource bounds
BuildOptions Structure
type BuildOptions struct {
Nonce *felt.Felt
MaxFee *felt.Felt
ResourceBounds rpc.ResourceBoundsMapping
Tip uint64
PaymasterData []*felt.Felt
AccountDeployment []*felt.Felt
NonceDataMode rpc.DataAvailabilityMode
FeeMode rpc.DataAvailabilityMode
}Returns
*rpc.InvokeTxnV3: Fully constructed invoke transaction V3error: Error if build fails
Usage Example
package main
import (
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/NethermindEth/starknet.go/utils"
)
func main() {
// Define contract calls
calls := []rpc.FunctionCall{
{
ContractAddress: contractAddr,
EntryPointSelector: transferSelector,
Calldata: []*felt.Felt{recipientAddr, amount},
},
}
// Build transaction
txn, err := utils.BuildInvokeTxn(calls, &utils.BuildOptions{
Nonce: currentNonce,
MaxFee: maxFeeAmount,
ResourceBounds: rpc.ResourceBoundsMapping{
L1Gas: rpc.ResourceBounds{
MaxAmount: new(felt.Felt).SetUint64(10000),
MaxPricePerUnit: new(felt.Felt).SetUint64(100),
},
},
})
if err != nil {
panic(err)
}
// txn is ready to be signed and sent
}Use Cases
1. ERC20 Token Transfer
transferCall := rpc.FunctionCall{
ContractAddress: erc20Address,
EntryPointSelector: utils.GetSelectorFromNameFelt("transfer"),
Calldata: []*felt.Felt{recipientAddress, amount},
}
txn, _ := utils.BuildInvokeTxn([]rpc.FunctionCall{transferCall}, opts)2. Multi-Call Transaction
calls := []rpc.FunctionCall{
{ContractAddress: contract1, EntryPointSelector: selector1, Calldata: data1},
{ContractAddress: contract2, EntryPointSelector: selector2, Calldata: data2},
}
txn, _ := utils.BuildInvokeTxn(calls, opts)3. NFT Minting
mintCall := rpc.FunctionCall{
ContractAddress: nftContract,
EntryPointSelector: utils.GetSelectorFromNameFelt("mint"),
Calldata: []*felt.Felt{toAddress, tokenId},
}
txn, _ := utils.BuildInvokeTxn([]rpc.FunctionCall{mintCall}, opts)See Also
- Transaction Construction walks through building complete invoke transactions
- Fee Estimation and Resource Bounds for calculating transaction fees
- Custom Resource Bounds if you need fine-grained control over resources

