Skip to content

Latest commit

 

History

History
188 lines (153 loc) · 4.95 KB

README.md

File metadata and controls

188 lines (153 loc) · 4.95 KB

sui4j CI License Coverage Branches

Sui4j

Sui4j is a robust, reactive, type safe Java library for working with Smart Contracts on the @MystenLabs/sui network.

This allows you to work with the @MystenLabs/sui blockchain, without the additional overhead of having to write your own integration code for the platform in JVM ecosystem.

WARNING: Note that we are still iterating on the RPC and SDK API before TestNet, therefore please expect frequent breaking changes in the short-term. We expect the API to stabilize after the upcoming TestNet launch.

Using

The latest 0.4.1 version tested with sui devnet-0.24.0 version.

Maven

<!-- https://mvnrepository.com/artifact/me.grapebaba/sui4j -->
<dependency>
<groupId>me.grapebaba</groupId>
<artifactId>sui4j</artifactId>
<version>0.4.1</version>
</dependency>

Gradle

// https://mvnrepository.com/artifact/me.grapebaba/sui4j
implementation 'me.grapebaba:sui4j:0.4.1'

Building Locally

To get started you need to install JDK8+, then run the following command:

$ ./gradlew build

Javadoc

For the latest javadocs for the main branch, run ./gradlew javadoc and open the document under the build/docs/javadoc/index.html in your browser.

Testing

To run unit tests

./gradlew test

To run E2E tests against local network

You can start sui local network refer to sui-local-network doc.

Start local network

git clone [email protected]:MystenLabs/sui.git
cd sui
cargo build --release
cd sui/target/release
./sui genesis
./sui start

To run Integration tests

./gradlew integrationTest

Supported APIs (sui SDK 0.25.0)

  • sui_batchTransaction
  • sui_devInspectTransaction
  • sui_dryRunTransaction
  • sui_executeTransaction
  • sui_executeTransactionSerializedSig(same with sui_executeTransaction)
  • sui_getAllBalances
  • sui_getAllCoins
  • sui_getBalance
  • sui_getCheckpointContents
  • sui_getCheckpointContentsByDigest
  • sui_getCheckpointSummary
  • sui_getCheckpointSummaryByDigest
  • sui_getCoinMetadata
  • sui_getCoins
  • sui_getCommitteeInfo
  • sui_getDelegatedStakes
  • sui_getDynamicFieldObject
  • sui_getDynamicFields
  • sui_getEvents
  • sui_getLatestCheckpointSequenceNumber
  • sui_getMoveFunctionArgTypes
  • sui_getNormalizedMoveFunction
  • sui_getNormalizedMoveModule
  • sui_getNormalizedMoveModulesByPackage
  • sui_getNormalizedMoveStruct
  • sui_getObject
  • sui_getObjectsOwnedByAddress
  • sui_getObjectsOwnedByObject
  • sui_getRawObject
  • sui_getReferenceGasPrice
  • sui_getSuiSystemState
  • sui_getTotalSupply
  • sui_getTotalTransactionNumber
  • sui_getTransaction
  • sui_getTransactionAuthSigners
  • sui_getTransactions
  • sui_getTransactionsInRange
  • sui_getValidators
  • sui_mergeCoins
  • sui_moveCall
  • sui_pay
  • sui_payAllSui
  • sui_paySui
  • sui_publish
  • sui_requestAddDelegation
  • sui_requestSwitchDelegation
  • sui_requestWithdrawDelegation
  • sui_splitCoin
  • sui_splitCoinEqual
  • sui_subscribeEvent
  • sui_tblsSignRandomnessObject
  • sui_transferObject
  • sui_transferSui
  • sui_tryGetPastObject

Examples

	String BASE_URL="http://localhost:9000";
	// It must be a absolute path
	String TEST_KEY_STORE_PATH=
	System.getProperty("user.home")+"/.sui/sui_config/sui.keystore";
	Sui sui=new Sui(BASE_URL,TEST_KEY_STORE_PATH);

	// query objects
	CompletableFuture<List<SuiObjectInfo>>res=
	sui.getObjectsOwnedByAddress("0xea79464d86786b7a7a63e3f13f798f29f5e65947");
	List<SuiObjectInfo> objects=res.get();
	String coinObjectId=objects.get(0).getObjectId();
	List<String> addresses=new ArrayList<>(sui.addresses());

	// Transfer sui
	CompletableFuture<ExecuteTransactionResponse> res1=
	sui.transferSui(
	"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
	coinObjectId,
	100L,
	addresses.get(0),
	2000L,
	ExecuteTransactionRequestType.WaitForLocalExecution);

	CompletableFuture<ExecuteTransactionResponse> res2=
	sui.moveCall(
	"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
	"0x0000000000000000000000000000000000000002",
	"devnet_nft",
	"mint",
	Lists.newArrayList(),
	Lists.newArrayList(
	"Example NFT",
	"An example NFT.",
	"ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"),
	null,
	2000L,
	ExecuteTransactionRequestType.WaitForLocalExecution);

For more examples, you can see SuiIntTests

Contribution

To help sui4j grow, follow Contributing to sui4j.