Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions bindings/go/examples/prepare_send_iota/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

package main

import (
"log"

sdk "bindings/iota_sdk_ffi"
)

func main() {
client := sdk.GraphQlClientNewDevnet()

fromAddress, err := sdk.AddressFromHex("0x611830d3641a68f94a690dcc25d1f4b0dac948325ac18f6dd32564371735f32c")
if err != nil {
log.Fatalf("Failed to parse address: %v", err)
}

toAddress, err := sdk.AddressFromHex("0x0000a4984bd495d4346fa208ddff4f5d5e5ad48c21dec631ddebc99809f16900")
if err != nil {
log.Fatalf("Failed to parse address: %v", err)
}

coinObjId, err := sdk.ObjectIdFromHex("0xd04077fe3b6fad13b3d4ed0d535b7ca92afcac8f0f2a0e0925fb9f4f0b30c699")
if err != nil {
log.Fatalf("Failed to parse object ID: %v", err)
}
coin, err := client.Object(coinObjId, nil)
if err.(*sdk.SdkFfiError) != nil {
log.Fatalf("Failed to get coin: %v", err)
}

gasCoinObjId, err := sdk.ObjectIdFromHex("0x0b0270ee9d27da0db09651e5f7338dfa32c7ee6441ccefa1f6e305735bcfc7ab")
if err != nil {
log.Fatalf("Failed to parse object ID: %v", err)
}
gasCoin, err := client.Object(gasCoinObjId, nil)
if err.(*sdk.SdkFfiError) != nil {
log.Fatalf("Failed to get gas coin: %v", err)
}

builder := sdk.NewTransactionBuilder()
objects := []*sdk.Argument{
builder.Input(sdk.UnresolvedInputFromObject(*coin).WithOwnedKind()),
}
builder.TransferObjects(objects, builder.Input(sdk.UnresolvedInputNewPure(toAddress.ToBytes())))
builder.SetSender(fromAddress)
builder.SetGasBudget(50000000)
gasPrice, err := client.ReferenceGasPrice(nil)
if err.(*sdk.SdkFfiError) != nil {
log.Fatalf("Failed to get gas price: %v", err)
}
builder.SetGasPrice(*gasPrice)
builder.AddGasObjects([]*sdk.UnresolvedInput{sdk.UnresolvedInputFromObject(*gasCoin).WithOwnedKind()})

txn, err := builder.Finish()
if err != nil {
log.Fatalf("Failed to create transaction: %v", err)
}

txnBytes, err := txn.BcsSerialize()
if err != nil {
log.Fatalf("Failed to serialize transaction: %v", err)
}
log.Printf("Signing Digest: %v", sdk.HexEncode(txn.SigningDigest()))
log.Printf("Txn Bytes: %v", sdk.Base64Encode(txnBytes))

res, err := client.DryRunTx(txn, nil)
if err.(*sdk.SdkFfiError) != nil {
log.Fatalf("Failed to send IOTA: %v", err)
}

if res.Error != nil {
log.Fatalf("Failed to send IOTA: %v", *res.Error)
}

log.Print("Send IOTA dry run was successful!")
}
107 changes: 107 additions & 0 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,42 @@ func uniffiCheckChecksums() {
panic("iota_sdk_ffi: UniFFI contract version mismatch")
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_func_base64_decode()
})
if checksum != 57367 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_func_base64_decode: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_func_base64_encode()
})
if checksum != 54791 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_func_base64_encode: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_func_hex_decode()
})
if checksum != 35424 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_func_hex_decode: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_func_hex_encode()
})
if checksum != 34343 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_func_hex_encode: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_address_to_bytes()
})
Expand Down Expand Up @@ -3239,6 +3275,15 @@ func uniffiCheckChecksums() {
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_transaction_bcs_serialize()
})
if checksum != 39185 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_transaction_bcs_serialize: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_transaction_digest()
})
Expand Down Expand Up @@ -19368,6 +19413,7 @@ func (_ FfiDestroyerSystemPackage) Destroy(value *SystemPackage) {
// transaction-v1 = transaction-kind address gas-payment transaction-expiration
// ```
type TransactionInterface interface {
BcsSerialize() ([]byte, error)
Digest() *Digest
Expiration() TransactionExpiration
GasPayment() GasPayment
Expand Down Expand Up @@ -19398,6 +19444,23 @@ func NewTransaction(kind *TransactionKind, sender *Address, gasPayment GasPaymen



func (_self *Transaction) BcsSerialize() ([]byte, error) {
_pointer := _self.ffiObject.incrementPointer("*Transaction")
defer _self.ffiObject.decrementPointer()
_uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) RustBufferI {
return GoRustBuffer {
inner: C.uniffi_iota_sdk_ffi_fn_method_transaction_bcs_serialize(
_pointer,_uniffiStatus),
}
})
if _uniffiErr != nil {
var _uniffiDefaultValue []byte
return _uniffiDefaultValue, _uniffiErr
} else {
return FfiConverterBytesINSTANCE.Lift(_uniffiRV), nil
}
}

func (_self *Transaction) Digest() *Digest {
_pointer := _self.ffiObject.incrementPointer("*Transaction")
defer _self.ffiObject.decrementPointer()
Expand Down Expand Up @@ -33930,3 +33993,47 @@ func iota_sdk_ffi_uniffiFreeGorutine(data C.uint64_t) {
guard <- struct{}{}
}

func Base64Decode(input string) ([]byte, error) {
_uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) RustBufferI {
return GoRustBuffer {
inner: C.uniffi_iota_sdk_ffi_fn_func_base64_decode(FfiConverterStringINSTANCE.Lower(input),_uniffiStatus),
}
})
if _uniffiErr != nil {
var _uniffiDefaultValue []byte
return _uniffiDefaultValue, _uniffiErr
} else {
return FfiConverterBytesINSTANCE.Lift(_uniffiRV), nil
}
}

