Skip to content

Commit

Permalink
feat: update transactions and marketplace with v2 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
lewinskimaciej committed Jan 9, 2024
1 parent d7cf276 commit 3405434
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 57 deletions.
8 changes: 4 additions & 4 deletions pages/service/assets/managing-profile-assets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If we registered an ERC20 contract for your game, you are able to manage the ERC
Initiating a token transfer would look something like this. In the example below, we are not considering more complicated features like sponsoring transactions just yet - the transaction will be paid for by you - the game developer.

```typescript
const transaction = await beam.assets.transferToken("your-sender-id", {
const transaction = await beam.assetsV2.transferTokenV2("your-sender-id", {
receiverEntityId: "your-receiver-id",
assetAddress: "your-contract-address",
amountToTransfer: "10", // 10 means 10 - we don't expect you to consider any other format like gwei
Expand All @@ -36,11 +36,11 @@ const transaction = await beam.assets.transferToken("your-sender-id", {
Asset transfers work in a similar fashion as ERC20 token transfers, but instead of calling the `transferToken`, you will need to call the `transferAsset` method and pass an `assetId` property for the asset you want to move around.

```typescript
const transaction = await beam.assets.transferAsset("your-sender-id", {
const transaction = await beam.assetsV2.transferAssetV2("your-sender-id", {
receiverEntityId: "your-receiver-id",
assetAddress: "your-contract-address",
assetId: "73",
amountToTransfer: "1", // amountToTransfer is related to 1155, defaults to 1 and doesn't have to be passed for ERC721 contracts.
amountToTransfer: 1, // amountToTransfer is related to 1155, defaults to 1 and doesn't have to be passed for ERC721 contracts.
});

// {
Expand All @@ -56,7 +56,7 @@ const transaction = await beam.assets.transferAsset("your-sender-id", {
Lastly - we offer you the possibility to transfer our native token: BEAM. Depending on the context of your game, you might want to be able to transfer our native token around between profiles.

```typescript
const transaction = await beam.assets.transferNativeToken("your-sender-id", {
const transaction = await beam.assetsV2.transferNativeTokenV2("your-sender-id", {
receiverEntityId: "your-receiver-id",
amountToTransfer: "10", // 10 means 10 - we don't expect you to consider any other format like gwei
});
Expand Down
16 changes: 12 additions & 4 deletions pages/service/assets/reading-profile-assets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ By running the following method, you will receive all ERC721 and ERC1155 type as
Note that at the moment of writing, we do not expose filtering options yet - but they are expected to drop soon in order for you to filter in different ways to get meaningful results.

```typescript
const profileAssets = await beam.assets.getProfileAssets("entity-id");
const profileAssets = await beam.assetsV2.getProfileAssetsForGamePostV2("entity-id", {
sortDirection: 'desc';
sortBy: 'acquiredAt';
contract: "0x..."; // if you want to get assets only from one collection, null/undefined otherwise
includeAttributes: true; // defaults to false
continuation: null; // pagination continuation token
limit: 20;
});

// {
// "data": [
Expand All @@ -42,7 +49,7 @@ const profileAssets = await beam.assets.getProfileAssets("entity-id");
In order to get all ERC20 token balances for a profile, you can run the `getProfileCurrencies` method. The response model for this enpdoint is not paginated, as we don't expect a single game to have more than a few on-chain currencies to support their in-game economy.

```typescript
const profileTokens = await beam.assets.getProfileCurrencies("entity-id");
const profileTokens = await beam.assetsV2.getProfileCurrenciesV2("entity-id");

// {
// "data": [
Expand All @@ -52,6 +59,7 @@ const profileTokens = await beam.assets.getProfileCurrencies("entity-id");
// "symbol": "string",
// "decimals": 0,
// "logoUri": "string",
// "chainId": 13337;
// "balance": "string"
// }
// ]
Expand All @@ -63,15 +71,15 @@ const profileTokens = await beam.assets.getProfileCurrencies("entity-id");
If you are interested in validating the native currency of a profile, for example to validate whenever the profile has enough BEAM to run a self-paid transaction, you could fetch the native token balance directly by doing the following:

```typescript
const profileTokens = await beam.assets.getProfileNativeCurrency("entity-id");
const profileTokens = await beam.assetsV2.getProfileNativeCurrencyV2("entity-id");

// {
// "nativeTokenBalance": {
// "name": "string",
// "symbol": "string",
// "decimals": 0,
// "logoUri": "string",
// "chainId": 0,
// "chainId": 13337,
// "balance": "string"
// }
// }
Expand Down
4 changes: 1 addition & 3 deletions pages/service/marketplace/buying-assets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
If a user shows interest in a listing for sale by another profile, it's possible to buy the listed asset with a profile by simply calling the `buyListedAsset` method. Note that in order to actually buy the asset, the buyer-profile needs to be funded with enough BEAM based on the listing price set by the seller profile.

```typescript
const response = await beam.marketplace.buyListedAsset('buyer-profile-id', {
orderId: '' // data[0].orderId from the getListedAssetsForProfile method,
const response = await beam.marketplaceV2.buyListedAssetV2('buyer-profile-id', 'order-id-to-fulfill' {
quantity: 1 // the amount of NFTs to buy, only relevant for ERC-1155 based tokens, defaults to 1
});

// {
// "status": "success",
// "type": "custodial",
// "transactionHash": '0x71f3f259568e9875c41a4350a3912a3a7650d9321ccd1d57641241128b4e504f',
// "explorerUrl": "https://subnets.avax.network/beam/0x71f3f259568e9875c41a4350a3912a3a7650d9321ccd1d57641241128b4e504f"
// }
Expand Down
4 changes: 2 additions & 2 deletions pages/service/marketplace/currencies.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ title: Currencies
At the moment of writing the Beam marketplace supports a couple of pre-configured tokens for all marketplace interactions. In order to get the currencies supported for a specific chain, we've added a method. Here's how you can use it:

```typescript
const currencies = await beam.marketplace.getCurrencies(4337); // the chain ID you want to get the supported currencies for
const currencies = await beam.marketplaceV2.getChainCurrenciesV2(4337); // the chain ID you want to get the supported currencies for

// {
// data: [
// {
// currency: 'USDC'
// decimals: 18,
// tokenAddress: '0x007Fdc86FD12924C9116025C7F594843087397E3'
// address: '0x007Fdc86FD12924C9116025C7F594843087397E3'
// }
// ]
// }
Expand Down
5 changes: 3 additions & 2 deletions pages/service/marketplace/listing-assets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
In order to list an asset on behalf of a profile you need to give us some information about the listing.

```typescript
const transaction = await beam.marketplace.listAsset('profile-seller-id', {
marketplaceId": "64df956525e46b4d63ae37e9,
const transaction = await beam.marketplaceV2.listAssetV2('profile-seller-id', {
assetAddress: '0x...',
assetId: '1',
quantity: 1 // You can list multiple 1155 assets from the same token, defaults to 1
price: '1000', // Listing price in BEAM token
sellType: 'FixedPrice' // AscendingAuction, DescendingAuction or FixedPrice
Expand Down
51 changes: 21 additions & 30 deletions pages/service/marketplace/offers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ Based on the available currencies, you can create an offer for items which are l

```typescript

const transaction = await beam.marketplace.createAssetOffer('profile-offerer-id', {
marketplaceId: "64df956525e46b4d63ae37e9",
const transaction = await beam.marketplaceV2.createAssetOfferV2('profile-offerer-id', {
assetAddress: '0x...',
assetId: '1',
quantity: 1 // You can make an offer for multiple 1155 assets from the same token
price: '1000', // Listing price
currency: 'USDC' // Defaults to BEAM. Find all available options through the getCurrencies() method;
currency: 'USDC' // Defaults to WBEAM. Find all available options through the getCurrencies() method; You cannot use native(BEAM) to make offers.
});

// {
Expand All @@ -34,9 +35,9 @@ const transaction = await beam.marketplace.createAssetOffer('profile-offerer-id'
If you want to cancel the offer, you can use the following snippet.

```typescript
const transaction = await beam.marketplace.cancelAssetOffer(
"profile-offerer-id",
"651bfbb9b47baf2d2a092c04"
const transaction = await beam.marketplaceV2.cancelAssetOfferV2("profile-offerer-id", {
offerId: 'offer-id-you-created'
}
);

// {
Expand All @@ -51,44 +52,34 @@ const transaction = await beam.marketplace.cancelAssetOffer(
If you want to list all the offers made to an NFT, you are able to do so with the following snippets

```typescript
const transaction = await beam.marketplace.getAssetOffers(
"asset-marketplace-id"
// Get all offers for an asset
const transaction = await beam.marketplaceV2.getAssetOffersV2(
"asset-address",
"asset-id"
);
const transaction = await beam.marketplace.getProfileOffers(

// Get all offers that player created
const transaction = await beam.marketplaceV2.getPlayerOffersV2(
"profile-offerer-id"
);
const transaction = await beam.marketplace.getProfileAssetOffers(

//Get all asset offers that player created
const transaction = await beam.marketplaceV2.getPlayerAssetOffersV2(
"profile-offerer-id",
"asset-marketplace-id"
"asset-address",
"asset-id"
);

// {
// "data": [
// {
// "orderId": "651578cd46df7c4288b267cc",
// "kind": "SignedSingleOrder",
// "currency": "Wmc",
// "quantity": 1,
// "quantityFilled": 0,
// "quantityAvailable": 1,
// "offerer": "0x106b7272d041727878Aff54514e81DEEF546C64d",
// "tokenAmount": "0x01b4fbd92b5f8000",
// "tokenAmountNumber": 0.123,
// "startTime": "2023-07-08T12:35:00.000Z",
// "endTime": "2023-08-08T12:35:00.000Z"
// }
// ]
// }
```

### Accepting an offer

If an item is listed by a profile that is managed by you through the SDK, it's possible to accept an offer through the SDK as well. Keep in mind that not every listing is managed through the SDK: accepting offers to an asset on Sphere only can be done if you manage the profile that listed it in the first place.

```typescript
const transaction = await beam.marketplace.acceptAssetOffer(
const transaction = await beam.marketplaceV2.acceptAssetOfferV2(
"profile-seller-id",
{
offerId: 'offer-id-you-accept'
quantity: 1, // You can accept multiple 1155 assets from the same token
}
);
Expand Down
11 changes: 7 additions & 4 deletions pages/service/transactions/custom-charges.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ You could charge your users an X amount of Gold by simply creating a policy, and
Eventually, you as a game developer will be responsible for funding the BEAM for all the transactions that are ran through our service, so if you take away in-game Gold, you have to consider if it is economically viable to make this transaction. Let's assume a single transaction on Beam costs < 0.001 BEAM, and a Gold costs the user $ 0.05 to obtain - this means that the transaction through the policy is now not only economically viable, it also allows you to to sponsor quite some transactions for the user as the single Gold paid for the transaction in tenfold.

```typescript
const transaction = await beam.assets.transferAsset("your-sender-id", {
receiverEntityId: "your-receiver-id",
assetAddress: "your-contract-address",
assetId: "73",
const transaction = await beam.assetsV2.transferAssetV2("your-sender-id", {
assets: [
receiverEntityId: "your-receiver-id",
assetAddress: "your-contract-address",
assetId: "73",
amountToTransfer: 1,
]
// ...
sponsor: false, // 👈 This handles the transaction to be self paid
policyId: "cl..", // 👈 This triggers the custom policy to be used
Expand Down
11 changes: 7 additions & 4 deletions pages/service/transactions/profile-paid-transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ Take into account that if the Profile doesn't actually have the necessary BEAM f
Below you will find an example how this would look like when managing assets in a Profile

```typescript
const transaction = await beam.assets.transferAsset("your-sender-id", {
receiverEntityId: "your-receiver-id",
assetAddress: "your-contract-address",
assetId: "73",
const transaction = await beam.assetsV2.transferAssetV2("your-sender-id", {
assets: [
receiverEntityId: "your-receiver-id",
assetAddress: "your-contract-address",
assetId: "73",
amountToTransfer: 1,
]
// ...
sponsor: false, // 👈 This handles the transaction to be self paid
});
Expand Down
11 changes: 7 additions & 4 deletions pages/service/transactions/sponsored-transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ We think this default is sensible, as it's you as the game developer are in cont
To paint a clearer picture on how this looks like, below you'll find a transaction which is sponsored

```typescript
const transaction = await beam.assets.transferAsset("your-sender-id", {
receiverEntityId: "your-receiver-id",
assetAddress: "your-contract-address",
assetId: "73",
const transaction = await beam.assetsV2.transferAssetV2("your-sender-id", {
assets: [
receiverEntityId: "your-receiver-id",
assetAddress: "your-contract-address",
assetId: "73",
amountToTransfer: 1,
]
// ...
sponsor: true, // 👈 true is also the default.
});
Expand Down

0 comments on commit 3405434

Please sign in to comment.