Skip to content

Commit

Permalink
Merge pull request #9 from ethstorage/integration-test
Browse files Browse the repository at this point in the history
Support using contract address from config instead of contract address from ETHSTORAGE_MAPPING.
  • Loading branch information
iteyelmp authored Jul 24, 2024
2 parents 22119e8 + 2d8df03 commit 077416f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ const ethStorage = await EthStorage.create({
});
```

If you want to use your own contract, you can specify your contract address when create EthStorage.
```js
const {EthStorage} = require("ethstorage-sdk")

const rpc = "https://1rpc.io/sepolia";
const ethStorageRpc = "http://65.109.115.36:9540";
const privateKey = "0xabcd...";
const address = "0xabcd..."; // EthStorage contract address

const ethStorage = await EthStorage.create({
rpc: rpc,
ethStorageRpc: ethStorageRpc,
privateKey: privateKey,
address: address,
});
```

#### estimateCost

Expand Down
5 changes: 4 additions & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ The `FlatDirectory` class is a higher-level data management tool that provides m
- `rpc` (string): RPC for any evm network.
- `ethStorageRpc` (string): The EthStorage network rpc corresponding to this evm network, the data is obtained from the EthStorage network.
- `privateKey` (string): Wallet private key.
- `address` (string, optional): your Ethstorage contract address if you want to use your own one, if you want to use the default contract address, ignore this.

**Example**
```javascript
const config = {
rpc: "your_rpc",
ethStorageRpc: "ethstorage_rpc",
privateKey: "your_private_key"
privateKey: "your_private_key",
address: "your_contract_address"
};

const ethStorage = await EthStorage.create(config);
Expand Down Expand Up @@ -381,3 +383,4 @@ const status = await flatDirectory.setDefault(defaultFile);
## 5. Version History

- v1.0.1: Initial release with basic storage and data management functionalities.

14 changes: 9 additions & 5 deletions src/ethstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export class EthStorage {
#blobUploader;

static async create(config) {
const {rpc} = config;
const {rpc, address} = config;
const ethStorage = new EthStorage(config);
await ethStorage.init(rpc);
await ethStorage.init(rpc, address);
return ethStorage;
}

Expand All @@ -36,9 +36,13 @@ export class EthStorage {
this.#blobUploader = new BlobUploader(rpc, privateKey);
}

async init(rpc) {
const chainId = await getChainId(rpc);
this.#contractAddr = ETHSTORAGE_MAPPING[chainId];
async init(rpc, address) {
if (address != null) {
this.#contractAddr = address;
} else {
const chainId = await getChainId(rpc);
this.#contractAddr = ETHSTORAGE_MAPPING[chainId];
}
if (!this.#contractAddr) {
throw new Error("EthStorage: Network not supported yet.");
}
Expand Down

0 comments on commit 077416f

Please sign in to comment.