func Base64Encode(input []byte) string {
return FfiConverterStringINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI {
return GoRustBuffer {
inner: C.uniffi_iota_sdk_ffi_fn_func_base64_encode(FfiConverterBytesINSTANCE.Lower(input),_uniffiStatus),
}
}))
}

func HexDecode(input string) ([]byte, error) {
_uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) RustBufferI {
return GoRustBuffer {
inner: C.uniffi_iota_sdk_ffi_fn_func_hex_decode(FfiConverterStringINSTANCE.Lower(input),_uniffiStatus),
}
})
if _uniffiErr != nil {
var _uniffiDefaultValue []byte
return _uniffiDefaultValue, _uniffiErr
} else {
return FfiConverterBytesINSTANCE.Lift(_uniffiRV), nil
}
}

func HexEncode(input []byte) string {
return FfiConverterStringINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI {
return GoRustBuffer {
inner: C.uniffi_iota_sdk_ffi_fn_func_hex_encode(FfiConverterBytesINSTANCE.Lower(input),_uniffiStatus),
}
}))
}

55 changes: 55 additions & 0 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3586,6 +3586,11 @@ void uniffi_iota_sdk_ffi_fn_free_transaction(void* ptr, RustCallStatus *out_stat
void* uniffi_iota_sdk_ffi_fn_constructor_transaction_new(void* kind, void* sender, RustBuffer gas_payment, RustBuffer expiration, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTION_BCS_SERIALIZE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTION_BCS_SERIALIZE
RustBuffer uniffi_iota_sdk_ffi_fn_method_transaction_bcs_serialize(void* ptr, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTION_DIGEST
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTION_DIGEST
void* uniffi_iota_sdk_ffi_fn_method_transaction_digest(void* ptr, RustCallStatus *out_status
Expand Down Expand Up @@ -4629,6 +4634,26 @@ void uniffi_iota_sdk_ffi_fn_method_zkloginverifier_verify(void* ptr, RustBuffer
void* uniffi_iota_sdk_ffi_fn_method_zkloginverifier_with_jwks(void* ptr, RustBuffer jwks, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FUNC_BASE64_DECODE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FUNC_BASE64_DECODE
RustBuffer uniffi_iota_sdk_ffi_fn_func_base64_decode(RustBuffer input, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FUNC_BASE64_ENCODE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FUNC_BASE64_ENCODE
RustBuffer uniffi_iota_sdk_ffi_fn_func_base64_encode(RustBuffer input, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FUNC_HEX_DECODE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FUNC_HEX_DECODE
RustBuffer uniffi_iota_sdk_ffi_fn_func_hex_decode(RustBuffer input, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FUNC_HEX_ENCODE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FUNC_HEX_ENCODE
RustBuffer uniffi_iota_sdk_ffi_fn_func_hex_encode(RustBuffer input, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_FFI_IOTA_SDK_FFI_RUSTBUFFER_ALLOC
#define UNIFFI_FFIDEF_FFI_IOTA_SDK_FFI_RUSTBUFFER_ALLOC
RustBuffer ffi_iota_sdk_ffi_rustbuffer_alloc(uint64_t size, RustCallStatus *out_status
Expand Down Expand Up @@ -4907,6 +4932,30 @@ void ffi_iota_sdk_ffi_rust_future_free_void(uint64_t handle
#ifndef UNIFFI_FFIDEF_FFI_IOTA_SDK_FFI_RUST_FUTURE_COMPLETE_VOID
#define UNIFFI_FFIDEF_FFI_IOTA_SDK_FFI_RUST_FUTURE_COMPLETE_VOID
void ffi_iota_sdk_ffi_rust_future_complete_void(uint64_t handle, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_FUNC_BASE64_DECODE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_FUNC_BASE64_DECODE
uint16_t uniffi_iota_sdk_ffi_checksum_func_base64_decode(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_FUNC_BASE64_ENCODE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_FUNC_BASE64_ENCODE
uint16_t uniffi_iota_sdk_ffi_checksum_func_base64_encode(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_FUNC_HEX_DECODE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_FUNC_HEX_DECODE
uint16_t uniffi_iota_sdk_ffi_checksum_func_hex_decode(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_FUNC_HEX_ENCODE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_FUNC_HEX_ENCODE
uint16_t uniffi_iota_sdk_ffi_checksum_func_hex_encode(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ADDRESS_TO_BYTES
Expand Down Expand Up @@ -6827,6 +6876,12 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_systempackage_modules(void
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SYSTEMPACKAGE_VERSION
uint16_t uniffi_iota_sdk_ffi_checksum_method_systempackage_version(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTION_BCS_SERIALIZE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTION_BCS_SERIALIZE
uint16_t uniffi_iota_sdk_ffi_checksum_method_transaction_bcs_serialize(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTION_DIGEST
Expand Down
72 changes: 72 additions & 0 deletions bindings/kotlin/examples/PrepareSendIota.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import iota_sdk.*
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
try {
val client = GraphQlClient.newDevnet()

val fromAddress =
Address.fromHex(
"0x611830d3641a68f94a690dcc25d1f4b0dac948325ac18f6dd32564371735f32c"
)

val toAddress =
Address.fromHex(
"0x0000a4984bd495d4346fa208ddff4f5d5e5ad48c21dec631ddebc99809f16900"
)

val coin =
client.`object`(
ObjectId.fromHex(
"0xd04077fe3b6fad13b3d4ed0d535b7ca92afcac8f0f2a0e0925fb9f4f0b30c699"
)
)
if (coin == null) {
throw Exception("missing coin")
}

val gasCoin =
client.`object`(
ObjectId.fromHex(
"0x0b0270ee9d27da0db09651e5f7338dfa32c7ee6441ccefa1f6e305735bcfc7ab"
)
)
if (gasCoin == null) {
throw Exception("missing gas coin")
}

val builder = TransactionBuilder()

builder.transferObjects(
listOf(builder.input(UnresolvedInput.fromObject(coin).withOwnedKind())),
builder.input(UnresolvedInput.newPure(toAddress.toBytes()))
)

builder.setSender(fromAddress)
builder.setGasBudget(50000000u)
val refGasPrice = client.referenceGasPrice(null)
if (refGasPrice == null) {
throw Exception("missing ref gas price")
}
builder.setGasPrice(refGasPrice)
builder.addGasObjects(listOf(UnresolvedInput.fromObject(gasCoin).withOwnedKind()))

val txn = builder.finish()

println("Signing Digest: ${hexEncode(txn.signingDigest())}")
println("Txn Bytes: ${base64Encode(txn.bcsSerialize())}")

val res = client.dryRunTx(txn, false)

if (res.error != null) {
throw Exception("Failed to send IOTA: ${res.error}")
}

println("Send IOTA dry run was successful!")
} catch (e: Exception) {
e.printStackTrace()
}
}
2 changes: 1 addition & 1 deletion bindings/kotlin/examples/Stake.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fun main() = runBlocking {
val res = client.dryRunTx(txn, false)

if (res.error != null) {
throw Exception(res.error)
throw Exception("Failed to stake: ${res.error}")
}

println("Stake dry run was successful!")
Expand Down
Loading