Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add custom network? #59

Open
zydjohnHotmail opened this issue Feb 27, 2023 · 11 comments
Open

How to add custom network? #59

zydjohnHotmail opened this issue Feb 27, 2023 · 11 comments

Comments

@zydjohnHotmail
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
No.
Describe the solution you'd like
A clear and concise description of what you want to happen.
I want to know how to write some blocks to custom network/chain.
What information is necessary?
Does it work like MetaMask wallet, to add a custom network, it is necessary to get the Chain ID/Network ID, RPC URL, Native token, etc.
What if some custom chain, its chain ID is not easy to find?

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
No other ideas.

Additional context
Add any other context or screenshots about the feature request here.

@nguyenphuminh
Copy link
Owner

nguyenphuminh commented Feb 28, 2023

Does it work like MetaMask wallet, to add a custom network, it is necessary to get the Chain ID/Network ID, RPC URL, Native token, etc.

Yeah to interact with the chain currently you just need the RPC URL.

What if some custom chain, its chain ID is not easy to find?

Chain ID is a constant, it is just a random number that resembles a chain really, it is easy to have something like that, but currently JeChain does not have such property.

Right now you can still make a custom chain out of it by just simply not syncing from other nodes and start mining your own chain from genesis. That's also the default setting, currently there is not an "official" JeChain "network" yet, you would start your own. You can also change the genesis block which includes the original coin mint and stuff too, it's in ./src/core/genesis.js.

The only problem with running a custom chain without chain id is that a different chain that's also powered by the JeChain specs/client can take transactions from your chain and submit it into their chain because there is no chain id difference. But if you don't use or don't care about the other chain you are fine.

Thanks for the suggestion!

@zydjohnHotmail
Copy link
Author

Hello:
Thank you very much for your reply.
I have a real world example to work on: https://explorer.btcbam.com/
This is a blockchain explorer, which I can’t find any useful information, I can’t get its Chain ID, and also no idea what is the RPC URL.
Using Chrome developer tools, I can see something, but mostly not very helpful.
The only thing always popup is: this error:
WebSocket connection to 'wss://localhost:7001/socket.io/?EIO=3&transport=websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
As my experience with blockchain explorer is rather limited.
Can you take a look and let me know what I can do?
Basically, my job is to re-build the this blockchain explorer with JeChain, so I can see the RPC URL and better if I can get Chain ID.
From one post I see that if you can get the genesis block of the blockchain, then you can get its Chain ID. But for this explorer, how can I get its genesis block (the first block of the blockchain), in order to get its Chain ID?
Please advise,
Thanks,

@nguyenphuminh
Copy link
Owner

nguyenphuminh commented Feb 28, 2023

The only thing always popup is: this error:

It is like that because the site does not provide an RPC URL for the chain, if you want a Bitcoin RPC URL try googling for node providers or run your own node through sth like Bitcoin Core (which is not hard, just download and run).

Basically, my job is to re-build the this blockchain explorer with JeChain, so I can see the RPC URL and better if I can get Chain ID.

You set your own RPC URL in ./config.json, you don't need an explorer for that, and like I said JeChain does not have a chain id property currently, so you can't get JeChain's chain id because it does not exist. But in EVM based chains (which is probably what you are talking about here), chain ids are simply just numbers that the developer define in their configuration so that their transactions don't conflict with other EVM based chains, you should be able to get chain id in a transaction object.

@zydjohnHotmail
Copy link
Author

