Skip to main content

Getting Started

Installation

Install with yarn: yarn add @gomuweb3/sdk

or npm: npm install @gomuweb3/sdk

Instantiate the Gomu SDK

On the Web, through Metamask

import { Web3Provider } from "@ethersproject/providers";
import Gomu from "@gomuweb3/sdk";

const gomu = await Gomu.new({
provider: new Web3Provider(window.ethereum),
});

On Node.js

import { Web3Provider } from "@ethersproject/providers";
import { Wallet } from "@ethersproject/wallet";
import Gomu from "@gomuweb3/sdk";
import HDWalletProvider from "@truffle/hdwallet-provider";

const chainId = 1; // Ethereum
const mnemonic = "<YOUR_MNEMONIC>";
const url = "<ALCHEMY_OR_INFURA_URL>";
const provider = new HDWalletProvider({
mnemonic,
url,
});
const wallet = Wallet.fromMnemonic(mnemonic);
const gomu = await Gomu.new({
provider: new Web3Provider(provider),
signer: wallet,
address: wallet.address,
chainId,
});
note

Some node-native sub-dependencies aren't polyfilled in Webpack 5, so consider using other versions of Webpack. If you are using create-react-app, then downgrading react-script to version 4 might help.

Preparing of assets

Gomu currently supports buying / selling of ERC721 / ERC1155 tokens for ERC20 tokens.

Support for native tokens and trading of arbitrary combinations of ERC721/ ERC1155/ ERC20 assets is coming soon!

import { Erc20Asset, ERC721Asset, ERC1155Asset } from "@gomuweb3/sdk"

// Wrapped Ethereum
const erc20Asset: Erc20Asset = {
contractAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
type: "ERC20",
amount: BigInt("12345000000000000000"), // 12.345 WETH
}

// Bored Ape Yacht Club
const erc721Asset: Erc721Asset = {
contractAddress: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
tokenId: "6",
type: "ERC721",
}

// The Six Dragons - Faith Helmet
const erc1155Asset: Erc1155Asset = {
contractAddress: "0xfaafdc07907ff5120a76b34b731b278c38d6043c",
tokenId: "54277541829991974093381269539132608062317087198765048803605787749302453403648",
type: "ERC1155",
amount: BigInt("7"),
note

Amount is in base unit

Example usage of sell and buy orders on Opensea and Traderxyz

Creating sell orders for asset on opensea and traderxyz in WETH on mainnet:

const makerAsset = {
contractAddress: "<ASSET_CONTRACT_ADDRESS>",
tokenId: "<TOKEN_ID>",
type: "ERC721", // or ERC1155
};

const takerAsset = {
contractAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH ERC20 Contract Address
type: "ERC20",
amount: 12000000000000000000n, // 12 WETH in BigInt
// OR
amount: BigInt("12000000000000000000"),
};

gomuSdk
.makeOrder({
makerAssets: [makerAsset],
takerAssets: [takerAsset],
})
.then(console.log); // Order[]

Creating buy orders in WETH on mainnet:

const makerAsset = {
contractAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH ERC20 Contract Address
amount: 33000000000000000000n, // 33 WETH in BigInt
type: "ERC20",
};

const takerAsset = {
contractAddress: "<ASSET_CONTRACT_ADDRESS>",
tokenId: "<TOKEN_ID>",
type: "ERC721", // or ERC1155
};

gomuSdk
.makeOrder({
makerAssets: [makerAsset],
takerAssets: [takerAsset],
})
.then(console.log); // Order[]

Get orders where you are maker, and cancel first one:

const getOrdersThenCancelFirstOne = async() {
const { orders } = await gomuSdk.getOrders({
maker: '<YOUR_ACCOUNT_ADDRESS>',
});
const cancelledResponse = await gomuSdk.cancelOrder(orders[0]);
};

Get orders for specific asset for sale and take first order. Do note that you probably want to sort the orders to take orders with maximum value:

const getOrdersThenTakeFirstOne = async() {
const { orders } = await gomuSdk.getOrders({
makerAsset: {
contractAddress: '<ASSET_CONTRACT_ADDRESS>',
tokenId: '<TOKEN_ID>',
type: 'ERC721',
},
});
const takenOrderResponse = await gomuSdk.takeOrder(orders[0]);
};