Sending Transactions
Learn how to interact with the CLoud send transactions onchain.
note
To use embedded signers, first you need to authenticate your users. Follow the steps to set up embedded signers for your users with the embedded signer overview.
Quickstart#
1. Create a transactionIntent - Server side#
Create a request to your backend to create a transactionIntent. In the body of the request:
- Include the
player
that signs the transaction. - Include the
policy
that interacts with the contract for gas. If non-existen the user will need to have gas tokens. - Include
optimistic
if you want the transactions to be confirmed faster.
Depending on the type of transaction you're creating you'll define interactions
. The interactions
field is an array of objects that contain the information of the contract to interact with, the function to call, and the arguments to pass to the function.
- the interactions field contains the
contract
that has previously been added to Openfort. - the
functionName
defines the function to call from within the contract. - If there exist more than one function with the same name, the
functionArgs
will be used to determine which function to call.
2. Sign the transactionIntent with the signer. - Client side#
Use the nextAction
returned by the backend to sign the transaction with the embedded signer.
The transaction will be automatically signed and broadcasted by using the sendSignatureTransactionIntentRequest
method.
_29const handleCollectButtonClick = async () => {_29 try {_29 setCollectLoading(true);_29 const collectResponse = await fetch(`/api/examples/protected-collect`, {_29 method: "POST",_29 headers: {_29 "Content-Type": "application/json",_29 },_29 });_29 const collectResponseJSON = await collectResponse.json();_29_29 if (collectResponseJSON.data?.nextAction) {_29 console.log("config", config);_29_29 const response = await openfort.sendSignatureTransactionIntentRequest(_29 collectResponseJSON.data.id,_29 collectResponseJSON.data.nextAction.payload.userOperationHash_29 );_29 console.log("response", response);_29 }_29_29 console.log("success:", collectResponseJSON.data);_29 alert("Action performed successfully");_29 } catch (error) {_29 console.error("Error:", error);_29 } finally {_29 setCollectLoading(false);_29 }_29};
If you've integrated Openfort with another web3 library, you can also use that library's syntax for requesting a transaction from the client-side:
Library | Method |
---|---|
Ethers | Use the signer's sendTransaction method. |
Wagmi | Use the useSendTransaction hook. |