@script3/soroban-governor-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

soroban-governor-js-sdk JS

JS library for interacting with Soroban smart contracts soroban-governor and soroban-votes via Soroban RPC.

Use it

Now that you have your library up-to-date and added to your project, you can import it in a file and see inline documentation for all of its exported methods:

import { VotesClient } from "soroban-governor-js-sdk";

let rpc = new SorobanRpc.Server("rpcUrl");
let account = await rpc.getAccount("public key");
let votes = new VotesClient("Contract Address");

let { op, parser } = votes.depositFor({
  from: config.admin.publicKey(),
  amount: 100000n,
});

// Create transaction from operation
let tx = new TransactionBuilder(account, {
  fee: "10000",
  networkPassphrase: "passphrase",
})
  .setTimeout(TimeoutInfinite)
  .addOperation(xdr.Operation.fromXDR(op.toXDR("base64"), "base64"))
  .build();

// Simulate
let sim_resp = await rpc.simulateTransaction(tx);

// Parse Response
let result = ContractResult.fromSimulationResponse(sim_resp, parser);

// Error handling
if (result.result.isErr()) {
  let error = result.result.unwrapErr();
  if (error.type == ContractErrorType.InvokeHostFunctionEntryArchived) {
    // create a restore ledger entry tx_builder
  } else {
    throw result.result.unwrapErr();
  }
}

// ...Handle transaction signing and submitting

Readme

Keywords

none

Package Sidebar

Install

npm i @script3/soroban-governor-sdk

Weekly Downloads

59

Version

1.0.1

License

MIT

Unpacked Size

205 kB

Total Files

29

Last publish

Collaborators

  • mootz12