Skip to content

Latest commit

 

History

History
214 lines (171 loc) · 6.63 KB

README.md

File metadata and controls

214 lines (171 loc) · 6.63 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 1.0.0-alpha version tested with sui v1.0.0 version.(dynamic field api will be added soon)

Maven

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

Gradle

// https://mvnrepository.com/artifact/me.grapebaba/sui4j
implementation 'me.grapebaba:sui4j:1.0.0-alpha'

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 git@github.com:MystenLabs/sui.git
cd sui
RUST_LOG="consensus=off" cargo run --bin sui-test-validator

To run Integration tests

./gradlew integrationTest

How to use it

Connecting to Sui Network

Sui sui = new Sui("<full_node_url>","<faucet_url>","<your_keystore_path>");

New Address

KeyResponse keyRes = sui.newAddress(SignatureScheme.ED25519);

Request Faucet

CompletableFuture<FaucetResponse> faucetRes = sui.requestSuiFromFaucet(s);

Writing APIs

Move Call

CompletableFuture<TransactionBlockResponse> callRes =
	sui.moveCall(
		"0x0a7421363a1f6a82800f7c9340ac02b5905798cb",
		"0x02",
		"pay",
		"split",
		Lists.newArrayList(structType),
		Lists.newArrayList("0x4b89576d18d500194f14c935bc8b297a8e1556f3217e5f125ae3d1c0f13408f9", 10000L),
		null,
		3000000L,
		null,
		null,
		transactionBlockResponseOptions,
		ExecuteTransactionRequestType.WaitForLocalExecution);

Transfer Object

CompletableFuture<TransactionBlockResponse> res =
	sui.transferObjects(
		sender.get(),
		Lists.newArrayList(objects.get(0).getData().getObjectId()),
		recipient.get(),
		null,
		3000000L,
		null,
		null,
		transactionBlockResponseOptions,
		ExecuteTransactionRequestType.WaitForLocalExecution);

Publish

CompletableFuture<TransactionBlockResponse> res =
	sui.publish(
		sender.get(),
		Lists.newArrayList(
			"oRzrCwYAAAAKAQAUAhQsA0BJBIkBEgWbAWcHggLNAgjPBGAGrwXCAwrxCC0MngnUAQAMAR4B"
				+ "JAIRAh0CHwIlAiYCJwIoAAACAAABDAAAAwQAAQQHAQAAAgYHAAMCDAEIAQQIBAAFBQwABwcCAAkJ"
				+ "BwAAFgABAAEcARUBAAEjFBUBAAIpCwwAAwoNAQEIAxoJCgEIBBoSEwAFDgYHAQIGIREBAQwGJREB"
				+ "AQgHIg4PAAgXBAUBAgkbCxYACwMHAwUIBAgIEAgHAgwBDAkIAggABwgIAAILBQEIAQgHAQgAAQYJ"
				+ "AAEBAgkABwgIAQgHAQgBAgYIBwcICAELBQEJAAEKAgEIBAMHCwUBCQAKCAQKCAQBBggIAQUBCwUB"
				+ "CAECCQAFAQcICAEIBgEJAAELAwEJAAEICQVCT0FSUwRCb2FyB0Rpc3BsYXkITWV0YWRhdGEGT3B0"
				+ "aW9uCVB1Ymxpc2hlcgZTdHJpbmcJVHhDb250ZXh0A1VJRANVcmwMYWRkX211bHRpcGxlA2FnZQVi"
				+ "b2FycwVidXllcgVjbGFpbQdjcmVhdG9yC2Rlc2NyaXB0aW9uB2Rpc3BsYXkLZHVtbXlfZmllbGQI"
				+ "ZnVsbF91cmwCaWQHaW1nX3VybARpbml0E2lzX29uZV90aW1lX3dpdG5lc3MIbWV0YWRhdGEEbmFt"
				+ "ZQNuZXcVbmV3X3Vuc2FmZV9mcm9tX2J5dGVzBG5vbmUGb2JqZWN0Bm9wdGlvbgdwYWNrYWdlBX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wcFEQMHBhEDBwcRAwcIEQMHCREDBwoR"
				+ "A0AMCgAAAAAAAAAHCxEDBwwRAwcNEQMHDhEDBw8RAwcQEQMHEREDBxIRAwcTEQMHFBEDQAwKAAAA"
				+ "AAAAADgDCwIKAS4RCjgECwMKAS4RCjgFCgERBgcVEQMHFhEDBxcRAwcYEQM4BjgHBgoAAAAAAAAA"
				+ "EgIKAS4RCgcZEQwSAQsBLhEKOAgCAA=="),
		Lists.newArrayList(
			"0x0000000000000000000000000000000000000000000000000000000000000001",
			"0x0000000000000000000000000000000000000000000000000000000000000002"),
		null,
		30000000L,
		null,
		null,
		transactionBlockResponseOptions,
		ExecuteTransactionRequestType.WaitForLocalExecution);

Reading APIs

Get Owned Objects

CompletableFuture<PaginatedObjectsResponse> res =
	sui.getObjectsOwnedByAddress(sender.get(), null, null, null);

Get Coins

CompletableFuture<PaginatedCoins> res = sui.getAllCoins(sender.get(), null, null);

Get Transaction Block

CompletableFuture<PaginatedTransactionResponse> res =
	sui.queryTransactionBlocks(query, null, 10, false);

Event APIs

Subscribe

Disposable disposable =
	sui.subscribeEvent(eventFilter, System.out::println, System.out::println);

disposable.dispose();

For more examples, you can see SuiIntTests

Contribution

To help sui4j grow, follow Contributing to sui4j.