Blockchain Transactions (Optional)

Submit a transaction using a user's session token for your app or game.

Step 1: Get A Session Access Token With More Permissions

In our previous steps, we created a basic OAuth URL without any contract interaction permissions. Now that we want to execute a transaction on on the HYCHAIN Blockchain, on behalf of our authorized user, they need to approve our app to do that. Let's update our OAuth flow URL to include the required permissions.

In this example, we have a Counter contract on HYCHAIN Testnet that simply increments a number it tracks when it's increment() function is used. This contract can be found here: 0x0188B6A7B90DF7ACaCC1eADF4abe31477938fC22

We're going to add the contractFunctionSelectors query parameter to our OAuth flow URL now. This query parameter allows us to request permissions to interact with specific contract addresses and their specific functions as the authorized user. In this case, we want to interact with the counter contract at address 0x0188B6A7B90DF7ACaCC1eADF4abe31477938fC22, and it's increment() function.

We'll set the value of contractFunctionSelectors to [{"address":"0x0188B6A7B90DF7ACaCC1eADF4abe31477938fC22","functionSelectors":["increment()"]}]

For our demo app, our new OAuth URL that now requests permissions for this contract interaction from our user becomes: https://hyplay.com/oauth/authorize/?appId=ce904287-c653-4231-87d5-3e87ab50c382&chain=HYCHAIN_TESTNET&responseType=token&redirectUri=https%3A%2F%2Fhyplay.com&contractFunctionSelectors=[{"address":"0x0188B6A7B90DF7ACaCC1eADF4abe31477938fC22","functionSelectors":["increment()"]}]

Once a user has completed our updated OAuth flow, the resulting session access token now has approved permissions for performing the increment transaction on their behalf as many times as we'd like.


Step 2: Perform A Transaction

Now we have a session access token from the previous step that has updated permissions. We're going to perform a transaction using that session access token from our updated OAuth flow URL to invoke the increment() function of our approved Counter contract on HYCHAIN Testnet at address 0x0188B6A7B90DF7ACaCC1eADF4abe31477938fC22.

To do this, we'll use the create transaction endpoint here: https://docs.hyplay.com/reference/createtransaction

The create transaction endpoint is highly flexible. It can perform basic transfers from the wallet associated with the access token provided, to complex transactions with smart contracts, and more. For calling our increment() function on our counter contract, we'll provide it with the following fields.

  • address: This is the address of our counter contract we want to perform the increment() transaction for.
  • func: This is the function we want our transaction to invoke, in this case increment().
  • chain: This is the chain the transaction will be executed on, this needs to be the same chain that our contract is deployed on, in this example, HYCHAIN_TESTNET
  • x-session-authorization: This header we'll set to the value of our session access token from our OAuth URL flow.

We'll submit the request and see the transaction executed successfully by our authorized user's wallet!


Next Steps

That brings us to the conclusion of our quickstart guide. For next steps we recommend you take a look at the following resources.