Golang SDK
suave-geth provides an SDK with a set of tools to interact with SUAVE, including deploying contracts, sending transactions, and waiting for transaction receipts.
Installationβ
Make sure you have Go installed on your system and your workspace is set. Then import the SDK package into your Go project:
import "github.com/ethereum/go-ethereum/suave/sdk"
Then, introduce a replace
statement in your go.mod
file to point to the SUAVE Geth fork:
replace github.com/ethereum/go-ethereum => github.com/flashbots/suave-geth
This is a temporary setup, and the SDK will later be spawned into its own library.
Usageβ
Creating a Clientβ
To start interacting with Ethereum smart contracts, instantiate a new client:
client := sdk.NewClient(rpcClient, privateKey, executionNodeAddress)
rpcClient
: Your Ethereum RPC client.privateKey
: An ECDSA private key for signing transactions.executionNodeAddress
: The address of a SUAVE Kettle. Use0xf579de142d98f8379c54105ac944fe133b7a17fe
if working on Toliman.
One way to instantiate a golang RPC client using the go-ethereum rpc module "github.com/ethereum/go-ethereum/rpc" is:
exNodeNetAddr = "http://localhost:8545"
rpcClient, _ := rpc.Dial(exNodeNetAddr)
Deploying a Contractβ
Deploy a smart contract to the network:
transactionResult, err := sdk.DeployContract(bytecode, client)
bytecode
: The compiled bytecode of the smart contract.client
: An instance of yourClient
.
Sending a Transactionβ
Interact with a contract by sending a transaction:
transactionResult, err := contract.SendTransaction(methodName, args, confidentialData)
methodName
: The name of the contract method to call.args
: Arguments for the method call.confidentialData
: Confidential data bytes for the transaction.
Transaction Resultβ
After sending a transaction, you can query the result and receipt:
receipt, err := transactionResult.Wait()
Wait for the transaction to be mined and get the receipt.
hash := transactionResult.Hash()
Retrieve the hash of the transaction.
Client Methodsβ
The following are key methods available on the Client
type:
RPC()
: Retrieves the underlying RPC client.SignTxn(*types.LegacyTx)
: Signs a transaction with the provided private key.SendTransaction(*types.LegacyTx)
: Sends a signed transaction to the network.