Skip to content
/ sui Public
forked from mofalabs/sui

A cross-platform Sui SDK for Mobile, Web and Desktop

License

Notifications You must be signed in to change notification settings

gtmickey/sui

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sui Dart SDK

Pub

Installation

dependencies:
  sui: ^0.1.7

Demo

https://sui-dart.pages.dev/

Usage

Connecting to Sui Network

/// connect to devnet
final devnetClient = SuiClient(SuiUrls.devnet);

/// connect to testnet
final testnetClient = SuiClient(SuiUrls.testnet);

/// connect to mainnet
final mainnetClient = SuiClient(SuiUrls.mainnet);

Getting coins from the faucet

Faucet V0

final faucet = FaucetClient(SuiUrls.faucetDev);
await faucet.requestSuiFromFaucetV0('0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2');

Faucet V1

final faucet = FaucetClient(SuiUrls.faucetDev);
await faucet.requestSuiFromFaucetV1('0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2');

Sui Account

Create account with private key

/// Ed25519 account
final ed25519 = SuiAccount.ed25519Account();
final ed25519Import = SuiAccount.fromPrivateKey(ed25519.privateKeyHex(), SignatureScheme.Ed25519);

/// Secp256k1 account
final secp256k1 = SuiAccount.secp256k1Account();
final sepc256k1Import = SuiAccount.fromPrivateKey(secp256k1.privateKeyHex(), SignatureScheme.Secp256k1);

/// Secp256r1 account
final secp256r1 = SuiAccount.secp256r1Account();
final sepc256r1Import = SuiAccount.fromPrivateKey(secp256r1.privateKeyHex(), SignatureScheme.Secp256r1);

Create account with mnemonic

/// create mnemonics
final mnemonics = SuiAccount.generateMnemonic();

/// Ed25519 account
final ed25519 = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.Ed25519);

/// Secp256k1 account
final secp256k1 = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.Secp256k1);

/// Secp256r1 account
final secp256r1 = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.Secp256r1);

Writing APIs

Transfer Object

final account = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.Ed25519);
final client = SuiClient(SuiUrls.devnet);

final tx = TransactionBlock();
tx.transferObjects(
    [tx.objectId('0x2619f581cb1864d07c89453a69611202669fdc4784fb59b9cb4278ec60756011')], 
    tx.pureAddress(account.getAddress())
);

final result = await client.signAndExecuteTransactionBlock(account, tx);
print(result.digest);

Split and Transfer Coins

final account = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.Ed25519);
final client = SuiClient(SuiUrls.devnet);

final tx = TransactionBlock();
final coin = tx.splitCoins(tx.gas, [tx.pureInt(1000)]);
tx.transferObjects(
    [coin],
    tx.pureAddress(account.getAddress())
);

final result = await client.signAndExecuteTransactionBlock(account, tx);
print(result.digest);

Merge Coins

final account = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.Ed25519);
final client = SuiClient(SuiUrls.devnet);

final tx = TransactionBlock();
tx.mergeCoins(tx.objectId('0x922ec73939b3288f6da39ebefb0cb88c6c54817441254d448bd2491ac4dd0cbd'), 
    [tx.objectId('0x8dafc96dec7f8d635e052a6da9a4153e37bc4d59ed44c45006e4e9d17d07f80d')]
);

final result = await client.signAndExecuteTransactionBlock(account, tx);
print(result.digest);

Move Call

final account = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.Ed25519);
final client = SuiClient(SuiUrls.devnet);

const packageObjectId = '0x...';
final tx = TransactionBlock();
tx.moveCall('$packageObjectId::nft::mint', arguments: [tx.pureString('Example NFT')]);

final result = await client.signAndExecuteTransactionBlock(account, tx);
print(result.digest);

Publish Modules

final account = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.Ed25519);
final client = SuiClient(SuiUrls.devnet);

const moduels = <String>[];
const dependencies = <String>[];
final tx = TransactionBlock();
final upgradeCap = tx.publish(moduels, dependencies);
tx.transferObjects([upgradeCap], account.getAddress());

final result = await client.signAndExecuteTransactionBlock(account, tx);
print(result.digest);

Reading APIs

Get Owned Objects

final client = SuiClient(SuiUrls.devnet);

final objects = await client.getOwnedObjects('0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2');

Get Objects

final client = SuiClient(SuiUrls.devnet);

final obj = await client.getObject('0x0d49dbda185cd0941b71315edb594276731f21b2232d8713f319b02c462a2da7',
    options: SuiObjectDataOptions(showContent: true)
);

final objs = await client.multiGetObjects([
    '0x0d49dbda185cd0941b71315edb594276731f21b2232d8713f319b02c462a2da7',
    '0x922ec73939b3288f6da39ebefb0cb88c6c54817441254d448bd2491ac4dd0cbd'
], options: SuiObjectDataOptions(showType: true));

Get Transaction

final client = SuiClient(SuiUrls.devnet);

final txn = await client.getTransactionBlock('6oH779AUs2WpwW77xCVGbYqK1FYVamRqHjV6A5wCV8Qj',
    options: SuiTransactionBlockResponseOptions(showEffects: true)
);

final txns = await client.multiGetTransactionBlocks([
    '9znMGToLRRa8yZvjCUfj1FJmq4gpb8QwpibFAUffuto1',
    '4CEFMajEtM62MthwY1xR3Bcddoh2h5wc7jeKEy7WWsbv'
], options: SuiTransactionBlockResponseOptions(showInput: true, showEffects: true));

Get Checkpoints

final client = SuiClient(SuiUrls.devnet);

final checkpoint = await client.getCheckpoint('338000');

final checkpoints = await client.getCheckpoints(descendingOrder: true);

Get Coins

final client = SuiClient(SuiUrls.devnet);

final coins = await client.getCoins(
    '0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2',
    coinType: '0x2::sui::SUI');

final allCoins = await client.getAllCoins('0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2');

final suiBalance = await client.getBalance('0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2');

Events APIs

Querying events

final client = SuiClient(SuiUrls.devnet);

final events = await client.queryEvents(
    {"Sender": "0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2"}, 
    limit: 2
);

/// Or with EventFilter

final events = await client.queryEventsByFilter(
    EventFilter(sender: "0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2"), 
    limit: 2
);

WebsocketClient subscribeEvent

final client = WebsocketClient(SuiUrls.webSocketDevnet);

final subscription = client.subscribeEvent({"Sender": "0xa2d8bb82df40770ac5bc8628d8070b041a13386fef17db27b32f3b0f316ae5a2"})
.listen((event) {
    debugPrint(event);
}, onError: (e) {
    debugPrint(e.toString());
});

About

A cross-platform Sui SDK for Mobile, Web and Desktop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 89.6%
  • C++ 4.4%
  • CMake 3.5%
  • Move 1.0%
  • Ruby 0.5%
  • Swift 0.4%
  • Other 0.6%