Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #533 from JesseTheRobot/feat/bundlr-to-irys
Browse files Browse the repository at this point in the history
feat: ✨ plugins: Transition from Bundlr to Irys storage driver
  • Loading branch information
febo committed Nov 9, 2023
2 parents 57b53ac + 496b73b commit e484b77
Show file tree
Hide file tree
Showing 16 changed files with 452 additions and 377 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-trainers-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@metaplex-foundation/js': minor
---

Transition from Bundlr to Irys
28 changes: 14 additions & 14 deletions packages/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ const metaplex = new Metaplex(connection);
On top of that, you can customise who the SDK should interact on behalf of and which storage provider to use when uploading assets. We refer to these as "Identity Drivers" and "Storage Drivers" respectively. You may change these drivers by calling the `use` method on the Metaplex instance like so. We'll see all available drivers in more detail below.

```ts
import { Metaplex, keypairIdentity, bundlrStorage } from "@metaplex-foundation/js";
import { Metaplex, keypairIdentity, irysStorage } from "@metaplex-foundation/js";
import { Connection, clusterApiUrl, Keypair } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("mainnet-beta"));
const wallet = Keypair.generate();

const metaplex = Metaplex.make(connection)
.use(keypairIdentity(wallet))
.use(bundlrStorage());
.use(irysStorage());
```

Notice how you can create a `Metaplex` instance using `Metaplex.make(...)` instead of `new Metaplex(...)` in order to make the fluent API more readable.
Expand Down Expand Up @@ -547,36 +547,36 @@ const file: MetaplexFile = await toMetaplexFileFromBrowser(browserFile);

Okay, now let’s talk about the concrete storage drivers available to us and how to set them up.

### bundlrStorage
### irysStorage

The `bundlrStorage` driver is the default driver and uploads assets on Arweave using the [Bundlr network](https://bundlr.network/).
The `irysStorage` driver is the default driver and uploads assets on Arweave using [Irys](https://irys.xyz/).

By default, it will use the same RPC endpoint used by the `Metaplex` instance as a `providerUrl` and the mainnet address `"https://node1.bundlr.network"` as the Bundlr address.
By default, it will use the same RPC endpoint used by the `Metaplex` instance as a `providerUrl` and the mainnet address `"https://node1.irys.xyz"` as the Irys address.

You may customise these by passing a parameter object to the `bundlrStorage` method. For instance, here’s how you can use Bundlr on devnet.
You may customise these by passing a parameter object to the `irysStorage` method. For instance, here’s how you can use Irys on devnet.

```ts
import { bundlrStorage } from "@metaplex-foundation/js";
import { irysStorage } from "@metaplex-foundation/js";

metaplex.use(bundlrStorage({
address: 'https://devnet.bundlr.network',
metaplex.use(irysStorage({
address: 'https://devnet.irys.xyz',
providerUrl: 'https://api.devnet.solana.com',
timeout: 60000,
}));
```

To fund your bundlr storage account you can cast it in TypeScript like so:
To fund your irys storage account you can cast it in TypeScript like so:

```ts
const bundlrStorage = metaplex.storage().driver() as BundlrStorageDriver;
const irysStorage = metaplex.storage().driver() as IrysStorageDriver;
```

This gives you access to useful public methods such as:

```ts
bundlrStorage.fund([metaplexFile1, metaplexFile2]); // Fund using file size.
bundlrStorage.fund(1000); // Fund using byte size.
(await bundlrStorage.bundlr()).fund(1000); // Fund using lamports directly.
irysStorage.fund([metaplexFile1, metaplexFile2]); // Fund using file size.
irysStorage.fund(1000); // Fund using byte size.
(await irysStorage.irys()).fund(1000); // Fund using lamports directly.
```

### mockStorage
Expand Down
4 changes: 2 additions & 2 deletions packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"test:exports": "node ./test/cjs-export.test.cjs && node ./test/esm-export.test.mjs"
},
"dependencies": {
"@bundlr-network/client": "^0.8.8",
"@irys/sdk": "^0.0.2",
"@metaplex-foundation/beet": "0.7.1",
"@metaplex-foundation/mpl-auction-house": "^2.3.0",
"@metaplex-foundation/mpl-bubblegum": "^0.6.2",
Expand Down Expand Up @@ -73,4 +73,4 @@
"readmeFile": "./README.md",
"displayName": "js"
}
}
}
54 changes: 0 additions & 54 deletions packages/js/src/errors/BundlrError.ts

This file was deleted.

54 changes: 54 additions & 0 deletions packages/js/src/errors/IrysError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { MetaplexError } from './MetaplexError';

/** @group Errors */
export class IrysError extends MetaplexError {
readonly name: string = 'IrysError';
constructor(message: string, cause?: Error) {
super(message, 'plugin', 'Irys', cause);
}
}

/** @group Errors */
export class FailedToInitializeIrysError extends IrysError {
readonly name: string = 'FailedToInitializeIrysError';
constructor(cause: Error) {
const message =
'Irys could not be initialized. ' +
'Please check the underlying error below for more details.';
super(message, cause);
}
}

/** @group Errors */
export class FailedToConnectToIrysAddressError extends IrysError {
readonly name: string = 'FailedToConnectToIrysAddressError';
constructor(address: string, cause: Error) {
const message =
`Irys could not connect to the provided address [${address}]. ` +
'Please ensure the provided address is valid. Some valid addresses include: ' +
'"https://node1.irys.xyz" for mainnet and "https://devnet.irys.xyz" for devnet';
super(message, cause);
}
}

/** @group Errors */
export class AssetUploadFailedError extends IrysError {
readonly name: string = 'AssetUploadFailedError';
constructor(status: number) {
const message =
`The asset could not be uploaded to the Irys network and ` +
`returned the following status code [${status}].`;
super(message);
}
}

/** @group Errors */
export class IrysWithdrawError extends IrysError {
readonly name: string = 'IrysWithdrawError';
constructor(error: string) {
const message =
`The balance could not be withdrawn from the Irys network and ` +
`returned the following error: ${error}.`;
super(message);
}
}
2 changes: 1 addition & 1 deletion packages/js/src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './BundlrError';
export * from './IrysError';
export * from './MetaplexError';
export * from './ProgramError';
export * from './RpcError';
Expand Down
2 changes: 0 additions & 2 deletions packages/js/src/plugins/bundlrStorage/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/js/src/plugins/bundlrStorage/plugin.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/js/src/plugins/corePlugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { utilsModule } from '../utilsModule';

// Default drivers.
import { guestIdentity } from '../guestIdentity';
import { bundlrStorage } from '../bundlrStorage';
import { irysStorage } from '../irysStorage';

// Verticals.
import { systemModule } from '../systemModule';
Expand All @@ -32,7 +32,7 @@ export const corePlugins = () => ({

// Default drivers.
metaplex.use(guestIdentity());
metaplex.use(bundlrStorage());
metaplex.use(irysStorage());

// Verticals.
metaplex.use(systemModule());
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './auctionHouseModule';
export * from './bundlrStorage';
export * from './irysStorage';
export * from './candyMachineModule';
export * from './candyMachineV2Module';
export * from './corePlugins';
Expand Down
Loading

0 comments on commit e484b77

Please sign in to comment.