Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Added contract data to be used in js projects (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
javiesses authored Mar 30, 2020
1 parent 47e4339 commit ebc3a28
Show file tree
Hide file tree
Showing 8 changed files with 1,998 additions and 2,184 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- checkout
- run:
name: Prepare Truffle
command: sudo npm install -g [email protected].0
command: sudo npm install -g [email protected].18

- run:
name: Install rns-fifs
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ build/
node_modules/
.DS_Store
.secret
RSKOwnerData.json
NamePriceData.json
FIFSRegistrarData.json
RenewerData.json
FIFSAddrRegistrarData.json
BytesUtilsData.json
types
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,37 @@ MainNet: [0x7a9872a7615c475b62a62b8f6e491077fb05f663](https://explorer.rsk.co/ad

TestNet: [0xe48ad1d5fbf61394b5a7d81ab2f36736a046657b](https://explorer.testnet.rsk.co/address/0xe48ad1d5fbf61394b5a7d81ab2f36736a046657b)

## JS

```js
const Web3 = require('web3');
const FIFSRegistrarData = require('@rsksmart/rns-rskregistrar/FIFSRegistrarData.json');
const web3 = new Web3('https://public-node.rsk.co')
const FIFSRegistrar = new web3.eth.Contract(FIFSRegistrarData.abi, FIFSRegistrarData.address.rskMainnet);
```

## Types

There are TypeScript typing definitions of the contracts published together with the original contracts.
Supported contract's libraries are:

* `web3` version 1.* - `web3-v1-contracts`
* `web3` version 2.* - `web3-v2-contracts`
* `truffle` - `truffle-contracts`
* `ethers` - `ethers-contracts`

You can use them as follow:

```typescript
import Web3 from 'web3'
import FIFSRegistrar from '@rsksmart/rns-rskregistrar/types/web3-v1-contracts/FIFSRegistrarData.d.ts'
import FIFSRegistrarData from '@rsksmart/rns-rskregistrar/FIFSRegistrarData.json'
const web3 = new Web3('https://public-node.rsk.co')
const registrar = new web3.eth.Contract(FIFSRegistrarData.abi, FIFSRegistrarData.address.rskMainnet) as FIFSRegistrar
```

Replace `web3-v1-contracts` with the proper library version.

## Setup

```
Expand Down
26 changes: 26 additions & 0 deletions addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"RSKOwner": {
"rskMainnet": "0x45d3e4fb311982a06ba52359d44cb4f5980e0ef1",
"rskTestnet": "0xca0a477e19bac7e0e172ccfd2e3c28a7200bdb71"
},
"NamePrice": {
"rskMainnet": "0xd09adf13e482928e47e96dd6f02aad1daf7a5a47",
"rskTestnet": "0x794f99f1a9382ba88b453ddb4bfa00acae8d50e8"
},
"FIFSRegistrar": {
"rskMainnet": "0x779195c53cc7c1a33bd2eea5f63f2c1da8798d61",
"rskTestnet": "0x36ffda909f941950a552011f2c50569fda14a169"
},
"Renewer": {
"rskMainnet": "0x7a9872a7615c475b62a62b8f6e491077fb05f663",
"rskTestnet": "0xe48ad1d5fbf61394b5a7d81ab2f36736a046657b"
},
"FIFSAddrRegistrar": {
"rskMainnet": "0xd9c79ced86ecf49f5e4a973594634c83197c35ab",
"rskTestnet": "0x90734bd6bf96250a7b262e2bc34284b0d47c1e8d"
},
"BytesUtils": {
"rskMainnet": "0xe9e32c20cbce0ad4f16377bd9a84554828e86a06",
"rskTestnet": "0x7faf084ef72cb71f3383a5c568c70853ac4c298e"
}
}
81 changes: 81 additions & 0 deletions datagen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const fs = require('fs');

const addresses = require('./addresses');

const rskOwnerBuild = require('./build/contracts/RSKOwner');

const rskOwnerData = {
abi: rskOwnerBuild.abi,
bytecode: rskOwnerBuild.bytecode,
address: {
rskMainnet: addresses.RSKOwner.rskMainnet,
rskTestnet: addresses.RSKOwner.rskTestnet,
},
};

fs.writeFileSync('./RSKOwnerData.json', JSON.stringify(rskOwnerData));

const namePriceBuild = require('./build/contracts/NamePrice');

const namePriceData = {
abi: namePriceBuild.abi,
bytecode: namePriceBuild.bytecode,
address: {
rskMainnet: addresses.NamePrice.rskMainnet,
rskTestnet: addresses.NamePrice.rskTestnet,
},
};

fs.writeFileSync('./NamePriceData.json', JSON.stringify(namePriceData));

const fifsRegistrarBuild = require('./build/contracts/FIFSRegistrar');

const fifsRegistrarData = {
abi: fifsRegistrarBuild.abi,
bytecode: fifsRegistrarBuild.bytecode,
address: {
rskMainnet: addresses.FIFSRegistrar.rskMainnet,
rskTestnet: addresses.FIFSRegistrar.rskTestnet,
},
};

fs.writeFileSync('./FIFSRegistrarData.json', JSON.stringify(fifsRegistrarData));

const fifsAddrRegistrarBuild = require('./build/contracts/FIFSAddrRegistrar');

const fifsAddrRegistrarData = {
abi: fifsAddrRegistrarBuild.abi,
bytecode: fifsAddrRegistrarBuild.bytecode,
address: {
rskMainnet: addresses.FIFSAddrRegistrar.rskMainnet,
rskTestnet: addresses.FIFSAddrRegistrar.rskTestnet,
},
};

fs.writeFileSync('./FIFSAddrRegistrarData.json', JSON.stringify(fifsAddrRegistrarData));

const renewerBuild = require('./build/contracts/Renewer');

const renewerData = {
abi: renewerBuild.abi,
bytecode: renewerBuild.bytecode,
address: {
rskMainnet: addresses.Renewer.rskMainnet,
rskTestnet: addresses.Renewer.rskTestnet,
},
};

fs.writeFileSync('./RenewerData.json', JSON.stringify(renewerData));

const bytesUtilsBuild = require('./build/contracts/BytesUtils');

const bytesUtilsData = {
abi: bytesUtilsBuild.abi,
bytecode: bytesUtilsBuild.bytecode,
address: {
rskMainnet: addresses.BytesUtils.rskMainnet,
rskTestnet: addresses.BytesUtils.rskTestnet,
},
};

fs.writeFileSync('./BytesUtilsData.json', JSON.stringify(bytesUtilsData));
Loading

0 comments on commit ebc3a28

Please sign in to comment.