Hello:
Thanks again for your quick response. However, my experience with blockchain explorer is limited.
For the example explorer(https://explorer.btcbam.com/), I can use Bitcoin core javascript. But tell me how I can get the first block of its blockchain? They are not exactly same, even the difference is not very big.
If I get the first block, then I can run some JeChain code to mine the other blocks until the latest block appeared in the explorer?
Thanks,

@nguyenphuminh
Copy link
Owner

You can easily get blocks using JeChain's JSON-RPC: https://github.com/nguyenphuminh/JeChain/blob/main/JSON-RPC.md (the get_blockByNumber method). First block has block num of 1 so just request block with block num of 1.

@zydjohnHotmail
Copy link
Author

Hello:
I really need detailed instructions on this issue now.
As the repo did NOT have enough examples, so I find some similar example from internet. I think using curl command is easy to understand.
Here is what I can think for what you have said:
curl RPC_URL -X POST -H "Content-Type: application/json" --data '{"method":"eth_getBlockByNumber","params":["1",false],"id":1,"jsonrpc":"2.0"}'

I am facing 2 issues now.
According to your suggestion: “It is like that because the site does not provide an RPC URL for the chain.”
Then if I use other’s RPC URL, like Bitcoin, then the first block is not what I want, right? I want to get the first block from btcbam blockchain, so I can clone or synchronize the whole blockchain from it, not a new blockchain, which has no relation with btcbam blockchain.
Another issue is: in which environment I should run your RPC JavaScript?
From Chrome developer tools or from Windows command line?
Please provide more details on this issue.
Thank you very much!

@zydjohnHotmail
Copy link
Author

Hello:
Actually, I found npm package for BTCBAM RPC:
D:\nodejs\TestJS>npm install btcbamcoind-rpc

added 1 package, and audited 2 packages in 1s

found 0 vulnerabilities

D:\nodejs\TestJS>type package.json
{
"dependencies": {
"btcbamcoind-rpc": "^0.0.1"
}
}
D:\nodejs\TestJS>
The package seems not big, but too difficult for me to understand. Can you take a look and figure out what is the RPC URL from this npm package?
Thanks,

@nguyenphuminh
Copy link
Owner

As the repo did NOT have enough examples, so I find some similar example from internet. I think using curl command is easy to understand.

That's Ethereum, not JeChain, please read the specs.

Another issue is: in which environment I should run your RPC JavaScript?

You can do whatever you want, curl, axios in js, chrome dev tools, thunder client, any tool to test, etc, it's just http apis.

Then if I use other’s RPC URL, like Bitcoin, then the first block is not what I want, right? I want to get the first block from btcbam blockchain, so I can clone or synchronize the whole blockchain from it, not a new blockchain, which has no relation with btcbam blockchain.

I think I'm missing something here, what is btcbam?

@zydjohnHotmail
Copy link
Author

Hi,
explorer(https://explorer.btcbam.com/), btcbam is the blockchain name also the native token name. The most important issue is how to find the RPC_URL, from the npm package, I can see the following:
var client = new RpcClient({
user: 'user',
pass: 'pass',
host: 'localhost',
port: 8332,
rejectUnauthorized: true,
disableAgent: true
});
Then it seems the RPC is on localhost, but I don't have any RPC server running.
How to figure out this, please advise,
Thanks,

@zydjohnHotmail
Copy link
Author

Hello:
I found more info for this btcbam blockchain, the following is the output from its core cli:
getblockchaininfo
{
"chain": "main",
"blocks": 0,
"headers": 0,
"bestblockhash": "001dc4c7cfc31ec2f30ecf9573c4418cd89122ed6d51dfe20fd82e6b74719c26",
"difficulty": 2.384149979653205e-007,
"moneysupply": 0,
"mediantime": 1626363636,
"verificationprogress": 1,
"initialblockdownload": true,
"chainwork": "0000000000000000000000000000000000000000000000000000000000000400",
"size_on_disk": 402,
"pruned": false,
"softforks": {
"bip34": {
"type": "buried",
"active": true,
"height": 1
},
"bip66": {
"type": "buried",
"active": true,
"height": 0
},
"bip65": {
"type": "buried",
"active": true,
"height": 0
},
"csv": {
"type": "buried",
"active": true,
"height": 1
},
"segwit": {
"type": "buried",
"active": true,
"height": 1
}
},
"warnings": ""
}
The following is the corresponding output for BitcoinCoin CLI: (I have a full node with prune enabled for Bitcoin blockchain in my PC)

{
"chain": "main",
"blocks": 778794,
"headers": 778828,
"bestblockhash": "00000000000000000000d68337b93a392557dea98d514ded23f23cf12ee4512c",
"difficulty": 43053844193928.45,
"mediantime": 1677668125,
"verificationprogress": 0.9999520121271832,
"initialblockdownload": false,
"chainwork": "0000000000000000000000000000000000000000416d0b7ad4f1bb236e253984",
"size_on_disk": 1887961257,
"pruned": true,
"pruneheight": 777917,
"automatic_pruning": true,
"prune_target_size": 1999634432,
...
}

I want to know that the data:
"chainwork": "0000000000000000000000000000000000000000000000000000000000000400",
Does it mean the network or chain ID for btcbam blockchain.
While at the same time, for Bitcoin, the data is:
"chainwork": "0000000000000000000000000000000000000000416d0b7ad4f1bb236e253984",
What does it mean for Bitcoin?
There are also the command: getrpcinfo:
{
"active_commands": [
{
"method": "getrpcinfo",
"duration": 0
}
],
"logpath": "F:\BitcoinCore\debug.log"
}

For both Bitcoin and btcbam, the output is almost the same, only the difference is the logpath.
But from this information, I can’t figure out what the RPC URL is?
Can you get some useful information for RPC URL for either Bitcoin or btcbam?
Thanks,

@garfearme
Copy link

Ok I pay supposedly Coinbase support to find my funds that are stuck in the block chain so they take my money and send me .375 bitcoin as a custom token which is not showing and I can't touch it and now it's gone, so what do I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants