-
Notifications
You must be signed in to change notification settings - Fork 21
Documentation
Main tez.js Library
-
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, default1278
) -
options.debugMode
Boolean Debug mode enablement (optional, defaultfalse
) -
options.localForge
Boolean Forge operations locally (optional, defaulttrue
) -
options.validateLocalForge
Boolean Validate local forge bytes against remote forged bytes (optional, defaultfalse
)
-
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',
});
Import a secret key
-
key
String The secret key -
passphrase
String? The passphrase of the encrypted key -
email
String? The email associated with the fundraiser account
await sotez.importKey('edskRv6ZnkLQMVustbYHFPNsABu1Js6pEEWyMUFJQTqEZjVCU2WHh8ckcc7YA4uBzPiJjZCsv3pC1NDdV99AnyLzPjSip4uC3y');
Import a ledger public key
-
path
String The ledger path (optional, default"44'/1729'/0'/0'"
) -
curve
Number The curve parameter (optional, default0x00
)
await sotez.importLedger();
Queries a node given a path and payload
-
path
String The RPC path to query -
payload
String The payload of the query -
method
String The request method. Either 'GET' or 'POST'
sotez.query(`/chains/main/blocks/head`)
.then(head => console.log(head));
Returns Promise The response of the query
Originate a new account
-
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, default1278
) -
paramObject.gasLimit
Number The gas limit to set for the transaction (optional, default10000
) -
paramObject.storageLimit
Number The storage limit to set for the transaction (optional, default257
)
-
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
Get the balance for a contract
-
address
String The contract for which to retrieve the balance
sotez.getBalance('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(balance => console.log(balance))
Returns Promise The balance of the contract
Get the delegate for a contract
-
address
String The contract for which to retrieve the delegate
sotez.getDelegate('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(delegate => console.log(delegate))
Returns Promise The delegate of a contract, if any
Get the manager for a contract
-
address
String The contract for which to retrieve the manager
sotez.getManager('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(({ manager, key }) => console.log(manager, key))
Returns Promise The manager of a contract
Get the counter for an contract
-
address
String The contract for which to retrieve the counter
sotez.getCounter('tz1fXdNLZ4jrkjtgJWMcfeNpFDK9mbCBsaV4')
.then(counter => console.log(counter))
Returns Promise The counter of a contract, if any
Get the baker information for an address
-
address
String The contract for which to retrieve the baker information
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
Get the header of the current head
sotez.getHeader().then(header => console.log(header))
Returns Promise The whole block header
Get the current head block of the chain
sotez.getHead().then(head => console.log(head))
Returns Promise The current head block
Get the current head block hash of the chain
sotez.getHeadHash().then(headHash => console.log(headHash))
Returns Promise The block's hash, its unique identifier
Ballots casted so far during a voting period
sotez.getBallotList().then(ballotList => console.log(ballotList))
Returns Promise Ballots casted so far during a voting period
List of proposals with number of supporters
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
Sum of ballots casted so far during a voting period
sotez.getBallots().then(({ yay, nay, pass }) => console.log(yay, nay, pass))
Returns Promise Sum of ballots casted so far during a voting period
List of delegates with their voting weight, in number of rolls
sotez.getListings().then(listings => console.log(listings))
Returns Promise The ballots of the current voting period
Current proposal under evaluation
sotez.getCurrentProposal().then(currentProposal => console.log(currentProposal))
Returns Promise Current proposal under evaluation
Current period kind
sotez.getCurrentPeriod().then(currentPeriod => console.log(currentPeriod))
Returns Promise Current period kind
Current expected quorum
sotez.getCurrentQuorum().then(currentQuorum => console.log(currentQuorum))
Returns Promise Current expected quorum
Check for the inclusion of an operation in new blocks
-
hash
String The operation hash to check -
interval
Number The interval to check new blocks (optional, default10
) -
timeout
Number The time before the operation times out (optional, default180
)
sotez.awaitOperation('ooYf5iK6EdTx3XfBusgDqS6znACTq5469D1zQSDFNrs5KdTuUGi')
.then((hash) => console.log(hash));
Returns Promise The hash of the block in which the operation was included
Get the current head block hash of the chain
Returns Promise The response of the rpc call
Prepares an operation
-
paramObject
Object The parameters for the operation
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
Simulate an operation
-
paramObject
Object The parameters for the operation
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
Send an operation
-
paramObject
Object The parameters for the operation
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 an operation
Returns Promise Object containing the injected operation hash
Inject an operation without prevalidation
-
sopbytes
String The signed operation bytes
Returns Promise Object containing the injected operation hash
Transfer operation
-
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, defaultfalse
) -
paramObject.fee
Number The fee to set for the transaction (optional, default1278
) -
paramObject.gasLimit
Number The gas limit to set for the transaction (optional, default10100
) -
paramObject.storageLimit
Number The storage limit to set for the transaction (optional, default0
) -
paramObject.mutez
Number Whether the input amount is set to mutez (1/1,000,000 tez) (optional, defaultfalse
) -
paramObject.rawParam
Number Whether to accept the object parameter format (optional, defaultfalse
)
-
sotez.transfer({
to: 'tz1RvhdZ5pcjD19vCCK9PgZpnmErTba3dsBs',
amount: '1000000',
fee: '1278',
}).then(result => console.log(result))
Returns Promise Object containing the injected operation hash
Activate an account
sotez.activate(pkh, secret)
.then((activateOperation) => console.log(activateOperation))
Returns Promise Object containing the injected operation hash
Originate a new contract
-
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, defaultfalse
) -
paramObject.delegatable
Boolean Whether the new account is delegatable (optional, defaultfalse
) -
paramObject.delegate
String? The delegate for the new account -
paramObject.fee
Number The fee to set for the transaction (optional, default1278
) -
paramObject.gasLimit
Number The gas limit to set for the transaction (optional, default10000
) -
paramObject.storageLimit
Number The storage limit to set for the transaction (optional, default257
)
-
Returns Promise Object containing the injected operation hash
Set a delegate for an account
-
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, default1278
) -
paramObject.gasLimit
Number The gas limit to set for the transaction (optional, default10000
) -
paramObject.storageLimit
Number The storage limit to set for the transaction (optional, default0
)
-
Returns Promise Object containing the injected operation hash
Register an account as a delegate
-
paramObject
Object The parameters for the operation
Returns Promise Object containing the injected operation hash
Typechecks the provided code
-
code
String The code to typecheck
Returns Promise Typecheck result
Serializes a piece of data to a binary representation
Returns Promise Serialized data
Typechecks data against a type
Returns Promise Typecheck result
Runs or traces code against an input and storage
-
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, defaultfalse
)
Returns Promise Run results
Extract key pairs from a secret key
-
sk
String The secret key to extract key pairs from -
password
String? The password used to encrypt the sk (optional, default''
)
crypto.extractKeys('edskRqAF8s2MKKqRMxq53CYYLMnrqvokMyrtmPRFd5H9osc4bFmqKBY119jiiqKQMti2frLAoKGgZSQN3Lc3ybf5sgPUy38e5A')
.then(({ sk, pk, pkh }) => console.log(sk, pk, pkh))
Returns Promise The extracted key pairs
Generate a mnemonic
Returns String The generated mnemonic
Check the validity of a tezos implicit address (tz1...)
-
address
String The address to check
Returns Boolean Whether address is valid or not
Generate a new key pair given a mnemonic and passphrase
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 bytes
-
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''
)
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 signed bytes
Returns Boolean Whether the signed bytes are valid
Convert from base58 to integer
-
v
String The b58 value
Returns String The converted b58 value
Convert from mutez to tez
-
mutez
Number The amount in mutez to convert to tez
Returns Number The mutez amount converted to tez
Convert from tez to mutez
-
tez
Number The amount in tez to convert to mutez
Returns String The tez amount converted to mutez
Base58 encode
-
payload
(String | Uint8Array) The value to encode -
prefixArg
Object The Uint8Array prefix values
Returns String The base58 encoded value
Base58 decode
Returns String The decoded base58 value
Buffer to hex
-
buffer
Object The buffer to convert to hex
Returns String Converted hex value
Hex to Buffer
-
hex
String The hex to convert to buffer
Returns Object Converted buffer value
Generate a hex nonce
-
length
Number The length of the nonce
Returns String The nonce of the given length
Merge two buffers together
Returns Object The merged buffer
Convert bytes from Int32
-
num
Number Number to convert to bytes
Returns Object The converted number
Convert hex from Int32
-
num
Number Number to convert to hex
Returns String The converted number
Forge boolean
-
bool
Boolean Boolean value to convert
Returns String The converted boolean
Forge script bytes
Returns String Forged script bytes
Forge parameter bytes
-
parameter
String Script to forge
Returns String Forged parameter bytes
Forge public key hash bytes
-
pkh
String Public key hash to forge
Returns String Forged public key hash bytes
Forge address bytes
-
address
String Address to forge
Returns String Forged address bytes
Forge zarith bytes
-
n
Number Zarith to forge
Returns String Forged zarith bytes
Forge public key bytes
-
pk
Number Public key to forge
Returns String Forged public key bytes
Forge operation bytes
-
op
Object Operation to forge
Returns String Forged operation bytes
Forge operation bytes
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
Decode raw bytes
-
bytes
String The bytes to decode
Returns Object Decoded raw bytes
Encode raw bytes
-
input
Object The value to encode
Returns String Encoded value as bytes
Get the public key and public key hash from the ledger
-
ledgerParams
Object The parameters of the getAddress function (optional, default{}
)
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
Sign an operation with the ledger
-
ledgerParams
Object The parameters of the signOperation function
ledger.signOperation({
path = "44'/1729'/0'/0'",
rawTxHex,
curve = 0x00,
}).then((signature) => console.log(signature))
Returns Promise The signed operation
Show the version of the ledger
ledger.getVersion()
.then(({ major, minor, patch, bakingApp }) => console.log(major, minor, patch, bakingApp))
Returns Promise The version info
Creates a key object from a base58 encoded key.
-
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
const key = new Key('edskRv6ZnkLQMVustbYHFPNsABu1Js6pEEWyMUFJQTqEZjVCU2WHh8ckcc7YA4uBzPiJjZCsv3pC1NDdV99AnyLzPjSip4uC3y');
await key.ready;
Returns the public key
Returns String The public key associated with the private key
Returns the secret key
Returns String The secret key associated with this key, if available
Returns public key hash for this key
Returns String The public key hash for this key
Sign a raw sequence of bytes
-
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 signature, throw error if it is not valid
-
bytes
String Sequance of bytes, raw format or hexadecimal notation -
signature
Uint8Array A signature in base58 encoding