Object and Smart Contract
Objects and Smart Contract transaction¶
TransferObjects¶
TransactionBlockResponseOptions transactionBlockResponseOptions=
new TransactionBlockResponseOptions();
transactionBlockResponseOptions.setShowEffects(true);
transactionBlockResponseOptions.setShowEvents(true);
transactionBlockResponseOptions.setShowInput(true);
transactionBlockResponseOptions.setShowObjectChanges(true);
CompletableFuture<TransactionBlockResponse> res=
sui.transferObjects(
sender.get(),
Lists.newArrayList(objects.get(0).getData().getObjectId()),
recipient.get(),
null,
3000000L,
null,
null,
transactionBlockResponseOptions,
ExecuteTransactionRequestType.WaitForLocalExecution);
Publish¶
TransactionBlockResponseOptions transactionBlockResponseOptions=
new TransactionBlockResponseOptions();
transactionBlockResponseOptions.setShowEffects(true);
transactionBlockResponseOptions.setShowEvents(true);
transactionBlockResponseOptions.setShowInput(true);
transactionBlockResponseOptions.setShowObjectChanges(true);
CompletableFuture<TransactionBlockResponse> res=
sui.publish(
sender.get(),
Lists.newArrayList(
"oRzrCwYAAAAKAQAUAhQsA0BJBIkBEgWbAWcHggLNAgjPBGAGrwXCAwrxCC0MngnUAQAMAR4B"
+"JAIRAh0CHwIlAiYCJwIoAAACAAABDAAAAwQAAQQHAQAAAgYHAAMCDAEIAQQIBAAFBQwABwcCAAkJ"
+"BwAAFgABAAEcARUBAAEjFBUBAAIpCwwAAwoNAQEIAxoJCgEIBBoSEwAFDgYHAQIGIREBAQwGJREB"
+"AQgHIg4PAAgXBAUBAgkbCxYACwMHAwUIBAgIEAgHAgwBDAkIAggABwgIAAILBQEIAQgHAQgAAQYJ"
+"AAEBAgkABwgIAQgHAQgBAgYIBwcICAELBQEJAAEKAgEIBAMHCwUBCQAKCAQKCAQBBggIAQUBCwUB"
+"CAECCQAFAQcICAEIBgEJAAELAwEJAAEICQVCT0FSUwRCb2FyB0Rpc3BsYXkITWV0YWRhdGEGT3B0"
+"aW9uCVB1Ymxpc2hlcgZTdHJpbmcJVHhDb250ZXh0A1VJRANVcmwMYWRkX211bHRpcGxlA2FnZQVi"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Vj"
+"dGlvbiEKAgYFQ2hyaXMKAiAfaHR0cHM6Ly9nZXQtYS1ib2FyLmZ1bGx1cmwuY29tLwACARIBAQIJ"
+"FAgGFQgEGQgEEAgEDwsDAQgEIAsDAQgEGAgCDQUTCAkCAgELAwAAAAACXw4AOAAEBAUICwEBBwAn"
+"CwAKATgBDAMOAwoBOAIMAg0CBwERAwcCEQMHAxEDBwQRAwcFEQMHBhEDBwcRAwcIEQMHCREDBwoR"
+"A0AMCgAAAAAAAAAHCxEDBwwRAwcNEQMHDhEDBw8RAwcQEQMHEREDBxIRAwcTEQMHFBEDQAwKAAAA"
+"AAAAADgDCwIKAS4RCjgECwMKAS4RCjgFCgERBgcVEQMHFhEDBxcRAwcYEQM4BjgHBgoAAAAAAAAA"
+"EgIKAS4RCgcZEQwSAQsBLhEKOAgCAA=="),
Lists.newArrayList(
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000002"),
null,
30000000L,
null,
null,
transactionBlockResponseOptions,
ExecuteTransactionRequestType.WaitForLocalExecution);
MoveCall¶
TransactionBlockResponseOptions transactionBlockResponseOptions=
new TransactionBlockResponseOptions();
transactionBlockResponseOptions.setShowEffects(true);
transactionBlockResponseOptions.setShowEvents(true);
transactionBlockResponseOptions.setShowInput(true);
transactionBlockResponseOptions.setShowObjectChanges(true);
io.sui.models.transactions.TypeTag.StructType structType=
new io.sui.models.transactions.TypeTag.StructType();
io.sui.models.transactions.StructTag structTag=new StructTag();
structTag.setAddress("0x02");
structTag.setModule("sui");
structTag.setName("SUI");
structType.setStructTag(structTag);
CompletableFuture<TransactionBlockResponse> res=
sui.moveCall(
sender.get(),
"0x02",
"pay",
"split",
Lists.newArrayList(structType),
Lists.newArrayList(suiObjectResponse.getData().getObjectId(),10000L),
null,
3000000L,
null,
null,
transactionBlockResponseOptions,
ExecuteTransactionRequestType.WaitForLocalExecution);
SponsoredTransaction¶
CompletableFuture<TransactionBlockResponse> res=
sui.newTransactionBlock()
.thenCompose(
(Function<TransactionBlock, CompletableFuture<TransactionBlockResponse>>)
transactionBlock->{
transactionBlock.setExpiration(null);
transactionBlock.setSender(sender.get());
return transactionBlock
.transferObjects(
Lists.newArrayList(objects.get(0).getData().getObjectId()),
recipient.get())
.thenCompose(
(Function<Argument, CompletableFuture<TransactionBlockResponse>>)
argument->{
final CompletableFuture<TransactionData>
transactionDataCompletableFuture=
transactionBlock
.setGasData(
Lists.newArrayList(),
sponsor.get(),
3000000L,
null)
.thenCompose(
(Function<
Void,
CompletableFuture<TransactionData>>)
unused->transactionBlock.build());
TransactionBlockResponseOptions
transactionBlockResponseOptions=
new TransactionBlockResponseOptions();
transactionBlockResponseOptions.setShowEffects(true);
transactionBlockResponseOptions.setShowEvents(true);
transactionBlockResponseOptions.setShowInput(true);
transactionBlockResponseOptions.setShowObjectChanges(true);
return transactionDataCompletableFuture.thenCompose(
(Function<
TransactionData,
CompletableFuture<TransactionBlockResponse>>)
transactionData->{
Intent intent=sui.transactionDataIntent();
String sponsorSig=
sui.signTransactionBlock(
sponsor.get(),transactionData,intent);
String senderSig=
sui.signTransactionBlock(
sender.get(),transactionData,intent);
return sui.executeTransaction(
transactionData,
Lists.newArrayList(senderSig,sponsorSig),
transactionBlockResponseOptions,
ExecuteTransactionRequestType
.WaitForLocalExecution);
});
});
});
For more examples, you can see SuiIntTests