zeta-chain / toolkit Goto Github PK
View Code? Open in Web Editor NEWA library of ZetaChain helper utilities, contracts, and Hardhat tasks for smart-contract development
License: MIT License
A library of ZetaChain helper utilities, contracts, and Hardhat tasks for smart-contract development
License: MIT License
Right now we depend on a specific version: 5.4.7. Would be great to start using the latest one.
Add a configurable timeout (should be possible to disable the timeout). After X number of tries it exists with code 1. Could be useful for CI.
npx hardhat interact --contract 0xe6663Ea61512630438ADC89dB7fD9aE5Ccb28D7B --network mumbai_testnet --destination 5 --tokenId 2 --amount 1
.5 --to 0x2cD3D070aE1BD365909dD859d29F387AA96911e1
Error HH310: Invalid param --tokenId. Command line params must be lowercase.
Bug (hardhat console
):
Expected behavior (just node
):
When I'm trying to type anything in the prompt field it corrupts the text.
I tried several different consoles:
I also tried to reinstall the node_modules.
Windows 10 19044.3086, hardhat 2.17.1, toolbox 1.0.8-athens3
Sometimes RPCs go down, so it would be useful to be able to set a different one.
One possible solution is just with a flag:
npx hardhat cctx ... --node https://example.org:443
Also, ensure it can verify all example contracts.
This is relevant for CCM, because some transactions may fail when a smart contract is called on a source chain. Right now CCTX tracking will keep tracking the TX even though an inbound might have failed.
npx hardhat messaging Message message:string --fees native
npx hardhat compile --force
npx hardhat deploy --networks goerli_testnet,bsc_testnet
BSC: https://testnet.bscscan.com/address/0x91d800CD2a88cF7E453FfDd29A8E1194BC59AA1f
Goerli: https://goerli.etherscan.io/address/0xa8c98d5B5f20875F42d784485B327CDf8bb3051B
When I'm trying to send a message from BSC to Goerli it fails:
npx hardhat interact --contract 0x91d800CD2a88cF7E453FfDd29A8E1194BC59AA1f --amount 0.1 --network bsc_testnet --destination goerli_testnet --message hello
โ https://testnet.bscscan.com/tx/0x26339a2852ce8c978592fee23565e7ae7ed620725a1bef1ab847b67ca3fdbf0a
When I'm sending from Goerli to BSC using the same contract, it's fine:
npx hardhat interact --contract 0xa8c98d5B5f20875F42d784485B327CDf8bb3051B --amount 0.1 --network goerli_testnet --destination bsc_testnet --message hello
โ https://goerli.etherscan.io/tx/0xb2930e88cc0cf58d61597e8abd41e62c3f614bbab8c750b61c57397ffc0c7390
The same simple CCM contract with ZETA as fees works just fine both ways.
npx hardhat messaging Message message:string --fees zeta
https://testnet.bscscan.com/address/0x5C1d498E4200402CAAe9c6BFF4e3891A19686599
WebSocket is not reliable. The connection gets closed all the time, which makes the dev experience worse. It's also not possible to use CCTX tracking in scripts, because the script fails before getting all the info about a tx.
One solution is to make WSS reconnecting, but it's additional overhead. There is no reason to use WSS for this, polling should work just fine.
Either modify the interact
task or introduce a new one that will allow calling the contract from Bitcoin.
This will require making sure that the logic behind send-btc
can be called programmatically from the template.
Lines 101 to 144 in d7b6c52
The toolkit currently features 3 token transfer commands:
send-btc
send-zeta
send-zrc20
We need make the output of these commands consistent and add a confirmation.
? Send 0.001 tBTC to tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur? (Y/n)
? Send 2 ZETA from zeta_testnet to 0x4257d7F29FD5a4f9c5b8E6F0e3e8EA0A241a1D00 on goerli_testnet? (Y/n)
? Send 0.1 gETH from goerli_testnet to 0x4257d7F29FD5a4f9c5b8E6F0e3e8EA0A241a1D00 on zeta_testnet? (Y/n)
We need to ensure that most of the tools in the toolkit are working properly. To do this we can set up a Github action that runs commands and checks the output. For templating, for example, we need to run the template gen code, compile, deploy, interact with the contract and check that the changes have propagated to the destination successfully.
WIP: #36
later, it would be cool if we have a tool to help you construct the memo for btc (cli tool like this, or a helper function)!
An unexpected error occurred:
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
at new NodeError (node:internal/errors:399:5)
at Function.from (node:buffer:335:9)
at SimpleTaskDefinition.main [as action] (/Users/fadeev/template/node_modules/@zetachain/toolkit/dist/tasks/sendBTC.js:114:46)
at Environment._runTaskDefinition (/Users/fadeev/template/node_modules/hardhat/src/internal/core/runtime-environment.ts:333:35)
at Environment.run (/Users/fadeev/template/node_modules/hardhat/src/internal/core/runtime-environment.ts:166:25)
at main (/Users/fadeev/template/node_modules/hardhat/src/internal/cli/cli.ts:280:17) {
code: 'ERR_INVALID_ARG_TYPE'
}
Happens when you don't have a private key in .env (or an env variable).
Keep publicly available functions in "helpers" and internal functions in "lib".
Right now trackCCTX
depends on a Node.js package for spinners.
https://github.com/zeta-chain/toolkit/blob/cd1637d3f01d9c774edaf6c1b17c5c8535ee9b9a/helpers/tx.ts
Would be great to remove all Node.js logic from this function to be able to use it on the frontend. I imagine we could emit events from trackCCTX
and catch them in a wrapper function that depends on spinners. So, trackCCTX
will just emit events and return JSON and will be frontend-compatible, and the wrapper function will be Node.js-dependent and will show spinners in the terminal.
Right now there are dependencies on Node.js libs, which makes it impossible to do imports:
// this doesn't work from a browser
import { prepareData } from "@zetachain/toolkit/helpers";
One simple temporary solution would be to add the following to package.json
:
"exports": {
"./helpers/evm": "./dist/helpers/evm.js"
},
Ideally, nothing in helpers/
should depend on Node.js. We can move all these things under lib/
.
When following the tutorial:
https://www.zetachain.com/docs/developers/omnichain/tutorials/withdraw/#set-up-your-environment
The command
npx hardhat omnichain Withdraw recipient
will erase the file content to be written if they already exist.
It might eventually be a concern since there are many sections of the tutorial that write into deploy.ts
and the command erase deploy.ts
content.
My suggestion would be to add a verification for the command to ask for confirmation.
npx hardhat omnichain Withdraw recipient
deploy.ts already exist, do you want to continue and overwrite the file?
npx hardhat omni foo
(with no fields specified) should generate a contract that can be compiled and deployed.
The toolkit ships with a number of helper functions that are useful for ZetaChain dapp devs. For example, getBalances
, which fetches balances of all supported tokens from all connected chains. This is very straightforward and config-free when using public endpoints, but for production we recommend using dedicated RPC endpoints, such as the ones provided by BlockPi or Ankr.
The question is, what's the most dev-friendly way of making functions like getBalances
configurable to use custom endpoints?
One option, is to have a "Client" class that you can instantiate with custom endpoints.
class Client {
private rpcEndpoints: RpcEndpoints;
constructor(customRpcEndpoints?: RpcEndpoints) {
const defaultRpcEndpoints: RpcEndpoints = {
blockchainA: 'https://public-node.blockchainA.com',
blockchainB: 'https://public-node.blockchainB.com',
// ... other blockchains
};
// Merge user RPC endpoints with default ones, prioritizing user's custom endpoints
this.rpcEndpoints = { ...defaultRpcEndpoints, ...customRpcEndpoints };
}
async getBalances(): Promise<any[]> {
// Logic to fetch balances from each blockchain using this.rpcEndpoints
return balances;
}
//...
}
Second option is to make getBalances
accept an optional argument with endpoints.
async function getBalances(userRpcEndpoints?: RpcEndpoints): Promise<any[]> {
//...
return balances;
}
In both scenarios API keys will be passed alongside endpoints most likely stored in env variables.
I think the second option is a bit more lightweight and since helper functions most likely will not require shared state, the class approach seems like an overkill.
Any better approaches?
npx hardhat send-btc --amount 0.001 --memo 629eEe97B95Bd6e04B0885De58eF016177a709Ae2cD3D070aE1BD365909dD859d29F387AA96911e1 --recipient tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur
An unexpected error occurred:
ReferenceError: fetch is not defined
Use the helper in fees
to get CCM fees. Fees are charged when the destination chain is a connected chain (and not ZetaChain).
CCM contracts should be deployed only to connected chains, not zeta_testnet.
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.