Skip to content

MiniMiners (https://miniminersgame.com/) smartcontracts on Sui blockchain written in Sui Move programming language

Notifications You must be signed in to change notification settings

Seascape-Foundation/miner-sui-smartcontracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MiniMiners play-to-earn game on Sui Blockchain The Smartcontracts of the MiniMiners, the p2e earn on Sui Blockchain.

πŸ’‘ Deployed recoursed are on another page: Addresses.md


Installation

It requires sui to be installed on your machine.

If you didn't install sui, install it using:

cargo install --locked --git https://github.com/MystenLabs/sui.git --branch devnet sui

Upon installation complete, type on terminal:

sui -V

If you see the sui version printed, then go to the next step. Sui Version on terminal

Link to the Sui

The MiniMiners smartcontracts utilize sui and std library packages. Those packages are installed with the sui client.

In this repository, open the Move.toml in the root folder. In the [dependencies] section set the correct path to Sui packages:

Sui = { local = "../sui/crates/sui-framework" }

The sui code will be installed to the <user folder>/sui.

For example on Windows: C:\Users\<user name>\sui.

That means, sui packages will be in C:\Users\<user name>\sui\crates\sui-framework.

Error handling

If the sui publish command gives a client-server version mismatch error, then you should install the exact version:

cargo install --git `
https://github.com/MystenLabs/sui.git `
--tag devnet-0.27.1 sui --force

Build

sui move build

Compile the smartcontract source code to the binary.

Compile sui code

⚠️ Warning If you didn't see the output as on the screenshot above, then the code is malformed. Contact me: [email protected]


Test

sui move test

Run the tests Run tests

⚠️ Warning If you didn't see the output as on the screenshot above, then the code is malformed. Contact me: [email protected]


Deploy

πŸ’‘ You may need SUI token to publish or call functions. To obtain a gas for devnet check out https://docs.sui.io/build/faucet

Deploy the smartcontracts on the blockchain.

sui client publish --gas-budget 3000 --dev --doc --abi 

If it shows an error Multiple source verification errors found:

Then add to the command another argument after --abi:

--skip-dependency-verification

Upon successful publishing, the console output will show Transaction Hash. Then we need to update the game backend to work with the newly published data.

Also we need to set the verifier.

Verifier

SUI blockchain uses different algorithm than Ethereum. However we can derive the Sui keys from Ethereum keys. After all, Sui smartcontracts provide ecrecover identical as in the Ethereum Virtual Machines.

πŸ’‘ Tip The most easiest way to get Ethereum address from SUI private key, its better to load the private key into the Ethereum wallet.

⚠️ Only smartcontract owner can set the Verifier

sui client call `
--function set_verifier `
--module game `
--package 0x8703ea390380923722794a76ab14973a24ac90a8 `
--gas-budget 1000 `
--args `
  0xa824a2b14121d491fc195dbc157b6a97a74a3baa `
  0xeb3b05ca37ae926fc8d0a2115ca0903800a502f8

Mint by [permission]

The mine_nft could be minted by the permission. But the permission is granted from the server. Therefore, we set the mine_nft's verifier:

⚠️ Only smartcontract owner can set the verifier

sui client call `
--function set_verifier `
--module mine_nft `
--package 0x8703ea390380923722794a76ab14973a24ac90a8 `
--gas-budget 1000 `
--args `
  0xa824a2b14121d491fc195dbc157b6a97a74a3baa `
  0xeb3b05ca37ae926fc8d0a2115ca0903800a502f8

The first argument is the Info object's resource id. The second argument is the Game object's address's Ethereum wallet address.

Update the game backend

Go to the explorer, to the page of the transaction. The explorer will show the list of the created objects. Go to each object to identify the Object Type.

1. Update the config.json on CDN. For now for demo we keep the cdn on the backend as hardcoded config. Its hardcoded in the src/app.js. Find the sui_dev_config variable in the source file. And set the write parameters.

2. Update the sync bot In the repository of the sync bot, update the config/config.json

Done! Now you can call the following commands to test it.


Mint new MineNFTs

Can be called by the owner of NftFactory object. By default its the publisher of the package.

sui client call `
 --function mint `
 --module mine_nft `
 --package 0x1f9f5ea685a87c1bc72ccf16092dc659c1b62f56 ` --gas-budget 1000 `
 --args `
  		0x68cd72eb93b5894af90edc84591cf43c0c4d4c1d `
  0x8714a9b7819e42cedbde695f9a0242b7d79ff9c2 `
  2 `
  3

The first argument is the resource(aka object) id of the Factory. The second argument is the owner of the nft. The last two arguments are generation and quality.

Mint an MineNFT with generation = 2 and quality = 3. The minted nft is transferred to 0x8714a9b7819e42cedbde695f9a0242b7d79ff9c2.


Transfer Nft
sui client transfer --to 0x8ec7ccb4e3925fef987d8a2ff11f78051e0ffc46 `
--object-id 0xbd1479055f0f091123d245b7ad4ebb95ef80b9cb `
--gas-budget 3000

Transfer SUI to Game smartcontract

In order to test selling gold packs in exchange for crypto token, we need to have some token in the smartcontract

sui client call `
--function transfer_token `
--module game `
--package 0x1f9f5ea685a87c1bc72ccf16092dc659c1b62f56 `
--gas-budget 1000 `
--type-args 0x2::sui::SUI `
--args `
  0x1798b2bbe3db25d746cffa8a343f0840c85a99d8 `
  0x5e65827ec1c3f391d543c53d702f4377e8f30a18

Type argument of the coin is 0x2::sui::SUI. The first argument is the shared game object id. The second argument is the SUI object id.


Buying Gold

Lets test selling 1500000 of gold for 0.1 SUI.

gold_id = 101

sui client call `
--function sell_gold `
--module game `
--package 0x1f9f5ea685a87c1bc72ccf16092dc659c1b62f56 `
--gas-budget 1000 `
--type-args 0x2::sui::SUI `
--args `
  0x1798b2bbe3db25d746cffa8a343f0840c85a99d8 `
  0x4f44f0122e3577acdcacae1f1e44a1ef8a036a29 `
  9991804 `
  101

The first argument is the address of the shared game object. The second argument is the address of the Coin of --type-args type. The price of the sold gold will be added to the value of the passed coin object. The third argument is the amount of tokens in MIST

1 MIST = 10e-9 SUI One SUI is equal to 1 billion MIST

The last argument is the pack id. In our case its the gold pack.


Buy Pack

Let's test purchasing Diamonds for 0.002 SUI.

0.002 SUI = 2_000_000 MIST (2 million)

60 Diamonds pack id = 1

sui client call `
--function buy_pack `
--module game `
--package 0x1f9f5ea685a87c1bc72ccf16092dc659c1b62f56 `
--gas-budget 1000 `
--type-args 0x2::sui::SUI `
--args `
  0x1798b2bbe3db25d746cffa8a343f0840c85a99d8 `
  0x4f44f0122e3577acdcacae1f1e44a1ef8a036a29 ` 
  1

Do not pass the first SUI object as the function argument. That object is used by that wallet to pay for transaction fee.

The first argument is the shared game object. The second argument is the object id of --type-args type. The amount should be equal to the 2 million MIST. The third and last argument is the pack id.

Getting the object id of 0.002 SUI

We need to list the all objects that user has

sui client objects

If we don't find the amount that's worth 0.002 SUI we split the first object with 0.02 gas.

sui client split-coin `
--gas-budget 1000 `
--amounts 2000000 `
--coin-id 0xe8854a583350f445f552fe7354d9ea0cdc26b459

Then use the created object for buying pack.


Import NFT

sui client call `
  --function import_nft `
  --module game `
  --package 0x8bfc690e84558814aaab3f2f6755e18f0f59217d `
  --gas-budget 3000 `
  --type-args 0x8bfc690e84558814aaab3f2f6755e18f0f59217d::mine_nft::Mine `
  --args `
    0xbfd3f36b2ea108333cde4b2558c64d95dd6172dd `
    0x9d233fe1481b001c34a2f13893b87046cf1d0570 `
    1678367370 `
    0x0c4e96924cda5b54954e96a7fa1c44b5a95a42659e0ebcb40e5ded78bb0e67a46c99fbb032040234b372e193ec6c3a50300453b8e377e357562285093b69afa100

The first argument is the shared game object. The second argument is the coin object id. The tokens from smartcontracts will be added to the second argument.

0xbfd3f36b2ea108333cde4b2558c64d95dd6172dd: is the shared game object. 0x9d233fe1481b001c34a2f13893b87046cf1d0570 argument is the nft id. 1678367370 is the Unix timestamp returned by the server. The last parameter is the signature returned by the server.


Sui tutorials

The list of references used in the writing of these smartcontracts:

About

MiniMiners (https://miniminersgame.com/) smartcontracts on Sui blockchain written in Sui Move programming language

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages