https://github.com/stellar/js-stellar-xdr-json
A JS library for XDR conversion to and from JSON.
https://github.com/stellar/js-stellar-xdr-json
Last synced: about 1 year ago
JSON representation
A JS library for XDR conversion to and from JSON.
- Host: GitHub
- URL: https://github.com/stellar/js-stellar-xdr-json
- Owner: stellar
- License: apache-2.0
- Created: 2024-05-17T16:41:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-12T02:28:59.000Z (over 1 year ago)
- Last Synced: 2025-03-22T18:41:26.525Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 58.6 KB
- Stars: 2
- Watchers: 10
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# js-stellar-xdr-json
A JS library for XDR conversion to and from JSON.
## Usage
```js
import init, { decode, encode, guess, types, schema } from "@stellar/stellar-xdr-json";
// Fetch and initialize the Wasm module.
await init();
// Get a list of XDR types.
console.log(types());
// Get the JSON schema for any type.
console.log(schema("TransactionResult"));
// Guess what types an XDR value could be.
console.log(guess("AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="));
// Encode an XDR value.
console.log(encode(
"TransactionResult",
JSON.stringify(
{
"fee_charged": 100,
"result": {
"tx_success": [{ "op_inner": { "payment": "success" } }],
},
"ext": "v0",
},
),
));
// Decode an XDR value.
console.log(
decode("TransactionResult", "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="),
);