Backend-to-Backend
Access user sessions directly from your backend.
Interactions with the TDK API typically require an authenticated user to make the requests from the client side. However, the nature of Treasure Connect’s on-chain session creation also allows games to act on a Treasure Account’s behalf through the backend only for the duration and scope of the session.
Setup
Get backend wallet
Check in with the Treasure team to receive your backend wallet address (used in your app client and backend) and AWS KMS key ARN (used in the next step and your backend).
Create AWS role
Create a new IAM role in your AWS account with the following policy attached, filling in the AWS KMS key ARN from the previous step:
Provide the Treasure team with the new role’s ARN to complete the setup process.
Prerequisites
- TDK Core library installed in your project.
- The Treasure Account you want to act on behalf of must have already created a session through the client-side TDK with the same
backendWallet
address that will be used to sign the backend-to-backend request. See here for more information on starting sessions from a React-based application.
Usage
The key change in the above flow is that the TDKAPI
client doesn’t need to be created with a user’s auth token. Instead, the account address is specified in the transaction options, along with a payload signed by the backend wallet that will be verified by the TDK API.
See full generateAccountSignature
function documentation for more AWS KMS client configuration options.