Skip to content

Commit

Permalink
Removes web3 example. Refactors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-then committed Jan 30, 2025
1 parent eac5ac0 commit 6932803
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
38 changes: 8 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,30 @@ For the installation of these package you must execute in a terminal window:
npm install @rsksmart/rsk-precompiled-abis@<version>
```

## With Ethersjs
## With Ethers

```js

const ethers = require('ethers');
const precompiledAbi = require('@rsksmart/rsk-precompiled-abis');
const networkUrl = 'https://public-node.rsk.co/';

const BRIDGE_ADDRESS = '0x0000000000000000000000000000000001000006';
const networkUrl = 'https://public-node.testnet.rsk.co/';
const bridgeAbi = precompiledAbi.bridge.abi;
const provider = new ethers.JsonRpcProvider(networkUrl);
const bridge = new ethers.Contract(BRIDGE_ADDRESS, bridgeAbi, provider);
const bridge = new ethers.Contract(precompiledAbi.bridge.address, precompiledAbi.bridge.abi, provider);

bridge.getBtcBlockchainBestChainHeight().then(console.log);

```

That would print something like: `3633485n`.
That would print something like: `881524n`.

## With Viem

```js
const { createPublicClient, http } = require("viem");
const { mainnet } = require("viem/chains");
const precompiledAbi = require('@rsksmart/rsk-precompiled-abis');

const BRIDGE_ADDRESS = '0x0000000000000000000000000000000001000006';
const networkUrl = 'https://public-node.testnet.rsk.co/';
const bridgeAbi = precompiledAbi.bridge.abi;
const networkUrl = 'https://public-node.rsk.co/';

const client = createPublicClient({
chain: mainnet,
Expand All @@ -62,8 +57,8 @@ const client = createPublicClient({
const getBlockchainHeight = async () => {
try {
const height = await client.readContract({
address: BRIDGE_ADDRESS,
abi: bridgeAbi,
address: precompiledAbi.bridge.address,
abi: precompiledAbi.bridge.abi,
functionName: "getBtcBlockchainBestChainHeight",
});
console.log("btcBlockchainBestChainHeight:", height);
Expand All @@ -76,24 +71,7 @@ getBlockchainHeight();

```

That would print something like: `3633485n`.

## With Web3

```js

const Web3 = require('web3');
const precompiledAbi = require('@rsksmart/rsk-precompiled-abis');
const BRIDGE_ADDRESS = '0x0000000000000000000000000000000001000006';
const networkUrl = 'https://public-node.testnet.rsk.co/';
const bridgeAbi = precompiledAbi.bridge.abi;

const web3 = new Web3(networkUrl);
const bridge = new web3.eth.Contract(bridgeAbi, BRIDGE_ADDRESS);

bridge.methods.getBtcBlockchainBestChainHeight().call().then(console.log)

```
That would print something like: `881524n`.

# Important note

Expand Down
11 changes: 5 additions & 6 deletions tools/PrecompiledAbis.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ <h5 class='text-center'>Simple html page to get bridge methods selectors and eve
</div>
<div class="col-9">
<select id='abiForForkSelect' class='form-select form-select-sm' aria-label=''>
<option value='lovell'>Lovell</option>
<option selected value='arrowhead'>Arrowhead</option>
<option selected value='lovell'>Lovell</option>
<option value='arrowhead'>Arrowhead</option>
<option value='fingerroot'>Fingerroot</option>
<option value='hop'>Hop</option>
<option value='iris'>Iris</option>
Expand Down Expand Up @@ -267,12 +267,12 @@ <h5 class="modal-title" id="exampleModalLabel">Abi</h5>
];

let selectedAbis = null;
let selectedAbiForkInfo = abisForkInfoMap.arrowhead;
let selectedAbiForkInfo = abisForkInfoMap.lovell;

selectedAbisUrl.href = selectedAbiForkInfo.url;
selectedAbisUrl.textContent = selectedAbiForkInfo.url;

const testnetRskUrl = 'https://public-node.testnet.rsk.co/';
const testnetRskUrl = 'https://public-node.rsk.co/';

const defaultActionButtonOptions = {
name: 'Action Button',
Expand All @@ -291,7 +291,7 @@ <h5 class="modal-title" id="exampleModalLabel">Abi</h5>

if (!response.ok) {
if (response.status === 404) {
throw new Error(`ABI file not found at ${abiUrl} (404)`);
throw new Error(`ABI file for ${forkKey} not found. Consider selecting a different one. Check console for more info.`);
} else {
throw new Error(`Failed to fetch ABI. HTTP Status: ${response.status}`);
}
Expand Down Expand Up @@ -322,7 +322,6 @@ <h5 class="modal-title" id="exampleModalLabel">Abi</h5>

const getBridgeEventTopic = (eventAbi) => {
return ethers.keccak256(ethers.toUtf8Bytes(eventAbi.signature));
return '';
};

const getBridgeMethodSelector = (methodAbi) => {
Expand Down
2 changes: 1 addition & 1 deletion tools/RootstockBridge.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ <h5 class='text-center'>Simple html page to interact with the Rootstock (RSK) Bl
];

const bridgeAddress = '0x0000000000000000000000000000000001000006';
const testnetRskUrl = 'https://public-node.testnet.rsk.co/';
const testnetRskUrl = 'https://public-node.rsk.co/';
const mainnetRskUrl = 'https://public-node.rsk.co/';
let currentUrl = mainnetRskUrl;
let bridge;
Expand Down

0 comments on commit 6932803

Please sign in to comment.