teztech / eztz Goto Github PK
View Code? Open in Web Editor NEWTezos JS Library
License: MIT License
Tezos JS Library
License: MIT License
Hi, is there some possibility to use this library in node.js desktop app (electron) with npm or as an external library ? Thank you very much
The eztz.contract.send method successfully performs transactions, but when trying to make several consecutive transactions, the following error occurs:
Error: Counter XXX already used for contract tz------------XXX (expected YYYY)
The counter lags behind the required value by 1-2
HI,
I am running zeronet tezos node and below command works fine with curl.**
{"hash":"BKiY3ohPNvLVG5pcx7MY4viWfoV7dF4xD9hzAoeRNc7TvveZZhN"}
Now I made this html file using eztz library.
( I modified defaultProvider = "http://localhost:8732" in main.js and npm run-script build. And I used eztz.min.js that built newly)
<!DOCTYPE html>
<html>
<head>
<script src="./eztz.min.js"></script>
</head>
<body>
<script>
eztz.node.query("/blocks/head/hash").then(function(res){
console.log(res);
}).catch(function(e){});
</script>
</body>
</html>
But it gives an error.
(anonymous) @ eztz.min.js:8
query @ eztz.min.js:8
(anonymous) @ 4.html:9
4.html:1 Failed to load http://localhost:8732/blocks/head/hash: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 415.
415 error is related to content-type or something. I am not sure.
Is there something wrong or missed something?
Is it possible to add metadata to a transaction? We are running a baker and would like to track our payouts with an ID.
Thanks.
Status of the NPM module?
I think the package.json is missing some fields and XMLHttpRequest
needs to be polyfilled with xhr2
I get weird syntax errors when I try to do eztz.contract.originate
:
Failed to parse the request body: No case matched:
At /kind, unexpected string instead of endorsement
At /kind, unexpected string instead of seed_nonce_revelation
At /kind, unexpected string instead of double_endorsement_evidence
At /kind, unexpected string instead of double_baking_evidence
At /kind, unexpected string instead of activate_account
At /kind, unexpected string instead of proposals
At /kind, unexpected string instead of ballot
At /kind, unexpected string instead of reveal
At /kind, unexpected string instead of transaction
At /script/code, no case matched:
Unexpected array instead of object
Unexpected array instead of object
Unexpected array instead of object
At [2], no case matched:
Missing object field int
Missing object field string
Missing object field bytes
Unexpected object instead of array
At /args[0], no case matched:
Unexpected array instead of object
Unexpected array instead of object
Unexpected array instead of object
At [3], no case matched:
Missing object field int
Missing object field string
Missing object field bytes
Unexpected object instead of array
At /prim, unexpected string value "DUUP" instead of "ADD" , "LE" , "UNIT" , "timestamp" , "signature" , "COMPARE" , "LAMBDA" , "LOOP" , "Elt" , "IMPLICIT_ACCOUNT" , "NONE" , "set" , "pair" , "bytes" , "BLAKE2B" , "address" , "SHA256" , "XOR" , "RENAME" , "MAP" , "SET_DELEGATE" , "DIP" , "PACK" , "or" , "SIZE" , "Right" , "list" , "IF_CONS" , "LSR" , "TRANSFER_TOKENS" , "storage" , "UPDATE" , "CDR" , "SWAP" , "SOME" , "False" , "SHA512" , "CHECK_SIGNATURE" , "BALANCE" , "key_hash" , "unit" , "EMPTY_SET" , "SUB" , "MEM" , "RIGHT" , "ADDRESS" , "option" , "CONCAT" , "big_map" , "string" , "Unit" , "Some" , "UNPACK" , "NOT" , "LEFT" , "mutez" , "AMOUNT" , "DROP" , "ABS" , "bool" , "GE" , "PUSH" , "LT" , "operation" , "NEQ" , "NEG" , "None" , "CONS" , "EXEC" , "NIL" , "ISNAT" , "MUL" , "LOOP_LEFT" , "EDIV" , "SLICE" , "STEPS_TO_QUOTA" , "INT" , "SOURCE" , "CAR" , "CREATE_ACCOUNT" , "LSL" , "OR" , "IF_NONE" , "SELF" , "IF" , "Left" , "contract" , "map" , "SENDER" , "nat" , "DUP" , "EQ" , "NOW" , "key" , "GET" , "lambda" , "int" , "True" , "GT" , "parameter" , "IF_LEFT" , "FAILWITH" , "PAIR" , "ITER" , "Pair" , "CAST" , "EMPTY_MAP" , "CREATE_CONTRACT" , "HASH_KEY" , "CONTRACT" , "code" or "AND"
Unexpected array instead of object
Unexpected array instead of object
At /kind, unexpected string instead of delegation
Failed to parse the request body: No case matched:
At /kind, unexpected string instead of endorsement
At /kind, unexpected string instead of seed_nonce_revelation
At /kind, unexpected string instead of double_endorsement_evidence
At /kind, unexpected string instead of double_baking_evidence
At /kind, unexpected string instead of activate_account
At /kind, unexpected string instead of proposals
At /kind, unexpected string instead of ballot
At /kind, unexpected string instead of reveal
At /kind, unexpected string instead of transaction
At /script/code, no case matched:
Unexpected array instead of object
Unexpected array instead of object
Unexpected array instead of object
At [2], no case matched:
Missing object field int
Missing object field string
Missing object field bytes
Unexpected object instead of array
At /args[0], no case matched:
Unexpected array instead of object
Unexpected array instead of object
Unexpected array instead of object
At [3], no case matched:
Missing object field int
Missing object field string
Missing object field bytes
Unexpected object instead of array
At /prim, unexpected string value "DUUP" instead of "ADD" , "LE" , "UNIT" , "timestamp" , "signature" , "COMPARE" , "LAMBDA" , "LOOP" , "Elt" , "IMPLICIT_ACCOUNT" , "NONE" , "set" , "pair" , "bytes" , "BLAKE2B" , "address" , "SHA256" , "XOR" , "RENAME" , "MAP" , "SET_DELEGATE" , "DIP" , "PACK" , "or" , "SIZE" , "Right" , "list" , "IF_CONS" , "LSR" , "TRANSFER_TOKENS" , "storage" , "UPDATE" , "CDR" , "SWAP" , "SOME" , "False" , "SHA512" , "CHECK_SIGNATURE" , "BALANCE" , "key_hash" , "unit" , "EMPTY_SET" , "SUB" , "MEM" , "RIGHT" , "ADDRESS" , "option" , "CONCAT" , "big_map" , "string" , "Unit" , "Some" , "UNPACK" , "NOT" , "LEFT" , "mutez" , "AMOUNT" , "DROP" , "ABS" , "bool" , "GE" , "PUSH" , "LT" , "operation" , "NEQ" , "NEG" , "None" , "CONS" , "EXEC" , "NIL" , "ISNAT" , "MUL" , "LOOP_LEFT" , "EDIV" , "SLICE" , "STEPS_TO_QUOTA" , "INT" , "SOURCE" , "CAR" , "CREATE_ACCOUNT" , "LSL" , "OR" , "IF_NONE" , "SELF" , "IF" , "Left" , "contract" , "map" , "SENDER" , "nat" , "DUP" , "EQ" , "NOW" , "key" , "GET" , "lambda" , "int" , "True" , "GT" , "parameter" , "IF_LEFT" , "FAILWITH" , "PAIR" , "ITER" , "Pair" , "CAST" , "EMPTY_MAP" , "CREATE_CONTRACT" , "HASH_KEY" , "CONTRACT" , "code" or "AND"
Unexpected array instead of object
Unexpected array instead of object
At /kind, unexpected string instead of delegation
on the following Michelson:
parameter unit;
storage (pair string nat);
code { DUP ;
DIP { CDR } ;
CAR ;
DUUP @storage ;
DUP ;
CAR ;
SWAP ;
DROP ;
DIP { DROP } ;
PUSH nat 1 ;
DUUUP ;
DIIIP { DROP } ;
CDR ;
ADD ;
SWAP ;
PAIR @storage ;
NIL operation ;
PAIR };
The contract works if deployed directly from the tezos-client
.
Here is my code (I have a fork at @whaatt/eztz that adds some small things to make EZTZ work in Node, like require
-ing XMLHttpRequest
:
const fs = require('fs')
const init = fs.readFileSync('helloworld.liq.init.tz', 'utf8')
const code = fs.readFileSync('helloworld.liq.tz', 'utf8')
console.log(init)
console.log(code)
const eztz = require('eztz').eztz
eztz.node.setProvider('http://127.0.0.1:18731')
const sk = 'edsk3gUfUPyBSfrS9CCgmCiQsTCHGkviBDusMxDJstFtojtc1zcpsh'
const keys = eztz.crypto.extractKeys(sk);
eztz.contract.originate(keys, 2000, code, init, false, false, null, 500)
.then(console.log).catch(console.error)
Thanks!
Are there going to be changes made to this library for the Babylon proposal?
Expected Behavior
Show balance of tz account on alphanet
Current Behavior
Access to XMLHttpRequest at 'http://:8732/chains/main/blocks/head/context/contracts//balance' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Context (Environment)
I have set up a node on GCP, I am trying to connect to this node from a local machine via: eztz.node.setProvider("http://:8732");
Are there plans to add a request that would return all transactions from a given address?
Hi, was just browsing to find the b58 encoding tz1/2 prefixes, when I found this. Is this a typo?
Lines 13 to 14 in cfdc4fc
@stephenandrews what do you thing about moving lib to TypeScript (or some functional lang)?
TypeScript or some functional static lang will ensure correctness and will leave less space for bugs.
Expected Behavior
Current Behavior
Possible Solution
Steps to Reproduce
Context (Environment)
Detailed Description
Possible Implementation
Is it possible to add support for tz1
elliptic ed25519
keys?
Wrong string comparison on line 363 of file main.js, function sendOperation
Expected Behavior
!= 'undefined'
Current Behavior
!= 'unfedined'
I am tring to sign a transaction by Library, but I don't know how can I using the function sign
:
sign: function (bytes, sk, wm) {
var bb = utility.hex2buf(bytes);
if (typeof wm != 'undefined') bb = utility.mergebuf(wm, bb);
const sig = library.sodium.crypto_sign_detached(library.sodium.crypto_generichash(32, bb), utility.b58cdecode(sk, prefix.edsk), 'uint8array');
const edsig = utility.b58cencode(sig, prefix.edsig);
const sbytes = bytes + utility.buf2hex(sig);
return {
bytes: bytes,
sig: sig,
edsig: edsig,
sbytes: sbytes,
}
}
What is vm
?
The Ledger module is looking pretty good. Will you share the uncompiled version?
Why isn't the module published on npm? @stephenandrews
Can be useful to have a method to get the address
from publicKey
:
function getAddress(publicKey) {
const hash = sodium.crypto_generichash(20, publicKey);
const pkh = Utility.b58cencode(hash, Prefix.tz1)
return pkh
}
and something else for longer privateKey
I'm trying to originate a contract but I get "Failed to parse the request body".
the code is : parameter unit;
storage (list string);
code { CDR ; NIL operation ; PAIR };
and the init : { "hello" }
Please help!
Any expected work on supporting voting?
This isn't an issue - I'm looking for clarification. In main.js
there are two formatters for Tezos values and I am a bit confused.
In the utility
object, the two formatters are:
totez: m => parseInt(m) / 1000000,
mutez: function(tz) {
return new BN(new BN(tz).toFixed(6)).multipliedBy(1000000).toString();
},
I am sending successful transfers using eztz.rpc.transfer
- the values I supply for the transactions are floats like 4.1
or 0.1
. These are accurately outputting the correct amount of xtz taking place in the transfer (taking place through a Ledger integration on my front-end).
I am confused because although it works and the values match up (4.1xtz), it seems in this case that neither totez
or mutez
formatters are being used. Any ideas on what I'm missing here?
generateKeysNoSeed should either be included in eztz.min.js or its documentation should state that it's a CLI only function.
I'm having this error:
Failed to parse the request body: No case matched:
At /kind, unexpected string instead of endorsement
At /kind, unexpected string instead of seed_nonce_revelation
At /kind, unexpected string instead of double_endorsement_evidence
At /kind, unexpected string instead of double_baking_evidence
At /kind, unexpected string instead of activate_account
At /kind, unexpected string instead of proposals
At /kind, unexpected string instead of ballot
At /kind, unexpected string instead of reveal
Unhandled error (Invalid_argument "Z.of_substring_base: invalid digit")
At /kind, unexpected string instead of origination
At /kind, unexpected string instead of delegation
Trying to call a contract method:
function main(const action: entry_action; var finance_storage: finance_storage): (list(operation) * finance_storage) is
block {
skip
} with case action of
| Deposit(param) -> depositImp(finance_storage)
| Withdraw(param) -> withdrawImp(finance_storage)
end;
compiled code
parameter (or (unit %deposit) (unit %withdraw)) ;
I'm making the call like so:
const v3FullPoolAddress = "KT1EufKiVMbL6r4T2whQT88crUZJM7J3SW66";
const bobKeys = {
pk: "edpktvrjBvRB7zJGEQKBFpwGS2rb12VD4ibTv7Kqgv9yAi6ARW3vQy",
sk: "edsk3k86EP8oqGfgpmVq5XPpjwJTb3ivmDUpZw12j13dvnqnU3PCnM",
phk: "tz1P4iVZLrBEjqNKUDBe7bqV8CB2AQ51ZKf8"
};
eztz.contract
.send(v3FullPoolAddress, bobKeys.phk, bobKeys, 100, "(Left Unit)", 0.5)
.then(res => {
console.log(`Deposit Call from bob ${JSON.stringify(res)}`);
})
.catch(console.log);
calling the contract using tezos-client
works fine, any idea what can I be doing wrong?
Hi,
On using the defaultProvider in eztz.cli.js i.e.tezrpc.me/zeronet, it returns Empty Response as the result to any query command (I've checked it for rpc.getHead()). Kindly suggest a fix for this or suggest some other public rpc node available for Tezos Zeronet. Thanks in advance!
https://rpc.tezrpc.me returns 404
Hi Stephen,
First - this is a remarkable library BTW - great work!
I'm trying to adapt the code to work on betanet and I'm having some limited success creating a transaction...
I have substituted in the betanet protocol "PsYLVpVvgbLhAhoqAkMFUo6gudkJ9weNXhUYCiLDzcUpFpkk8Wt" and so far the process works through forge/operations, preapply/operations but when I send the signed bytes string to injection/operations I'm getting a 400 response with:
"Failed to parse the request body: JSON.of_buffer illegal number\n(98f0b430dcaf1aafb516fe33383efe71b78c1bae410fc11582042c8c7524979207000007a781154e1ae1d0a9cc8ec0934711e7d6d905be0091fe020000002ee6ce422dc26471442bc3425f8f09dfa45fd61a018d13bcee26f4f1a4c61ca108000007a781154e1ae1d0a9cc8ec0934711e7d6d905bee80792fe02f4030098e23000003
f528b39dfa11f591a4b0016fb3e30fce5c63c6800015edcb709386f3f92909a7fc66c91ee83b82f8ea0f81daaa2dfa337b763075cd404a9bc27a7e5e83d27575837d8e39e1efb4f516e603b2cd5d738a4aadeac06)"
Do you know what this might be?
Kind Regards,
Guyon
Hi, this library works flawlessly for the mainnet, but here I'm trying to connect to the Alphanet of the Tezos network and trying to simulate all the standard transactions as on the mainnet. Can you please guide me as to how how I can use one of your rpc providers to query the Alphanet. I explored every directory of this library to connect to to Alphanet, but always received "Empty Response Returned" despite the http status code being 200.
Please provide the appropriate solution to this. Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.