Skip to content

Commit e43f8a3

Browse files
committed
feedback tweaks
1 parent b987097 commit e43f8a3

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

examples/with-iota/src/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ async function main() {
3939
IOTA_PUBLIC_KEY,
4040
} = process.env;
4141

42+
// *** ENVIRONMENT CHECKING *** //
43+
4244
if (IOTA_ADDRESS === undefined || IOTA_PUBLIC_KEY === undefined) {
4345
throw new Error('IOTA_ADDRESS or IOTA_PUBLIC_KEY not set in .env.local');
4446
}
4547

48+
const publicKey = new Ed25519PublicKey(Buffer.from(IOTA_PUBLIC_KEY!, 'hex'));
49+
if (publicKey.toIotaAddress() !== IOTA_ADDRESS) {
50+
throw new Error('IOTA_PUBLIC_KEY does not match IOTA_ADDRESS');
51+
}
52+
4653
// sending to the same address
4754
const recipient = IOTA_ADDRESS;
4855
const amount = 1_000_000n; // 0.001 IOTA
@@ -54,12 +61,9 @@ async function main() {
5461
defaultOrganizationId: ORGANIZATION_ID!,
5562
});
5663

57-
const provider = new IotaClient({ url: getFullnodeUrl('testnet') });
58-
const publicKey = new Ed25519PublicKey(Buffer.from(IOTA_PUBLIC_KEY!, 'hex'));
64+
// *** TRANSACTION BUILDING *** //
5965

60-
if (publicKey.toIotaAddress() !== IOTA_ADDRESS) {
61-
throw new Error('IOTA_PUBLIC_KEY does not match IOTA_ADDRESS');
62-
}
66+
const provider = new IotaClient({ url: getFullnodeUrl('testnet') });
6367

6468
// fetch the user's IOTA coin objects
6569
const coins = await provider.getCoins({
@@ -78,7 +82,7 @@ async function main() {
7882
version: coins.data[0]!.version,
7983
digest: coins.data[0]!.digest,
8084
},
81-
]);
85+
]); // separate intended send amount from gas payment
8286
const coin = tx.splitCoins(tx.gas, [tx.pure('u64', amount)]);
8387
tx.transferObjects([coin], tx.pure.address(recipient));
8488

@@ -97,6 +101,8 @@ async function main() {
97101
const signature = Buffer.from(r + s, 'hex');
98102
const serialized = toSerializedSignature({ signature, pubKey: publicKey });
99103

104+
// *** EXECUTION *** //
105+
100106
const result = await provider.executeTransactionBlock({
101107
transactionBlock: Buffer.from(txBytes).toString('base64'),
102108
signature: serialized,

examples/with-sui/src/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ async function main() {
4343
throw new Error('SUI_ADDRESS or SUI_PUBLIC_KEY not set in .env.local');
4444
}
4545

46+
const publicKey = new Ed25519PublicKey(Buffer.from(SUI_PUBLIC_KEY!, 'hex'));
47+
if (publicKey.toSuiAddress() !== SUI_ADDRESS) {
48+
throw new Error('SUI_PUBLIC_KEY does not match SUI_ADDRESS');
49+
}
50+
4651
// sending to the same address
4752
const recipient = SUI_ADDRESS;
4853
const amount = 1_000_000n; // 0.001 SUI
@@ -54,12 +59,9 @@ async function main() {
5459
defaultOrganizationId: ORGANIZATION_ID!,
5560
});
5661

57-
const provider = new SuiClient({ url: getFullnodeUrl('testnet') });
58-
const publicKey = new Ed25519PublicKey(Buffer.from(SUI_PUBLIC_KEY!, 'hex'));
62+
// *** TRANSACTION BUILDING *** //
5963

60-
if (publicKey.toSuiAddress() !== SUI_ADDRESS) {
61-
throw new Error('SUI_PUBLIC_KEY does not match SUI_ADDRESS');
62-
}
64+
const provider = new SuiClient({ url: getFullnodeUrl('testnet') });
6365

6466
// fetch the user's SUI coin objects
6567
const coins = await provider.getCoins({
@@ -78,7 +80,7 @@ async function main() {
7880
version: coins.data[0]!.version,
7981
digest: coins.data[0]!.digest,
8082
},
81-
]);
83+
]); // separate intended send amount from gas payment
8284
const coin = tx.splitCoins(tx.gas, [tx.pure('u64', amount)]);
8385
tx.transferObjects([coin], tx.pure.address(recipient));
8486

@@ -97,6 +99,8 @@ async function main() {
9799
const signature = Buffer.from(r + s, 'hex');
98100
const serialized = toSerializedSignature({ signature, pubKey: publicKey });
99101

102+
// *** EXECUTION *** //
103+
100104
const result = await provider.executeTransactionBlock({
101105
transactionBlock: Buffer.from(txBytes).toString('base64'),
102106
signature: serialized,

0 commit comments

Comments
 (0)