Skip to content

Documentation

Andrew Kishino edited this page May 30, 2019 · 24 revisions

Sotez

Main tez.js Library

Parameters

  • provider String Address of the node (optional, default 'http://127.0.0.1:8732')
  • chain String Chain Id (optional, default 'main')
  • network String Network ['main', 'zero',] (optional, default 'main')
  • options Object (optional, default {})
    • options.defaultFee Number The default fee for tranactions (optional, default 1278)
    • options.debugMode Boolean Debug mode enablement (optional, default false)
    • options.localForge Boolean Forge operations locally (optional, default true)
    • options.validateLocalForge Boolean Validate local forge bytes against remote forged bytes (optional, default false)

Examples

import Sotez from 'sotez';
const sotez = new Sotez('https://127.0.0.1:8732', 'main', 'main', { defaultFee: 1275 })
await sotez.importKey('edskRv6ZnkLQMVustbYHFPNsABu1Js6pEEWyMUFJQTqEZjVCU2WHh8ckcc7YA4uBzPiJjZCsv3pC1NDdV99AnyLzPjSip4uC3y');
sotez.transfer({
  to: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
  amount: '1000000',
});

importKey

Import a secret key

Parameters

  • key String The secret key
  • passphrase String? The passphrase of the encrypted key
  • email String? The email associated with the fundraiser account

Examples

await sotez.importKey('edskRv6ZnkLQMVustbYHFPNsABu1Js6pEEWyMUFJQTqEZjVCU2WHh8ckcc7YA4uBzPiJjZCsv3pC1NDdV99AnyLzPjSip4uC3y');

importLedger

Import a ledger public key

Parameters

  • path String The ledger path (optional, default "44'/1729'/0'/0'")
  • curve Number The curve parameter (optional, default 0x00)

Examples

await sotez.importLedger();

query

Queries a node given a path and payload

Parameters

  • path String The RPC path to query
  • payload String The payload of the query
  • method String The request method. Either 'GET' or 'POST'

Examples

sotez.query(`/chains/main/blocks/head`)
 .then(head => console.log(head));

Returns Promise The response of the query

account

Originate a new account

Parameters

  • paramObject Object The parameters for the origination
    • paramObject.balance Number The amount in tez to transfer for the initial balance
    • paramObject.spendable Boolean? Whether the keyholder can spend the balance from the new account
    • paramObject.delegatable Boolean? Whether the new account is delegatable
    • paramObject.delegate String? The delegate for the new account
    • paramObject.fee Number The fee to set for the transaction (optional, default 1278)
    • paramObject.gasLimit Number The gas limit to set for the transaction (optional, default 10000)
    • paramObject.storageLimit Number The storage limit to set for the transaction (optional, default 257)

Examples

sotez.account({
  amount: 10,
  spendable: true,
  delegatable: true,
  delegate: 'tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4',
}).then(res => console.log(res.operations[0].metadata.operation_result.originated_contracts[0]))

Returns Promise Object containing the injected operation hash

getBalance

Get the balance for a contract

Parameters

  • address String The contract for which to retrieve the balance

Examples

