Initialise JavaScript SDK
Let's initiate library in your project, depending on if you're following ES6 standard or CommonJS module format.
Import​
import { DripSDK } from 'dripverse';
or
const { DripSDK } = require('dripverse');
Initialise​
You can generate your Project API from the Utility Page of the NFT or the Project page itself.
var drip = new DripSDK('PROJECT_API_KEY');
Read more about Utility Setup on DripVerse Platform.
Note: Please use your generated project key only and do NOT share your project key with anyone. Learn more about Generating Project Key.
Contract Client​
We would need a contract client to proceed. A contract client can be generated from a smart contract deployed on the network and compiled to extract it's abi and bytecode. You can learn about compiling solidity smart contract from solc docs.
We will simplify this process using our sdk:
- Default
- by ID
// Get Contract Client
let contract = await drip.contractClient();
In case, you've a custom contract deployed, you can call it instead:
// Get Custom Contract Client
let contract = await drip.contractClient({
contractId: 6
});
Now, you have the contract client loaded.
Wallet Client​
Minting NFT is non-custodial. So, you're owner of your keys at all times. We do not store or have access to your keys at any point. There are several ways to get wallet client.
- Private Key
- Alchemy
- Metamask
- Arcana
// Get your walletClient:
let walletClient = await drip.walletClient(PRIVATE_KEY);
Optional:
networkId
:1
: Polygon Mumbai Testnet3
: Polygon Mainnet (Default)
import { ethers } from "dripverse";
// If you've access to your private keys, then use this method
// You can save your private on your system or some secret manager of your choice.
// Use the Private Key to create a wallet instance
let wallet = await new ethers.Wallet(PRIVATE_KEY);
// You can use any rpc node provider service. We are using Alchemy in this example. You can use Infura or QuickNode as well.
let httpProvider = new ethers.providers.AlchemyProvider(
"maticmum",
ALCHEMY_HTTP_KEY
);
// Finally, use node endpoint to create a wallet client instance.
let walletClient = await wallet.connect(httpProvider);
import { ethers } from "dripverse";
// If you're using Metamask Wallet, then use this.
// Note: This might work for other browser based wallets as well. But we've not tested them all. If there's a wallet that you'd like it work with and currently doesn't, please reach out to us and we can work with you to support your wallet.
const ethersProvider = new ethers.providers.Web3Provider(
window.ethereum,
"any"
);
// Finally, create your wallet client instance.
const walletClient = ethersProvider.getSigner();
Follow the official Arcana docs to set up Arcana Auth and obtain the wallet provider.
import { ethers } from "dripverse";
// Arcana auth setup First.
// const getArcanaProvider = () => {
// ...
//}
const arcanaProvider = getArcanaProvider();
const ethersProvider = new ethers.providers.Web3Provider(arcanaProvider, "any");
// Finally, create your wallet client instance.
const walletClient = ethersProvider.getSigner();
Now, create a Contract Signer instance. We will use this going forward to interact with the smart contract functions.
let contractSigner = contract.connect(walletClient);