Skip to main content

Send a Transaction

info

Though it is possible to send transactions with iota.rs, we strongly recommend that you use the official wallet.rs library together with the stronghold.rs enclave for value-based transfers. This combination incorporates the best security practices while dealing with seeds, related addresses, and UTXO.

Pre-requirements

Before you can create a transaction, you will need to:

Create a Wallet

Create a wallet seed

You can create a wallet seed by instantiating an Ed25519Seed using its constructor. You will need to provide secretBytes to the constructor, which you can get by using the Converter.hexToBytes(hex) function.

Retrieve the wallet's address

Once you have created your wallet seed, you can use it

Once you have generated a seed, you can create a wallet using the Ed25519Address.toAddress() fucntion.

Request Funds

Before you can send the transaction, you will need to request funds. If you are on the alphanet, you can request test funds from the faucet. If you are running a private tangle, you can use the '/enqueue' endpoint.

Send the Transaction

Once you have fulfilled the pre-requirements, you can send the transaction using either the sendAdvanced(client, inputsAndSignatureKeyPairs, outputs, taggedData?) function, which will return the created block's id, or the send(client, seed, accountIndex, addressBech32, amount, taggedData?, addressOptions?) function, which will return the created block's id, as well as the constructed blocks.

As this example uses a genesis address, it must use the (client, inputsAndSignatureKeyPairs, outputs, taggedData?) function. However, if you are doing a wallet to wallet transfer, you can use the send(client, seed, accountIndex, addressBech32, amount, taggedData?, addressOptions?) method.

Example Code

stardust/packages/iota/examples/transaction/src/index.ts
loading...

Expected Output

Genesis
Seed bd80f079560f25b35ab6a5f95e31e57e1f549f81140d1d28884037dc9fa6ed10
Address Ed25519 0xd49b2cf7f727faf9cad957d14d7f13993c10010f43b0c2a5de72b728b9d01835
Address Bech32 rms1qr2fkt8h7unl47w2m9tazntlzwvncyqppapmps49meetw29e6qvr2wrxcz6
Wallet 1
Seed: e57fb750f3a3a67969ece5bd9ae7eef5b2256a818b2aac458941f7274985a410
Path: m/44'/4218'/0'/0'/0'
Address Ed25519 m/44'/4218'/0'/0'/0': 0x515582fe648b0f10a2b2a1b91d7502190c979baabfee85b6bbb5020692e55d16
Address Bech32 m/44'/4218'/0'/0'/0': rms1qpg4tqh7vj9s7y9zk2smj8t4qgvse9um42l7apdkhw6syp5ju4w3vajenuh
genesisFunds: {
address: 'rms1qr2fkt8h7unl47w2m9tazntlzwvncyqppapmps49meetw29e6qvr2wrxcz6',
waitingRequests: 1
}
Try # 1 : fetching basic output for address rms1qr2fkt8h7unl47w2m9tazntlzwvncyqppapmps49meetw29e6qvr2wrxcz6
Didn't find any, retrying soon...
Try # 2 : fetching basic output for address rms1qr2fkt8h7unl47w2m9tazntlzwvncyqppapmps49meetw29e6qvr2wrxcz6
Didn't find any, retrying soon...
Try # 3 : fetching basic output for address rms1qr2fkt8h7unl47w2m9tazntlzwvncyqppapmps49meetw29e6qvr2wrxcz6
inputsWithKeyPairs: [{"input":{"type":0,"transactionId":"0xab9c00cf096a80b8414dacb78f256d6604d968621533ca5a314c690392d5bd3d","transactionOutputIndex":0},"addressKeyPair":{"publicKey":{"0":133,"1":225,"2":45,"3":246,"4":113,"5":97,"6":179,"7":226,"8":184,"9":195,"10":212,"11":50,"12":205,"13":196,"14":138,"15":221,"16":95,"17":3,"18":229,"19":242,"20":69,"21":223,"22":2,"23":212,"24":169,"25":203,"26":248,"27":141,"28":222,"29":162,"30":252,"31":176},"privateKey":{"0":189,"1":128,"2":240,"3":121,"4":86,"5":15,"6":37,"7":179,"8":90,"9":182,"10":165,"11":249,"12":94,"13":49,"14":229,"15":126,"16":31,"17":84,"18":159,"19":129,"20":20,"21":13,"22":29,"23":40,"24":136,"25":64,"26":55,"27":220,"28":159,"29":166,"30":237,"31":16,"32":133,"33":225,"34":45,"35":246,"36":113,"37":97,"38":179,"39":226,"40":184,"41":195,"42":212,"43":50,"44":205,"45":196,"46":138,"47":221,"48":95,"49":3,"50":229,"51":242,"52":69,"53":223,"54":2,"55":212,"56":169,"57":203,"58":248,"59":141,"60":222,"61":162,"62":252,"63":176}},"consumingOutput":{"type":3,"amount":"1000000000","unlockConditions":[{"type":0,"address":{"type":0,"pubKeyHash":"0xd49b2cf7f727faf9cad957d14d7f13993c10010f43b0c2a5de72b728b9d01835"}}]}}]
Created Block Id 0xa48c85b745e964d66ca48912a88faab7c86c7662a2993a488239377f2dc07728
Wallet 1 Address Balance Integer { value: 1010000000n }
Wallet 1 First Unspent Address {
address: 'rms1qpg4tqh7vj9s7y9zk2smj8t4qgvse9um42l7apdkhw6syp5ju4w3vajenuh',
path: "m/44'/4218'/0'/0'/0'",
balance: Integer { value: 1020000000n }
}
Wallet 1 Unspent Addresses [
{
address: 'rms1qpg4tqh7vj9s7y9zk2smj8t4qgvse9um42l7apdkhw6syp5ju4w3vajenuh',
path: "m/44'/4218'/0'/0'/0'",
balance: Integer { value: 1020000000n }
}
]
Done