sotez.getBalance('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
  .then(balance => console.log(balance))

Returns Promise The balance of the contract

getDelegate

Get the delegate for a contract

Parameters

  • address String The contract for which to retrieve the delegate

Examples

sotez.getDelegate('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
  .then(delegate => console.log(delegate))

Returns Promise The delegate of a contract, if any

getManager

Get the manager for a contract

Parameters

  • address String The contract for which to retrieve the manager

Examples

sotez.getManager('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
  .then(({ manager, key }) => console.log(manager, key))

Returns Promise The manager of a contract

getCounter

Get the counter for an contract

Parameters

  • address String The contract for which to retrieve the counter

Examples

sotez.getCounter('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
  .then(counter => console.log(counter))

Returns Promise The counter of a contract, if any

getBaker

Get the baker information for an address

Parameters

  • address String The contract for which to retrieve the baker information

Examples

sotez.getBaker('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
  .then(({
    balance,
    frozen_balance,
    frozen_balance_by_cycle,
    staking_balance,
    delegated_contracts,
    delegated_balance,
    deactivated,
    grace_period,
  }) => console.log(
    balance,
    frozen_balance,
    frozen_balance_by_cycle,
    staking_balance,
    delegated_contracts,
    delegated_balance,
    deactivated,
    grace_period,
  ))

Returns Promise The information of the delegate address

getHeader

Get the header of the current head

Examples

sotez.getHeader().then(header => console.log(header))

Returns Promise The whole block header

getHead

Get the current head block of the chain

Examples

sotez.getHead().then(head => console.log(head))

Returns Promise The current head block

getHeadHash

Get the current head block hash of the chain

Examples

sotez.getHeadHash().then(headHash => console.log(headHash))

Returns Promise The block's hash, its unique identifier

getBallotList

Ballots casted so far during a voting period

Examples

sotez.getBallotList().then(ballotList => console.log(ballotList))

Returns Promise Ballots casted so far during a voting period

getProposals

List of proposals with number of supporters

Examples

sotez.getProposals().then(proposals => {
  console.log(proposals[0][0], proposals[0][1])
  console.log(proposals[1][0], proposals[1][1])
)

Returns Promise List of proposals with number of supporters

getBallots

Sum of ballots casted so far during a voting period

Examples

sotez.getBallots().then(({ yay, nay, pass }) => console.log(yay, nay, pass))

Returns Promise Sum of ballots casted so far during a voting period

getListings

List of delegates with their voting weight, in number of rolls

Examples

sotez.getListings().then(listings => console.log(listings))

Returns Promise The ballots of the current voting period

getCurrentProposal

Current proposal under evaluation

Examples

sotez.getCurrentProposal().then(currentProposal => console.log(currentProposal))

Returns Promise Current proposal under evaluation

getCurrentPeriod

Current period kind

Examples

sotez.getCurrentPeriod().then(currentPeriod => console.log(currentPeriod))

Returns Promise Current period kind

getCurrentQuorum

Current expected quorum

Examples

sotez.getCurrentQuorum().then(currentQuorum => console.log(currentQuorum))

Returns Promise Current expected quorum

awaitOperation

Check for the inclusion of an operation in new blocks

Parameters

  • hash String The operation hash to check
  • interval Number The interval to check new blocks (optional, default 10)
  • timeout Number The time before the operation times out (optional, default 180)

Examples

sotez.awaitOperation('ooYf5iK6EdTx3XfBusgDqS6znACTq5469D1zQSDFNrs5KdTuUGi')
 .then((hash) => console.log(hash));

Returns Promise The hash of the block in which the operation was included

call

Get the current head block hash of the chain

Parameters

  • path String The path to query
  • payload Object The payload of the request

Returns Promise The response of the rpc call

prepareOperation

Prepares an operation

Parameters

  • paramObject Object The parameters for the operation
    • paramObject.operation (Object | Array) The operation to include in the transaction

Examples

sotez.prepareOperation({
  operation: {
    kind: 'transaction',
    fee: '50000',
    gas_limit: '10200',
    storage_limit: '0',
    amount: '1000',
    destination: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
  }
}).then(({ opbytes, opOb, counter }) => console.log(opbytes, opOb, counter));

Returns Promise Object containing the prepared operation

simulateOperation

Simulate an operation

Parameters

  • paramObject Object The parameters for the operation
    • paramObject.operation (Object | Array) The operation to include in the transaction

Examples

sotez.simulateOperation({
  operation: {
    kind: 'transaction',
    fee: '50000',
    gas_limit: '10200',
    storage_limit: '0',
    amount: '1000',
    destination: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
  },
}).then(result => console.log(result));

Returns Promise The simulated operation result

sendOperation

Send an operation

Parameters

  • paramObject Object The parameters for the operation
    • paramObject.operation (Object | Array) The operation to include in the transaction
    • paramObject.skipPrevalidation Boolean Skip prevalidation before injecting operation (optional, default false)
    • paramObject.skipSignature (optional, default false)

Examples

const operation = {
  kind: 'transaction',
  fee: '50000',
  gas_limit: '10200',
  storage_limit: '0',
  amount: '1000',
  destination: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
};

sotez.sendOperation({ operation }).then(result => console.log(result));

sotez.sendOperation({ operation: [operation, operation] }).then(result => console.log(result));

Returns Promise Object containing the injected operation hash

inject

Inject an operation

Parameters

  • opOb Object The operation object
  • sopbytes String The signed operation bytes

Returns Promise Object containing the injected operation hash

silentInject

Inject an operation without prevalidation

Parameters

  • sopbytes String The signed operation bytes

Returns Promise Object containing the injected operation hash

transfer

Transfer operation

Parameters

  • paramObject Object The parameters for the operation
    • paramObject.to String The address of the recipient
    • paramObject.amount Number The amount in tez to transfer for the initial balance
    • paramObject.parameter String The parameter for the transaction (optional, default false)
    • paramObject.fee Number The fee to set for the transaction (optional, default 1278)
    • paramObject.gasLimit Number The gas limit to set for the transaction (optional, default 10100)
    • paramObject.storageLimit Number The storage limit to set for the transaction (optional, default 0)
    • paramObject.mutez Number Whether the input amount is set to mutez (1/1,000,000 tez) (optional, default false)
    • paramObject.rawParam Number Whether to accept the object parameter format (optional, default false)

Examples

sotez.transfer({
  to: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
  amount: '1000000',
  fee: '1278',
}).then(result => console.log(result))

Returns Promise Object containing the injected operation hash

activate

Activate an account

Parameters

  • pkh Object The public key hash of the account
  • secret String The secret to activate the account

Examples

sotez.activate(pkh, secret)
  .then((activateOperation) => console.log(activateOperation))

Returns Promise Object containing the injected operation hash

originate

Originate a new contract

Parameters

  • paramObject Object The parameters for the operation
    • paramObject.balance Number The amount in tez to transfer for the initial balance
    • paramObject.code String The code to deploy for the contract
    • paramObject.init String The initial storage of the contract
    • paramObject.spendable Boolean Whether the keyholder can spend the balance from the new account (optional, default false)
    • paramObject.delegatable Boolean Whether the new account is delegatable (optional, default false)
    • paramObject.delegate String? The delegate for the new account
    • paramObject.fee Number The fee to set for the transaction (optional, default 1278)
    • paramObject.gasLimit Number The gas limit to set for the transaction (optional, default 10000)
    • paramObject.storageLimit Number The storage limit to set for the transaction (optional, default 257)

Returns Promise Object containing the injected operation hash

setDelegate

Set a delegate for an account

Parameters

  • paramObject Object The parameters for the operation
    • paramObject.delegate String? The delegate for the new account
    • paramObject.fee Number The fee to set for the transaction (optional, default 1278)
    • paramObject.gasLimit Number The gas limit to set for the transaction (optional, default 10000)
    • paramObject.storageLimit Number The storage limit to set for the transaction (optional, default 0)

Returns Promise Object containing the injected operation hash

registerDelegate

Register an account as a delegate

Parameters

  • paramObject Object The parameters for the operation
    • paramObject.fee Number The fee to set for the transaction (optional, default 1278)
    • paramObject.gasLimit Number The gas limit to set for the transaction (optional, default 10000)
    • paramObject.storageLimit Number The storage limit to set for the transaction (optional, default 0)

Returns Promise Object containing the injected operation hash

typecheckCode

Typechecks the provided code

Parameters

  • code String The code to typecheck

Returns Promise Typecheck result

packData

Serializes a piece of data to a binary representation

Parameters

Returns Promise Serialized data

typecheckData

Typechecks data against a type

Parameters

Returns Promise Typecheck result

runCode

Runs or traces code against an input and storage

Parameters

  • code String Code to run
  • amount Number Amount to send
  • input String Input to run though code
  • storage String State of storage
  • trace Boolean Whether to trace (optional, default false)

Returns Promise Run results

crypto

extractKeys

Extract key pairs from a secret key

Parameters

  • sk String The secret key to extract key pairs from
  • password String? The password used to encrypt the sk (optional, default '')

Examples

crypto.extractKeys('edskRqAF8s2MKKqRMxq53CYYLMnrqvokMyrtmPRFd5H9osc4bFmqKBY119jiiqKQMti2frLAoKGgZSQN3Lc3ybf5sgPUy38e5A')
  .then(({ sk, pk, pkh }) => console.log(sk, pk, pkh))

Returns Promise The extracted key pairs

generateMnemonic

Generate a mnemonic

Returns String The generated mnemonic

checkAddress

Check the validity of a tezos implicit address (tz1...)

Parameters

  • address String The address to check

Returns Boolean Whether address is valid or not

generateKeys

Generate a new key pair given a mnemonic and passphrase

Parameters

  • mnemonic String The mnemonic seed
  • passphrase String The passphrase used to encrypt the seed

Examples

crypto.generateKeys('raw peace visual boil prefer rebel anchor right elegant side gossip enroll force salmon between', 'my_password_123')
  .then(({ mnemonic, passphrase, sk, pk, pkh }) => console.log(mnemonic, passphrase, sk, pk, pkh))

Returns Promise The generated key pair

sign

Sign bytes

Parameters

  • bytes String The bytes to sign
  • sk String The secret key to sign the bytes with
  • wm Object The watermark bytes
  • password String? The password used to encrypt the sk (optional, default '')

Examples

import { watermark } from 'sotez';

crypto.sign(opbytes, keys.sk, watermark.generic)
  .then(({ bytes, sig, edsig, sbytes }) => console.log(bytes, sig, edsig, sbytes))

Returns Promise The signed bytes

verify

Verify signed bytes

Parameters

  • bytes String The signed bytes
  • sig String The signature of the signed bytes
  • pk String The public key

Returns Boolean Whether the signed bytes are valid

utility

b582int

Convert from base58 to integer

Parameters

Returns String The converted b58 value

totez

Convert from mutez to tez

Parameters

  • mutez Number The amount in mutez to convert to tez

Returns Number The mutez amount converted to tez

mutez

Convert from tez to mutez

Parameters

  • tez Number The amount in tez to convert to mutez

Returns String The tez amount converted to mutez

b58cencode

Base58 encode

Parameters

Returns String The base58 encoded value

b58cdecode

Base58 decode

Parameters

  • enc string
  • prefixArg Object The Uint8Array prefix values
  • payload String The value to decode

Returns String The decoded base58 value

buf2hex

Buffer to hex

Parameters

  • buffer Object The buffer to convert to hex

Returns String Converted hex value

hex2buf

Hex to Buffer

Parameters

  • hex String The hex to convert to buffer

Returns Object Converted buffer value

hexNonce

Generate a hex nonce

Parameters

  • length Number The length of the nonce

Returns String The nonce of the given length

mergebuf

Merge two buffers together

Parameters

Returns Object The merged buffer

forge

toBytesInt32

Convert bytes from Int32

Parameters

  • num Number Number to convert to bytes

Returns Object The converted number

toBytesInt32Hex

Convert hex from Int32

Parameters

  • num Number Number to convert to hex

Returns String The converted number

bool

Forge boolean

Parameters

  • bool Boolean Boolean value to convert

Returns String The converted boolean

script

Forge script bytes

Parameters

  • script Object Script to forge
    • script.code String Script code
    • script.storage String Script storage

Returns String Forged script bytes

parameters

Forge parameter bytes

Parameters

  • parameter String Script to forge

Returns String Forged parameter bytes

publicKeyHash

Forge public key hash bytes

Parameters

  • pkh String Public key hash to forge

Returns String Forged public key hash bytes

address

Forge address bytes

Parameters

  • address String Address to forge

Returns String Forged address bytes

zarith

Forge zarith bytes

Parameters

Returns String Forged zarith bytes

publicKey

Forge public key bytes

Parameters

  • pk Number Public key to forge

Returns String Forged public key bytes

op

Forge operation bytes

Parameters

  • op Object Operation to forge

Returns String Forged operation bytes

forge

Forge operation bytes

Parameters

  • opOb Object The operation object(s)
  • counter number The current counter

Examples

forge.forge({
  branch: 'BKvjkVa7QxS99ckCEbTRtXm9pLxAGz9Km5AgHciHw8Xzkeo2jMS',
  contents: [{
    kind: 'transaction',
    source: 'tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4',
    fee: '50000',
    counter: '31204',
    gas_limit: '10200',
    storage_limit: '0',
    amount: '100000000',
    destination: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
  }],
}, 59326).then(({ opbytes, opOb }) => console.log(opbytes, opOb))

Returns String Forged operation bytes

decodeRawBytes

Decode raw bytes

Parameters

  • bytes String The bytes to decode

Returns Object Decoded raw bytes

encodeRawBytes

Encode raw bytes

Parameters

  • input Object The value to encode

Returns String Encoded value as bytes

ledger

getAddress

Get the public key and public key hash from the ledger

Parameters

  • ledgerParams Object The parameters of the getAddress function (optional, default {})
    • ledgerParams.path string The ledger path (optional, default 44'/1729'/0'/0')
    • ledgerParams.displayConfirm Boolean Whether to display a confirmation the ledger (optional, default false)
    • ledgerParams.curve Number The value which defines the curve (0x00=tz1, 0x01=tz2, 0x02=tz3) (optional, default 0x00)

Examples

ledger.getAddress({
  path = "44'/1729'/0'/0'",
  displayConfirm = true,
  curve = 0x00,
}).then(({ address, publicKey }) => console.log(address, publicKey))

Returns Promise The public key and public key hash

signOperation

Sign an operation with the ledger

Parameters

  • ledgerParams Object The parameters of the signOperation function
    • ledgerParams.path string The ledger path (optional, default 44'/1729'/0'/0')
    • ledgerParams.rawTxHex Boolean The transaction hex for the ledger to sign
    • ledgerParams.curve Number The value which defines the curve (0x00=tz1, 0x01=tz2, 0x02=tz3) (optional, default 0x00)

Examples

ledger.signOperation({
  path = "44'/1729'/0'/0'",
  rawTxHex,
  curve = 0x00,
}).then((signature) => console.log(signature))

Returns Promise The signed operation

getVersion

Show the version of the ledger

Examples

ledger.getVersion()
  .then(({ major, minor, patch, bakingApp }) => console.log(major, minor, patch, bakingApp))

Returns Promise The version info

Key

Creates a key object from a base58 encoded key.

Parameters

  • key String A public or secret key in base58 encoding, or a 15 word bip39 english mnemonic string
  • passphrase String The passphrase used if the key provided is an encrypted private key or a fundraiser key
  • email String Email used if a fundraiser key is passed

Examples

const key = new Key('edskRv6ZnkLQMVustbYHFPNsABu1Js6pEEWyMUFJQTqEZjVCU2WHh8ckcc7YA4uBzPiJjZCsv3pC1NDdV99AnyLzPjSip4uC3y');
await key.ready;

publicKey

Returns the public key

Returns String The public key associated with the private key

secretKey

Returns the secret key

Returns String The secret key associated with this key, if available

publicKeyHash

Returns public key hash for this key

Returns String The public key hash for this key

sign

Sign a raw sequence of bytes

Parameters

  • bytes String Sequence of bytes, raw format or hexadecimal notation
  • watermark Uint8Array The watermark bytes

Returns String The public key hash for this key

verify

Verify signature, throw error if it is not valid

Parameters

  • bytes String Sequance of bytes, raw format or hexadecimal notation
  • signature Uint8Array A signature in base58 encoding
Clone this wiki locally