-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 530ec93
Showing
16 changed files
with
1,064 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: ci | ||
|
||
on: ["push", "pull_request", "workflow_dispatch"] | ||
|
||
env: | ||
VERSION: mainnet-v1.3.0 | ||
|
||
jobs: | ||
test_and_demo: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [19.x] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Cache Binaries and move deps | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.move | ||
~/bin | ||
**/node_modules | ||
key: ${{ runner.os }}-cache-${{ env.VERSION }} | ||
restore-keys: | | ||
${{ runner.os }}-cache- | ||
- run: echo "${HOME}/bin" >> $GITHUB_PATH | ||
- name: install sui bin | ||
run: | | ||
mkdir -p ~/bin | ||
wget https://github.com/MystenLabs/sui/releases/download/${{ env.VERSION }}/sui -O ~/bin/sui | ||
chmod +x ~/bin/sui | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
- name: Install Task | ||
uses: arduino/setup-task@v1 | ||
- run: task build | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- uses: pnpm/action-setup@v2.2.4 | ||
with: | ||
version: 8.6.2 | ||
- run: pnpm install | ||
- run: pnpm demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sui.log.* | ||
.env | ||
build | ||
output.bpl | ||
.coverage_* | ||
.trace | ||
boilerplate | ||
.task/ | ||
node_modules/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
printWidth: 120, | ||
semi: true, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Mynft | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 0 | ||
|
||
dependencies = [ | ||
{ name = "Sui" }, | ||
] | ||
|
||
[[move.package]] | ||
name = "MoveStdlib" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet-v1.3.0", subdir = "crates/sui-framework/packages/move-stdlib" } | ||
|
||
[[move.package]] | ||
name = "Sui" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet-v1.3.0", subdir = "crates/sui-framework/packages/sui-framework" } | ||
|
||
dependencies = [ | ||
{ name = "MoveStdlib" }, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "Suibox" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.3.0" } | ||
|
||
[addresses] | ||
suibox = "0x0" | ||
sui = "0x2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Suibox | ||
|
||
## Quick Start | ||
|
||
Install package: `npm install @suia/suibox` | ||
|
||
```typescript | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# https://taskfile.dev | ||
|
||
version: "3" | ||
|
||
tasks: | ||
build: | ||
cmds: | ||
- sui move build | ||
- echo "build done" | ||
sources: | ||
- sources/**/*.move | ||
- Move.toml | ||
test: | ||
cmds: | ||
- sui move test | ||
sources: | ||
- sources/**/*.move | ||
- Move.toml | ||
demo: | ||
cmds: | ||
- pnpm ts-node examples/suibox.ts | ||
sources: | ||
- src/**/*.ts | ||
- examples/**/*.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { SuiboxContract } from '../src/suibox'; | ||
import { devnetConnection, Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js'; | ||
|
||
async function main(): Promise<void> { | ||
console.log('Hello from Suibox'); | ||
|
||
// init connection and signer | ||
const connection = devnetConnection; | ||
const provider = new JsonRpcProvider(connection); | ||
const keypairseed = process.env.KEY_PAIR_SEED; | ||
const keypair = Ed25519Keypair.fromSecretKey(Uint8Array.from(Buffer.from(keypairseed!, 'hex'))); | ||
const signer = new RawSigner(keypair, provider); | ||
|
||
const addr = await signer.getAddress(); | ||
console.log('addr: ', addr); | ||
await provider.requestSuiFromFaucet(addr); | ||
|
||
// wait for the faucet to send the sui | ||
await new Promise((resolve) => setTimeout(resolve, 3000)); | ||
|
||
// publish a new suibox contract | ||
const suiboxContract = await SuiboxContract.publish(signer); | ||
// you can also specify an existing suibox contract with the function below | ||
// const suiboxContract = new Contract(packageId, signer); | ||
|
||
// list all suiboxes | ||
let suiboxes = await suiboxContract.listSuiboxes(); | ||
console.log('suiboxes: ', suiboxes); | ||
const suibox = await suiboxContract.createSuibox({ | ||
name: 'suibox name', | ||
description: 'suibox description', | ||
image_url: 'suibox image url', | ||
layout: '9-box grid', | ||
}); | ||
suiboxes = await suiboxContract.listSuiboxes(); | ||
console.log('suiboxes: ', suiboxes); | ||
|
||
// create a new suibox as a nft and add it to the suibox created above | ||
const nft = await suiboxContract.createSuibox({ | ||
name: 'nft', | ||
description: 'nft', | ||
image_url: 'nft', | ||
layout: 'nft', | ||
}); | ||
await new Promise((resolve) => setTimeout(resolve, 3000)); | ||
await suibox.add({ objectId: nft.objectId }, 0); | ||
const nftsAfterAddNFT = await suibox.listNFTs(); | ||
console.log('nftsAfterAddNFT: ', nftsAfterAddNFT); | ||
|
||
// extract the nft from the suibox | ||
await suibox.extract(`${await nft.getPackageId()}::suibox::Suibox`, 0); | ||
const nftsAfterExtractNFT = await suibox.listNFTs(); | ||
console.log('nftsAfterExtractNFT: ', nftsAfterExtractNFT); | ||
console.log('----------- suibox example end -----------'); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "suibox", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"demo": "ts-node examples/suibox.ts", | ||
"fix:prettier": "prettier --write src examples" | ||
}, | ||
"dependencies": { | ||
"@mysten/sui.js": "^0.36.0" | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^16.0.2", | ||
"@types/node": "^20.3.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.8.3", | ||
"prettier": "^2.8.8" | ||
} | ||
} |
Oops, something went wrong.