gamechainsdk
Version:
A SDK for interacting with blockchain game assets
156 lines (108 loc) âĸ 4.62 kB
Markdown



**GameChainSDK** is your gateway to seamless integration with blockchain-based game assets. Build, manage, and interact with game assets effortlessly on Ethereum-compatible networks like Sepolia and ANCIENT8.
- đ **Blockchain Integration**: Interact with blockchain game assets using smart contracts.
- đ **Easy-to-Use API**: Simple functions for registering, transferring, and updating assets.
- đ **Multi-Network Support**: Works on Sepolia, ANCIENT8, and other EVM-compatible networks.
- đĻ **Lightweight and Efficient**: Designed for performance and developer productivity.
Install via npm:
```bash
npm install gamechainsdk
```
```javascript
import GameChainSDK from 'gamechainsdk';
const providerUrl = 'https://rpcv2-testnet.ancient8.gg/';
const contractAddress = '0x8628d91E8311B4856ae7d3E317a0E8fFf48E0f98'; // ANCIENT8 network
const sdk = new GameChainSDK(providerUrl, contractAddress);
```
```javascript
const registerAsset = async () => {
const account = '0xYourAccountAddress'; // Replace with your wallet address
const name = 'Sword of Power';
const metadata = 'A mythical sword of great power.';
try {
const result = await sdk.contract.methods.registerAsset(name, metadata).send({
from: account,
gas: 2000000,
});
console.log('Asset registered successfully:', result);
} catch (error) {
console.error('Error registering asset:', error.message);
}
};
```
```javascript
const fetchOwnerAssets = async () => {
const account = '0xYourAccountAddress'; // Replace with your wallet address
try {
const assets = await sdk.getOwnerAssets(account);
console.log('Owned assets:', assets);
} catch (error) {
console.error('Error fetching assets:', error.message);
}
};
```
```javascript
const updateAssetMetadata = async () => {
const account = '0xYourAccountAddress';
const assetId = 1; // Replace with the asset ID
const newMetadata = 'Updated description of the sword.';
try {
const result = await sdk.contract.methods.updateAssetMetadata(assetId, newMetadata).send({
from: account,
gas: 2000000,
});
console.log('Metadata updated successfully:', result);
} catch (error) {
console.error('Error updating metadata:', error.message);
}
};
```
```javascript
const transferAsset = async () => {
const fromAccount = '0xYourAccountAddress';
const toAccount = '0xRecipientAddress'; // Replace with the recipient's address
const assetId = 1; // Replace with the asset ID
try {
const result = await sdk.contract.methods.transferAsset(assetId, toAccount).send({
from: fromAccount,
gas: 2000000,
});
console.log('Asset transferred successfully:', result);
} catch (error) {
console.error('Error transferring asset:', error.message);
}
};
```
- đ ī¸ **Sepolia Testnet**: `0x1d6f8DAAd9a1B9c266768EC1AD0903Ab6E1e89C5`
- đŽ **ANCIENT8 Network**: `0x8628d91E8311B4856ae7d3E317a0E8fFf48E0f98`
Make sure your provider URL matches the network of the contract.
Optimize gas usage with estimation:
```javascript
const gas = await sdk.contract.methods.registerAsset(name, metadata).estimateGas({ from: account });
console.log('Estimated gas:', gas);
```
This project is licensed under the [MIT License](LICENSE).
Contributions are always welcome! Please fork this repository and submit a pull request for any changes.
If you encounter any issues, please open an issue on [GitHub](https://github.com/sambitsargam/gamechainsdk) or contact the maintainers.
Thanks to the open-source community and developers who contributed to the creation of GameChainSDK.
GameChainSDK is developed and maintained by **Sambit Sargam Ekalabya**.