Coder Social home page Coder Social logo

grapebaba / sui4j Goto Github PK

View Code? Open in Web Editor NEW
23.0 1.0 11.0 1.46 MB

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

Home Page: https://grapebaba.github.io/sui4j/

License: Apache License 2.0

Java 100.00%
jvm blockchain java sdk bcs move sui

sui4j's Introduction

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 [email protected]: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"
				+ "ZnVsbF91cmwCaWQHaW1nX3VybARpbml0E2lzX29uZV90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EGQgEEAgEDwsDAQgEIAsDAQgEGAgCDQUTCAkCAgELAwAAAAACXw4AOAAEBAUICwEBBwAn"
				+ "CwAKATgBDAMOAwoBOAIMAg0CBwERAwcCEQMHAxEDBwQRAwcFEQMHBhEDBwcRAwcIEQMHCREDBwoR"
				+ "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.

sui4j's People

Contributors

fearlessfe avatar github-actions[bot] avatar grapebaba avatar nacrit avatar teohaik avatar thinkafcod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sui4j's Issues

Unable to initialize Sui client

I am unable to initialize Sui client with this fragment of code:

    val TEST_KEY_STORE_PATH = System.getProperty("user.home") + "/.sui/sui_config/sui.keystore"
    val sui = Sui("https://fullnode.devnet.sui.io:443", TEST_KEY_STORE_PATH)

This is the stack trace of the exception I am getting:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 65 out of bounds for byte[33]
	at java.base/java.lang.System.arraycopy(Native Method)
	at org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters.<init>(Unknown Source)
	at io.sui.crypto.ED25519KeyPair.decodeBase64(ED25519KeyPair.java:95)
	at io.sui.crypto.SuiKeyPair.decodeBase64(SuiKeyPair.java:103)
	at io.sui.crypto.FileBasedKeyStore.lambda$new$0(FileBasedKeyStore.java:52)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at io.sui.crypto.FileBasedKeyStore.<init>(FileBasedKeyStore.java:48)
	at io.sui.Sui.<init>(Sui.java:86)

Any ideas what is going on?

verify signature

How does the backend Java verify the signature of a string signed by the js front-end

Tracking sui 0.28 breaking changes


title: Sui Breaking Changes in Release .28

The next release of Sui, release 0.28, includes the breaking changes described in this topic. A breaking change is one that introduces new, or changed, Sui functionality that causes existing apps and implementations to stop functioning as expected. Updates to this topic for next week include information about how to resolve or update your project that might break as a result of these changes.

[Major breaking change] - The new Programmable Transactions feature introduces a new type of transaction that replaces both batch transactions and normal transactions (with the exception of special system transactions). These transactions allow for a series of Commands (mini transactions of sorts) to be executed, where the results of commands can be used in following commands. For more information, see the Programmable Transactions RFC.

[Major breaking change] - SuiAddress and ObjectID are now 32 bytes long instead of 20 bytes (in hex, the len increases from 40 to 64). If your software interacts with any ObjectID and SuiAddress, you must update it to use updated addresses and redeploy it. PR 8542

[Breaking change] - Changes to Gas Budget to use SUI rather than gas units. This removes the concept of gas units from any user-related API operations. This does not change the format of TransactionData (u64). This is not a breaking change in the sense that the current format no longer works, but rather requires you to reconsider how you use gas budgets.

[Breaking change] - Currently, transactions require a single coin to pay for gas. This sometimes results in users needing to make separate transactions (such as PaySui) to merge coins before completing a transaction, which can also increase the cost of the transaction.

This release changes the field value type in TransactionData from gas_payment: ObjectRef to gas_payment: Vec<ObjectRef>, where Vec<ObjectRef> is a non-empty vector of owned SUI objects. This combines all of the coins into a single coin, using the ObjectID of the first coin in the vector as the coin containing the merge.

[Breaking change] - ecdsa_k1::ecrecover and ecdsa_k1::secp256k1_verify now require you to input the raw message instead of a hashed message. You must also include the u8 that represents the hash function. See PR 7773 for more details.

[Breaking change] The ValidatorMetadata function now includes a p2p_address field. The value for the field is the address the validator used for p2p activities, such as state sync. To learn more, see PR 8636.

[Transaction Format breaking change] - Adds a new expiration field to TransactionData to allow for users to specify a time that a transaction should expire, meaning it is no longer eligible to sign and execute by validators. In this release, the only supported value for the expiration field is epoch`. If not provided, no expiration is set for the associated transaction.

[Minor breaking change] - This release modifies the format for ConsensusCommitPrologue transactions. This is a system-generated transaction that updates timestamp on the Clock object, allowing Sui Move smart contracts to read up-to-date timestamps from the blockchain.

[Minor breaking change] - Removes bulletproofs and elliptic_curve modules from the Sui Framework. For more information, see PR 8660

[API breaking change] - This release replaces SuiCertifiedTransaction with SuiTransaction in SuiTransactionResponse. This is because validators can no longer guarantee to return a transaction certificate. This release also unifies SuiTransactionResponse and SuiExecuteTransactionResponse to simplify the API. See PR 8369 for more information.

[API breaking change] - Updates the structure for dynamic field names to make it easier to use in sui_getDynamicFieldObject. For more details, see PR 7318

[API breaking change] - This release removes the request_switch_delegation function from the Transaction Builder API. It also removes the pending_delegation_switches field from the validator set type in the Sui SDK. See PR 8435 for more information.

[API breaking change] - To reduce the size of Sui Full node synchronization payloads, this release removes events from TransactionEffect. The events are still included in the SuiTransactionResponse returned by sui_getTransaction and sui_submitTransaction endpoints. For more information, see PR 7822.

Is it necessary to add a new method to generate digest in transaction information? as follows

    String digest = Base58.encode(hashTypedData("TransactionData", txBytes));

public byte[] hashTypedData(String typeTag, byte[] data) {
byte[] typeTagBytes = String.format("%s::", typeTag).getBytes();
byte[] dataWithTag = new byte[typeTagBytes.length + data.length];
System.arraycopy(typeTagBytes, 0, dataWithTag, 0, typeTagBytes.length);
System.arraycopy(data, 0, dataWithTag, typeTagBytes.length, data.length);
Blake2b.Blake2b256 blake2b256 = new Blake2b.Blake2b256();
return blake2b256.digest(dataWithTag);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.