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

Removes web3 dependency. Using ethersjs in the html tools. Refactors. #85

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 38 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Welcome to the precompiled ABIs from Rootstock

Here you will find the ABIs for the existing precompiled contracts in Rootstock. You will also get their addresses and a builder to use it with [web3js](https://www.npmjs.com/package/web3).
Here you will find the ABIs for the existing precompiled contracts in Rootstock. You will also get their addresses.

# Version

Expand All @@ -24,34 +24,55 @@ For the installation of these package you must execute in a terminal window:
npm install @rsksmart/rsk-precompiled-abis@<version>
```

As an example to define and use it:
## With Ethers

1) Include the Web3 package.
```js

```javascript
const Web3 = require('web3');
```
const ethers = require('ethers');
const precompiledAbi = require('@rsksmart/rsk-precompiled-abis');
julia-zack marked this conversation as resolved.
Show resolved Hide resolved
const networkUrl = 'https://public-node.rsk.co/';

const provider = new ethers.JsonRpcProvider(networkUrl);
const bridge = new ethers.Contract(precompiledAbi.bridge.address, precompiledAbi.bridge.abi, provider);

2) Include the `rsk-precompiled-abis` package.
bridge.getBtcBlockchainBestChainHeight().then(console.log);

```javascript
const precompiled = require('@rsksmart/rsk-precompiled-abis');
```

3) Create an instance of the contract using package build method and Web3 as a parameter.
That would print something like: `881524n`.

(i.e.: using Bridge)
## With Viem

```shell
var bridge = precompiled.bridge.build(new Web3('http://localhost:4444'));
```
```js
const { createPublicClient, http } = require("viem");
const { mainnet } = require("viem/chains");
const precompiledAbi = require('@rsksmart/rsk-precompiled-abis');
const networkUrl = 'https://public-node.rsk.co/';
julia-zack marked this conversation as resolved.
Show resolved Hide resolved

4) Use a contract's method. For example, here we call `getFederationAddress`, and displays its result in the console.
const client = createPublicClient({
chain: mainnet,
transport: http(networkUrl),
});

const getBlockchainHeight = async () => {
try {
const height = await client.readContract({
address: precompiledAbi.bridge.address,
abi: precompiledAbi.bridge.abi,
functionName: "getBtcBlockchainBestChainHeight",
});
console.log("btcBlockchainBestChainHeight:", height);
} catch (error) {
console.error("Error getting btcBlockchainBestChainHeight:", error);
}
};

getBlockchainHeight();

```shell
bridge.methods.getFederationAddress().call().then(console.log);
```

That would print something like: `881524n`.

# Important note

If the version to be installed is not defined in the command line, it will install the latest version by default.
Expand Down
1 change: 0 additions & 1 deletion bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ const ADDRESS = '0x0000000000000000000000000000000001000006';
module.exports = {
abi: abi,
address: ADDRESS,
build: (client) => new client.eth.Contract(abi, ADDRESS)
};
1 change: 0 additions & 1 deletion hdWalletUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ const ADDRESS = '0x0000000000000000000000000000000001000009';
module.exports = {
abi: abi,
address: ADDRESS,
build: (client) => new client.eth.Contract(abi, ADDRESS)
};
Loading
Loading