Game Soft Currency Interaction

Soft Currencies

In the context of game development, a "soft currency" refers to a type of in-game currency that players can earn through gameplay, quests, or challenges. Unlike "hard currency," which is typically purchased with real-world money, soft currency is more easily acquired but often has limited use compared to hard currency. It is generally used for buying common items, upgrades, or for entry into specific game scenarios. Soft currency aims to engage players by rewarding them for time spent in-game and encouraging continued play.

Example:
In a mobile game, players might earn "coins" through completing levels or missions. These coins can be used to buy basic power-ups, but more premium items require "gems," which are a form of hard currency.

Create a Charge

Below, we will demonstrate how to utilize USDC on the Polygon Chain:

USDC Token Address on Polygon: 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174

To create a charge for 10 USD:

import { sphereoneSdk } from "./your-implementation-file";
import { SupportedChains } from "websdk";

// ...
const [chargeId, setChargeId] = useState("");
const [paymentLink, setPaymentLink] = useState("");

const {chargeId} = await WebSDK.createCharge({
  chargeData: {
    symbol: "USDC",
    chain: SupportedChains.POLYGON,
    successUrl: "https://sphereone.xyz/",
    cancelUrl: "https://sphereone.xyz/consumer",
    tokenAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
    items: [
      {
        name: "USDC",
        image:"https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/US10dollarbill-Series_2004A.jpg/2880px-US10dollarbill-Series_2004A.jpg",
        amount: 10,
        quantity: 1,
      }
    ]
  },
})
using SphereOne;

// ...

var chargeItems = new List<ChargeItem>
{
  new ChargeItem
  {
      name = "Your Item",
      image = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/US10dollarbill-Series_2004A.jpg/2880px-US10dollarbill-Series_2004A.jpg",
      amount = 10.0,
      quantity = 1,
   }
};

var chargeRequest = new ChargeReqBody
{
    chain = SupportedChains.SOLANA,
    symbol = "POLYGON",
    amount = 10.0,
    tokenAddress = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
    items = chargeItems,
    successUrl = "https://your-website.com/success",
    cancelUrl = "https://your-website.com/cancel",
};

var isTest = false;
var charge = await SphereOneManager.Instance.CreateCharge(chargeRequest, isTest);

if (charge == null) {
  // Handle the error
  return;
}

Debug.Log(charge.ToString());

From here, we can call payCharge by passing in the chargeId that we receive from createCharge to begin our process.

// importing the initialized WebSDK
import { sphereoneSdk } from "your-implementation-file";
import { SupportedChains } from "websdk";

// ...
// these are from previous section from: https://docs.sphereone.xyz/docs/create-charge#web-sdk
const [chargeId, setChargeId] = useState("");
const [paymentLink, setPaymentLink] = useState("");

// ... createCharge example ...

const pay = async () => {
  try {
    await sphereoneSdk.payCharge(chargeId);
  } catch (e: any) {
    console.error(e);
  }
};