Skip to content
API
Managing your game
Managing contracts

Managing contracts

If you want to run transactions for profiles that interact with specific contracts, the contract address will need to be registered for your game.

We provide a method for you to add any contract to your game, as long as you can provide us with the ABI and contract address. As adding a contract address to your game is probably a one time action that you won't repeat (a lot) over time, we can also recommend simply interacting with the hosted Swagger UI (opens in a new tab) to simply add the necessary contracts to your game.


Companion app

If you're using the Beam Companion app, it might be good to know that as soon as you add a contract to your game, all connected users to profiles of your game are able to see said contract in the Beam Companion app.


Adding a contract

Adding a contract is as simple as calling the addContractToGame method.

import { Beam } from "@onbeam/node";
 
const beam = new Beam("x-api-key");
 
const contract = beam.game.addContractToGame({
  address: "string", // the deployed contract address
  type: "ERC20", // ERC721, ERC1155
  chainId: 13337, // 13337 for Beam testnet
  name: "string", // The name of the asset contract, for example: 'Card Packs'
 
  // the JSON abi for the contract, we recommend you grabbing it from the explorer if you have a deployed & verified contract
  abi: [
    {
      name: "string",
      type: "string",
      anonymous: true,
      payable: true,
      constant: true,
      stateMutability: "string",
      gas: "string",
      inputs: [
        {
          name: "string",
          type: "string",
          indexed: true,
          internalType: "string",
          components: ["string"],
        },
      ],
      outputs: ["string"],
    },
  ],
});
 
// {
//  "type": "ERC20",
//  "id": "string",
//  "createdAt": "string",
//  "updatedAt": "string",
//  "externalId": "string",
//  "address": "string",
//  "name": "string",
//  "chainId": 0,
//  "gameId": "string"
//}

Deleting a contract

Removing a contract from your game is just as simple, simply use the removeContractFromGame method to remove it.

import { Beam } from "@onbeam/node";
 
const beam = new Beam("x-api-key");
 
const contract = beam.game.removeContractFromGame({
  address: "string", // the deployed contract address
  chainId: 13337, // 13337 for Beam testnet
});
 
// {
//  "success": true
//}