SDK currently has the following for the web3 integrations
- Gnosis - Gnosis for onchain payments
- Lit Protocol - For token gating
- NFT-PPFs - Fetching of NFT profile photos for users
- SIWE - Sign in with ethereum
- Snapshot - Snapshot for proposals
This SDK requires Node.js.
npm i web3-sdk-samudaiThe SDK has the following components and the below table provides an overview to initialize them.
| Plugin | README |
|---|---|
| Gnosis | const gnosis = new Gnosis(provider: Web3Provider, chaindId: number) |
| Lit Protocol | const litProtocol = new LitProtocol() |
| NFT PPFs | const nftPPfs = new NFTProfile() |
| SIWE | const siwe = new Siwe(provider: Web3Provider) |
| Snapshot | const snapshot = new Snapshot(spaceId: string, networkType: number, provider: Web3Provider) |
Gnosis APIs are used to create transactions on the multisig and fetch transactions.
To use Gnosis
const gnosis = new Gnosis(provider: Web3Provider, chaindId: number)const result = await gnosis.createSingleGnosisTx(receiverAddress: string, value: string,
safeAddress: string, senderAddress: string)Param 1:
safeAddressGnosis safe address. Param 2:receiverAddressWallet address of the user whom the funds is being sent. Param 3:valueETH value in wei. Param 4:senderAddressWallet address of the sender
const result = await gnosis.createBatchGnosisTx(safeAddress: string, receiverAddresses: string[],
value: string, senderAddress: string)Param 1:
safeAddressGnosis safe address. Param 2:receiverAddressesWallet addresses of the users whom the funds is being sent. Param 3:valueETH value in wei. Param 4:senderAddressWallet address of the sender
const result = await gnosis.getPendingTransactions(safeAddress: string)Param 1:
safeAddressGnosis safe address.
Example
const result = await gnosis.getPendingTransactions("<ethWalletAddress>")const result = await gnosis.getExecutedTransactions(safeAddress: string)Param 1:
safeAddressGnosis safe address.
Example
const result = await gnosis.getExecutedTransactions("<safeAddress>")const result = await gnosis.getTransactionDetails(safeTxHash: string)Param 1:
safeTxHashTransaction hash of a particular safe transaction.
Example
const result = await gnosis.getTransactionDetails("<safeTxHash>")const result = await gnosis.connectGnosis(userAddress: string)Param 1:
userAddressUser address
This will return the safes for which user is an owner and also list of all other owners for a safe
Example
const result = await gnosis.connectGnosis("<safeAddress>")NFT Profile APIs are used to fetch the NFTs owned by the user on ETH and Polygon which can later be set as profile photos
const nftProfile = new NFTProfile()const ethNFTs = await nftProfile.getEthProfilePPs(ethUserAddress: string)Param 1:
ethUserAddressWallet Address of the user.
Example
const ethNFTs = await nftProfile.getEthProfilePPs("<ethWalletAddress>")const polygonNFTs = await nftProfile.getMaticProfilePPs(maticUserAddress: string)Param 1:
maticUserAddressWallet Address of the user.
Lit Protocol APIs are used for token gating
To use Lit Protocol
const litProtocol = new LitProtocol()const tokenGating = await litProtocol.init(
chain: string,
contractAddress: string,
typeOfGating: TokenGatingType,
baseUrl: string,
path: string,
memberId: string,
tokenId?: string
)Param 1:
chainThe chain on which the Token Gating will be created. Refer the list of chains below the example. Param 2:contractAddressContract Address of the Token. Param 3:typeOfGatingEnum value of which type of Gating. Refer the enum list below the example. Param 4:baseUrlUrl of the url of frontend. Param 5:pathThe Path that requires the token gating. Param 6:memberIdMember UUID that is being authenticated. Param 7:tokenIdToken ID of a NFT for verification.
Returns:
jwtJWT token can be set on cookies or anything on the frontend and needs to be sent to SDK for verification
Example
const tokenGating = await litProtocol.init(
chain: "rinkeby",
contractAddress: "0xB1BFB38a527D05442D48068ca9798FD3E5d6ce0F",
typeOfGating: 0,
baseUrl: "http://samudai.xyz",
path: '/dao/<daoId>',
memberId: <memberId>,
)List of chains
| chain |
|---|
| ethereum |
| rinkeby |
| polygon |
| goerli |
| mumbai |
For further chain supports based on EVM use the following list https://developer.litprotocol.com/supportedChains
Enum for TokenGatingType
enum TokenGatingType = {
ERC20,
ERC721,
ERC1155,
}
ERC20 = 0
ERC721 = 1
ERC1155 = 2const result = await litProtocol.verifyLit(jwt: string, memberId: string)Param 1:
jwtJWT generated by the init functionality. Param 2:memberIdMember UUID
Returns: verifyLit returns true / false based on the access conditions
SIWE is used for Sign in with ethereum
To use SIWE
const siwe = new Siwe(provider: Web3Provider)To sign in user, you need to ask the user to sign a message and push the users to required screen after successful signing
const result = siwe.walletSignIn(domain: string)Param 1:
domainURL of the frontend
Example
const result = siwe.walletSignIn("https://samudai.xyz")Snapshot is used for fetching proposals and voting for them.
To use snapshot
const snapshot = new Snapshot(spaceId: string, networkType: number, provider: Web3Provider)Param 1:
spaceIdSpace ID in Snapshot Param 2:networkType0 for Ethereum, 1 for testnets Param 3:providerWeb3Provider
Example
const snapshot = new Snapshot("biryani.eth", 1, provider: Web3Provider)const result = snapshot.getSpace()const result = snapshot.getActiveProposals()const result = snapshot.getRecentProposals()const result = snapshot.castVote(proposalId: string, choice: number,account: any)