flow-bridge
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Initialization

import { FlowBridge } from 'flow-bridge';

const bridge = new FlowBridge("https://access-mainnet-beta.onflow.org");

Flow Bridge Api

Get events for block range

bridge.getEventsForHeightRange(options: {
    bottom: number;
    top: number;
    type: string;
}): Promise<EventsResponse.AsObject>

Execute a script

bridge.executeScript<T extends Type = Void>(options: {
    script: string;
    args: Type[];
}): Promise<T> 

Ping the chain

bridge.ping(): Promise<void>

Get latest block

bridge.getLatestBlock(option: {
    isSealed: boolean;
}): Promise<BlockResponse.AsObject> 

Get block by id

bridge.getBlockById(option: { id: string }): Promise<BlockResponse.AsObject>

Get block by height

bridge.getBlockByHeight(option: {
    height: number;
}): Promise<BlockResponse.AsObject>

Get account at block height

bridge.getAccountAtLatestBlock(option: {
    address: string;
}): Promise<AccountResponse.AsObject> 

Get transaction by id

getTransactionById(option: {
    id: string;
}): Promise<TransactionResponse.AsObject> 

Create a transaction

createTransaction(
    params: CreateTransactionParams
): Promise<Transaction>

Send a transaction

sendTransaction(
    createTransactionParams: CreateTransactionParams
): Promise<string>

Transaction types

interface TransactionSignature {
  address: string;
  keyId: number;
  signature: string;
}

interface TransactionSignatureCreator {
  address: string;
  keyId: number;
  signingFn: (message: string) => Promise<string>;
}

interface ProposalKey {
  address: string;
  keyId: number;
  sequenceNumber: number;
}

interface UnresolvedProposalKey {
  address: string;
  keyId: number;
}

interface TransactionPayload {
  script: string;
  arguments: Type[];
  referenceBlock: string;
  gasLimit: number;
  proposalKey: ProposalKey;
  payer: string;
  authorizers: string[];
}

interface TransactionEnvelope extends TransactionPayload {
  payloadSignatures: TransactionSignature[];
}

interface Transaction extends TransactionEnvelope {
  envelopeSignatures: TransactionSignature[];
}

interface CreateTransactionPayloadParams {
  script: string;
  arguments: Type[];
  referenceBlock?: string;
  gasLimit?: number;
  proposalKey: ProposalKey | UnresolvedProposalKey;
  payer: string;
  authorizers: string[];
}

interface CreateTransactionEnvelopeParams
  extends CreateTransactionPayloadParams {
  payloadSignatures: (TransactionSignature | TransactionSignatureCreator)[];
}

interface CreateTransactionParams
  extends CreateTransactionEnvelopeParams {
  envelopeSignatures: (TransactionSignature | TransactionSignatureCreator)[];
}

Type

The Type are based on the json-cadence syntax. Those are the types implemented right now:

interface Void {
  type: "Void";
}

interface Optional {
  type: "Optional";
  value: Type | null;
}

interface Bool {
  type: "Bool";
  value: boolean;
}

interface CString {
  type: "String";
  value: string;
}

interface Address {
  type: "Address";
  value: `0x${string}`;
}

interface Int {
  type: "Int";
  value: string;
}

interface Int8 {
  type: "Int8";
  value: string;
}

interface Int16 {
  type: "Int16";
  value: string;
}

interface Int32 {
  type: "Int32";
  value: string;
}

interface Int64 {
  type: "Int64";
  value: string;
}

interface Int128 {
  type: "Int128";
  value: string;
}

interface Int256 {
  type: "Int256";
  value: string;
}

interface Word8 {
  type: "Word8";
  value: string;
}

interface Word16 {
  type: "Word16";
  value: string;
}

interface Word32 {
  type: "Word32";
  value: string;
}

interface Word64 {
  type: "Word64";
  value: string;
}

interface CArray {
  type: "Array";
  value: Type[];
}

interface Dictionary {
  type: "Dictionary";
  value: { key: Type; value: Type }[];
}

Misc

Command for the improbable code gen

protoc \
    -I=protos \
    --plugin="protoc-gen-ts=./node_modules/.bin/protoc-gen-ts" \
    --js_out="import_style=commonjs,binary:lib-web/out_improbable" \
    --ts_out="service=grpc-web:lib-web/out_improbable" \
    protos/FlowInteractions.proto
protoc \
    -I=protos \
    --plugin="protoc-gen-ts=./node_modules/.bin/protoc-gen-ts" \
    --plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin \
    --js_out="import_style=commonjs,binary:out_improbable_node" \
    --ts_out="service=grpc-node:out_improbable_node" \
    --grpc_out="grpc_js:out_improbable_node" \
    protos/FlowInteractions.proto

Run the web version

npm run roll npm run web

Run the node version

npm run transpile npm start

Readme

Keywords

none

Package Sidebar

Install

npm i flow-bridge

Weekly Downloads

0

Version

1.0.6

License

ISC

Unpacked Size

1.11 MB

Total Files

54

Last publish

Collaborators

  • jekel18