How to use @taquito/michelson-encoder - 8 common examples

To help you get started, we’ve selected a few @taquito/michelson-encoder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ecadlabs / taquito / packages / taquito / src / contract / rpc-contract-provider.ts View on Github external
async getStorage(contract: string, schema?: ContractSchema): Promise {
    if (!schema) {
      schema = await this.rpc.getScript(contract);
    }

    let contractSchema: Schema;
    if (schema instanceof Schema) {
      contractSchema = schema;
    } else {
      contractSchema = Schema.fromRPCResponse({ script: schema as ScriptResponse });
    }

    const storage = await this.rpc.getStorage(contract);

    return contractSchema.Execute(storage, smartContractAbstractionSemantic(this)) as T; // Cast into T because only the caller can know the true type of the storage
  }
github ecadlabs / taquito / packages / taquito / src / contract / rpc-contract-provider.ts View on Github external
async getBigMapKey(contract: string, key: string, schema?: ContractSchema): Promise {
    if (!schema) {
      schema = await this.rpc.getScript(contract);
    }

    let contractSchema: Schema;
    if (schema instanceof Schema) {
      contractSchema = schema;
    } else {
      contractSchema = Schema.fromRPCResponse({ script: schema as ScriptResponse });
    }

    const encodedKey = contractSchema.EncodeBigMapKey(key);

    const val = await this.rpc.getBigMapKey(contract, encodedKey);

    return contractSchema.ExecuteOnBigMapValue(val) as T; // Cast into T because only the caller can know the true type of the storage
  }
github ecadlabs / taquito / packages / taquito / src / contract / rpc-contract-provider.ts View on Github external
async getBigMapKey(contract: string, key: string, schema?: ContractSchema): Promise {
    if (!schema) {
      schema = await this.rpc.getScript(contract);
    }

    let contractSchema: Schema;
    if (schema instanceof Schema) {
      contractSchema = schema;
    } else {
      contractSchema = Schema.fromRPCResponse({ script: schema as ScriptResponse });
    }

    const encodedKey = contractSchema.EncodeBigMapKey(key);

    const val = await this.rpc.getBigMapKey(contract, encodedKey);

    return contractSchema.ExecuteOnBigMapValue(val) as T; // Cast into T because only the caller can know the true type of the storage
  }
github ecadlabs / taquito / packages / taquito / src / contract / rpc-contract-provider.ts View on Github external
async getStorage(contract: string, schema?: ContractSchema): Promise {
    if (!schema) {
      schema = await this.rpc.getScript(contract);
    }

    let contractSchema: Schema;
    if (schema instanceof Schema) {
      contractSchema = schema;
    } else {
      contractSchema = Schema.fromRPCResponse({ script: schema as ScriptResponse });
    }

    const storage = await this.rpc.getStorage(contract);

    return contractSchema.Execute(storage, smartContractAbstractionSemantic(this)) as T; // Cast into T because only the caller can know the true type of the storage
  }
github ecadlabs / taquito / packages / taquito / src / contract / prepare.ts View on Github external
storageLimit = DEFAULT_STORAGE_LIMIT.ORIGINATION,
  }: OriginateParams,
  publicKeyHash: string
) => {
  // tslint:disable-next-line: strict-type-predicates
  if (storage !== undefined && init !== undefined) {
    throw new Error(
      'Storage and Init cannot be set a the same time. Please either use storage or init but not both.'
    );
  }

  const contractCode = Array.isArray(code) ? code : ml2mic(code);

  let contractStorage: object;
  if (storage !== undefined) {
    const schema = new Schema(contractCode[1].args[0]);
    contractStorage = schema.Encode(storage);
  } else {
    contractStorage = typeof init === 'string' ? sexp2mic(init) : init;
  }

  const script = {
    code: Array.isArray(code) ? code : ml2mic(code),
    storage: contractStorage,
  };

  const operation: RPCOriginationOperation = {
    kind: 'origination',
    fee,
    gas_limit: gasLimit,
    storage_limit: storageLimit,
    balance: format('tz', 'mutez', balance).toString(),
github ecadlabs / taquito / packages / taquito / src / contract / contract.ts View on Github external
constructor(
    public readonly address: string,
    public readonly script: ScriptResponse,
    private provider: ContractProvider,
    private entrypoints?: EntrypointsResponse
  ) {
    this.schema = Schema.fromRPCResponse({ script: this.script });
    this.parameterSchema = ParameterSchema.fromRPCResponse({ script: this.script });
    if (!this.entrypoints) {
      this._initializeMethodsLegacy(address, provider);
    } else {
      this._initializeMethods(address, provider, this.entrypoints.entrypoints);
    }
  }
github ecadlabs / taquito / packages / taquito / src / contract / contract.ts View on Github external
const method = function(...args: any[]) {
          const smartContractMethodSchema = new ParameterSchema(
            entrypoints[smartContractMethodName]
          );

          validateArgs(args, smartContractMethodSchema, smartContractMethodName);

          return new ContractMethod(
            provider,
            address,
            smartContractMethodSchema,
            smartContractMethodName,
            args
          );
        };
        this.methods[smartContractMethodName] = method;
github ecadlabs / taquito / packages / taquito / src / contract / contract.ts View on Github external
constructor(
    public readonly address: string,
    public readonly script: ScriptResponse,
    private provider: ContractProvider,
    private entrypoints?: EntrypointsResponse
  ) {
    this.schema = Schema.fromRPCResponse({ script: this.script });
    this.parameterSchema = ParameterSchema.fromRPCResponse({ script: this.script });
    if (!this.entrypoints) {
      this._initializeMethodsLegacy(address, provider);
    } else {
      this._initializeMethods(address, provider, this.entrypoints.entrypoints);
    }
  }

@taquito/michelson-encoder

converts michelson data and types into convenient JS/TS objects

Apache-2.0
Latest version published 1 month ago

Package Health Score

66 / 100
Full package analysis