-
Notifications
You must be signed in to change notification settings - Fork 922
it should be possible to create a transaction using plain objects #1693
Comments
I guess it would be totally possible to just use pipe under the hood here, but the resulting object would still be frozen like we're doing with each of those modular transaction modifiers. We could roll something along these lines: export function createTransaction(config: {
feePayer?: Base58EncodedAddress,
lifetime?: BlockhashLifetime | DurableNonceLifetime,
instructions?: TransactionInstruction[],
version: 'legacy' | 0,
}): Transaction | Transaction & TransactionWithFeePayer | Transaction & TransactionWithFeePayer & TransactionWithBlockhashLifetime {
if 'feePayer' in config {
pipe(
createTransactionInner({ version: config.version }),
tx => setTransactionFeePayer(config.feePayer, tx),
)
} else if {
/* all the rest */
}
} |
Pardon the wait, it's been a long month with Breakpoint The intention is that the result not be frozen - rather that the transaction is undateable using standard JS mechanisms (object and array accessors) until the moment the transaction is sent. Signing, building a JSON-RPC body and sending would be handled as an atomic operation after the developer considers the transaction 'complete', ie, so the signature always matches the transaction body. For example a developer could add a instruction by using array methods they already know, or set values inside the transaction using object.key accessors. When the developer wants to sign and send the transaction, they run
|
Thanks for circling back @mikemaccana, I think @lorisleiva has just the thing for you on this. TL/DR: If you want short-hand, you'll do something like So it's coming along nicely! |
Y'all are invited to publish helper packages that reconfigure the API like this. One of the good things about the functional API we've created is that it's flexible to the degree where it allows for this. Be aware though, that:
|
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up. |
Motivation
Piping and method chaining are not common approach to configuration in JS SDKs.
JS doesn't include an inbuilt pipeline operator, and the proposal to add one has been in draft since 2015, and is still in stage 2, which means it is still a draft and subject to change. Since pipelining isn't part of JS/TS, less people are familiar with the concept than with other languages. Many JS/TS front end developers do not have experience with languages (eg Elixir) where pipelinign is more popular.
Well regarded APIs like node.js, Svelte, React, Stripe, and Twilio use plain JS Object / TS Records to do configuration, rather than having end users use pipelining, method chaining, or similar.
It should be possible to create a transaction using Plain Old JavaScript Objects:
Before
Proposing
Example use case
A JS user, familiar with common JS practices of specifying config as a plain JS
Object
or TSRecord<string, unknown>
makes a transaction withcreateTransaction()
. They know transactions have a series of instructions, so look for theinstructions
key find it. They add an array instructions as the value.The text was updated successfully, but these errors were encountered: