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

Adding SPL support for Solana #26

Draft
wants to merge 2 commits into
base: anmol-gsoc2024
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ An npm package for seamless integration of all NFT related functionalities in We
- `/src/index.ts ` : Toolbox class, the single default export from the package
- `/src/classes` : Core classes of the package that implement functionalities
- `/src/helpers` : Helper classes that are used by core classes
- `src/chains` : Blockchain-specific implementations, adapters, and example scripts for various functionalities
- `/tests` : Tests for all core classes
- `/examples` : Example scripts for all functionalities
- `/docs` : Markdown documentation
- `/documentation` : Docusaurus project for documentation website

Expand Down Expand Up @@ -64,7 +64,7 @@ An npm package for seamless integration of all NFT related functionalities in We
To run an example script, update the required credentials in `examples/*.json` file and run

```
ts-node examples/generate.ts
ts-node src/chains/Ethereum/functions/generateEthereum.ts
```

To run Tests, update the required credentials in `tests/test_specs.json` file and run
Expand Down
20 changes: 16 additions & 4 deletions documentation/docs/Contracts/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ sidebar_position: 3

# Deploy Smart Contract

# Deploy Ethereum Contract

Once a Contract File has been finalized, it needs to be deployed to a blockchain network to make it operational.
NFT Toolbox makes this very simple with the `deployContract` function.
NFT Toolbox makes this very simple with the `deployEthereumContract` function.

The function uses the parameters provided to initialize Contract object to locate the Contract File,
establish an [ethers.js](https://ethers.org/) connection to the Blockchain network, Deploy the contract
Expand All @@ -14,11 +16,21 @@ and initialize it.
**After [Initializing the Contract Object](/docs/Contracts/initializeContract),**

```javascript
nftToolbox.deployContract();
nftToolbox.deployEthereumContract();
```

:::note
The directory path provided as parameter `dir` to `initContract` function must contain a Solidity file
with file name same as the parameter `name` passed to `initContract` function. This is the Contract file
The directory path provided as parameter `dir` to `initEthereumContract` function must contain a Solidity file
with file name same as the parameter `name` passed to `initEthereumContract` function. This is the Contract file
that will be deployed by NFT Toolbox.
:::

# Deploy Solana Contract

After drafting your Solana contract, you can deploy it to the Solana network using the `deploySolanaContract` function.

The `deploySolanaContract` function doesn't require additional parameters as it uses the information provided during initialization.

```javascript
nftToolbox.deploySolanaContract();
```
27 changes: 27 additions & 0 deletions documentation/docs/Contracts/draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sidebar_position: 2

# Draft Contract File

# Ethereum Draft Contract

The **ERC721** and **ERC1155** standards created by [Open Zeppelin](https://www.openzeppelin.com/contracts)
are the most popular NFT Contracts used by the community.
The [Open Zeppelin Wizard](https://wizard.openzeppelin.com/) is a tool that programatically generates
Expand Down Expand Up @@ -78,3 +80,28 @@ nftToolbox.draftContract({
updatableUri: false;
});
```

# Draft Solana Contract

To create a new Solana contract, use the `draftSolanaContract` function. This function generates a Rust program for your NFT contract.

## Parameters

The `draftSolanaContract` function takes the following parameters:


| Name | Type | Description |
| -------------- | ------- | ------------------------------------------ |
| `payer` | Keypair | Keypair of the account paying for deployment |
| `programId` | string | Program ID for the contract |
| `programData` | Buffer | Program data for the contract |

## Examples

```javascript
nftToolbox.draftSolanaContract({
payer: payer,
programId: programId,
programData: programData,
});
```
91 changes: 83 additions & 8 deletions documentation/docs/Contracts/initializeContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ sidebar_position: 1
# Initialize Contract Object

Before jumping into any functionality, a Contract object has to be initialized in the Toolbox.
This is done with the `initContract` function.


# Initializing Ethereum Contract

This is done with the `initEthereumContract` function for Ethereum.

## Parameters

The parameters of `initContract` function are described as follows.
The parameters of `initEthereumContract` function are described as follows.

| Name | Type | Description |
| ------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -39,10 +43,7 @@ See their [documentation](https://docs.ethers.io/v5/) for more details.
#### Supported Networks

- Ethereum Mainnet (`"homestead"`)
- Ropsten Testnet (`"ropsten"`)
- Rinkeby Testnet (`"rinkeby"`)
- Goerli Testnet (`"goerli"`)
- Kovan Testnet (`"kovan"`)
- Sepolia Testnet (`"sepolia"`)
- Polygon Mainnet (`"matic"`)
- Polygon Mumbai Testnet (`"maticmum"`)

Expand Down Expand Up @@ -79,8 +80,8 @@ Draft or Deploy functionalities.
**After [Importing the package](/docs/intro#import-it-in-your-project),**

```javascript
nftToolbox.initContract({
name: "YourContract",
nftToolbox.initEthereumContract({
name: "YourEthereumContract",
symbol: "YOUR",
dir: "./path/to/directory/Contracts/",
standard: "ERC721",
Expand All @@ -102,3 +103,77 @@ nftToolbox.initContract({
},
});
```

# Initialize Solana Contract

Before using any Solana-specific functionality, you need to initialize a Solana Contract object in the Toolbox. This is done with the `initSolanaContract` function.

## Parameters

The parameters of `initSolanaContract` function are described as follows.

| Name | Type | Description |
| ------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | string | Name of the Contract used on deployment |
| `symbol` | string | Symbol of the Contract used on deployment |
| `dir` | string | Path to directory where the new Contract File is to be created |
| `connection` | object | Used to set up Solana connection. See Connection Details |
| `deployed` | object | (optional) Used for initialization of deployed contracts. See Initialization for Deployed Contract |

### Connection Details

The fields of `connection` parameter are described as follows.

| Name | Type | Description |
| ---------- | ------ | ------------------------------------------------------------ |
| `rpc` | string | URL of the Solana RPC node |
| `network` | string | Solana network to use (e.g., "devnet", "mainnet") |
| `payer` | keypair | Keypair of the account paying for transactions |
| `idl` | idl | Interface Description Language for the program |

#### Supported Networks

- Devnet
- Testnet
- Mainnet

### Initialization for Deployed Contract

To initialize a deployed Solana contract, include the deployed parameter:

The fields of `deployed` parameter are described as follows.

| Name | Type | Description |
| --------- | ------ | ------------------------------------------- |
| `address` | string | Address of the deployed contract |
| `programId` | string | Program ID of the deployed contract |
| `programData` | Buffer | (optional) Program data of the contract |

:::note
The initialization for deployed contracts will only be useful in the Interacting Functionality and not in
Draft or Deploy functionalities.
:::


## Example

**After [Importing the package](/docs/intro#import-it-in-your-project),**

```javascript
nftToolbox.initSolanaContract({
name: "MySolanaNFT",
symbol: "SNFT",
dir: "./solana-contracts/",
connection: {
rpc: "https://api.devnet.solana.com",
network: "devnet",
connection: connection,
payer: payer,
idl: idl,
},
deployed: {
address: "Your program deployed address",
programId: "Your programId",
},
});
```
55 changes: 50 additions & 5 deletions documentation/docs/Contracts/interact.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ sidebar_position: 4

# Interact with Smart Contract

# Interact with Ethereum Contract

NFT Toolbox provides the functionality to interact with a deployed Smart Contract on a Blockchain Network.
This is done with `readContract` and `writeContract` functions.
This is done with `readEthereumContract` and `writeEthereumContract` functions.

Both the functions accept two parameters.

- **(string)** The name of the Contract method to be called
- **(array)** The parameters to be passed to the Contract method in order

`readContract` is used to call the _view_ methods on the Smart Contract which do not manipulate it's state.
`readEthereumContract` is used to call the _view_ methods on the Smart Contract which do not manipulate it's state.
It returns the response from the Smart Contract.

`writeContract` is used to call the methods on the Smart Contract which manipulate it's state.
`writeEthereumContract` is used to call the methods on the Smart Contract which manipulate it's state.
It returns the [ethers.js](https://ethers.org/) transaction object created on the Contract.

## Example
Expand All @@ -26,12 +28,55 @@ It returns the [ethers.js](https://ethers.org/) transaction object created on th
const exampleMintNFT = async () => {
const address = "0xADDRESS";

const tx = await nftToolbox.writeContract("safeMint", [address]);
const tx = await nftToolbox.writeEthereumContract("safeMint", [address]);
await tx.wait();

const bal = await nftToolbox.readContract("balanceOf", [address]);
const bal = await nftToolbox.readEthereumContract("balanceOf", [address]);
console.log(bal.toString());
};

exampleMintNFT();
```

# Interact with Solana Contract

NFT Toolbox provides the functionality to interact with a deployed Smart Contract on a Blockchain Network.
Once your Solana contract is deployed, using the `readSolanaContract` and `writeSolanaContract` functions.


Both the functions accept two parameters.

- **(string)** The name of the Contract method to be called
- **(array)** The parameters to be passed to the Contract method in order

`readSolanaContract` is used to call view methods that don't modify the contract state.
It returns the response from the Smart Contract.

`writeSolanaContract` is used to call methods that modify the contract state.
It returns a `Promise` that resolves to the transaction signature.

## Example

**After [Deploying a Contract](/docs/Contracts/deploy) or [Initializing a Deployed Contract](/docs/Contracts/initializeContract#initialization-for-deployed-contract)**


```javascript
import { PublicKey } from "@solana/web3.js";

const exampleMintNFT = async () => {
const recipient = new PublicKey("RECIPIENT_ADDRESS");

const tx = await nftToolbox.writeSolanaContract("mintSPLToken", [recipient, 1]);
console.log("Transaction signature:", tx);

const bal = await nftToolbox.readSolanaContract("getTokenBalance", [recipient]);
console.log("Balance:", bal.toString());
};

exampleMintNFT();
```

:::note
The difference in parameters (`[address]` for `Ethereum` vs `[recipient, 1]` for `Solana`) is Ethereum's safeMint typically only requires an address, while Solana's mintSPLToken requires both a recipient address and an amount.
:::

34 changes: 24 additions & 10 deletions documentation/docs/Upload/uploadCollection.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,46 @@ In order to be uploaded, a Collection has to first be initialized in the Toolbox
[Initialize a Collection](/docs/generate#initialize-a-collection).

:::note
The structure of directory provided to `initCollection` as parameter `dir` is restricted.
It must contain two directories named `assets` and `metadata`. These are the directories that NFT Toolbox
will upload to File Storage. The names of Asset and corresponding Metadata files must be same.
The structure of the directory provided to `initEthereumCollection` or `initSolanaCollection` as parameter dir is restricted.
It must contain two directories named assets and metadata. These are the directories that NFT Toolbox
will upload to File Storage. The names of Asset and corresponding Metadata files must be the same.
:::

NFT Collections are uploaded to File Storage with the `uploadCollection` function in Toolbox. The
NFT Collections are uploaded to File Storage using `uploadEthereumCollection` function for Ethereum & `uploadSolanaCollection` for Solana in the Toolbox. The
`uploadCollection` function first uploads the `assets` directory to File Storage. Then each metadata file
in the `metadata` folder is updated with the corresponding asset's URL.
Finally the `metadata` directory is uploaded to File Storage and both Asset and Metadata
[CIDs](https://docs.ipfs.tech/concepts/content-addressing/) are returned.

:::note
The `image` field in Metadata is named and updated in accordance with the
[OpenSea Metadata Standards](https://docs.opensea.io/docs/metadata-standards).
[OpenSea Metadata Standards](https://docs.opensea.io/docs/metadata-standards) for Ethereum.
Solana follows [Metaplex standard](https://developers.metaplex.com/token-metadata/token-standard) for Solana collections.
If a different format is required, it can be updated separately using the
[CIDs](https://docs.ipfs.tech/concepts/content-addressing/) returned by the function.
:::

## Example
## For Ethereum

**After [Initializing a Collection](/docs/generate#initialize-a-collection) and [Initializing the File Storage](/docs/Upload/initializeFileStorage),**
**After [Initializing Ethereum Collection](/docs/generate#initialize-ethereum-collection) and [Initializing the File Storage](/docs/Upload/initializeFileStorage),**

```javascript
const uploadCollectionExample = async function () {
const { assetCID, metadataCID } = await nftToolbox.uploadCollectionNFT();
const uploadEthereumCollectionExample = async function () {
const { assetCID, metadataCID } = await nftToolbox.uploadEthereumCollectionNFT();
console.log(assetCID, metadataCID);
};
uploadCollectionExample();
uploadEthereumCollectionExample();
```


## For Solana

**After [Initializing Solana Collection](/docs/generate#initialize-solana-collection) and [Initializing the File Storage](/docs/Upload/initializeFileStorage),**

```javascript
const uploadSolanaCollectionExample = async function () {
const { assetCID, metadataCID } = await nftToolbox.uploadSolanaCollectionNFT();
console.log(assetCID, metadataCID);
};
uploadSolanaCollectionExample();
```
Loading