Giter VIP home page Giter VIP logo

ethereum-sdk's Introduction

Rarible Protocol Ethereum Software Development Kit

⚠️ PLEASE READ ⚠️

This package has been moved to another repository. Current repository won't be updated anymore.

Rarible Protocol Ethereum SDK enables applications to easily interact with Rarible protocol.

See more information about Rarible Protocol at docs.rarible.org.

Installation

npm install -D @rarible/protocol-ethereum-sdk

or inject package into your web page with web3 instance

<script src="https://unpkg.com/@rarible/[email protected]/umd/rarible-web3-ethereum.js" type="text/javascript"></script>
<script src="https://unpkg.com/@rarible/[email protected]/umd/rarible-ethereum-sdk.js" type="text/javascript"></script>
<script src="https://unpkg.com/[email protected]/dist/web3.min.js" type="text/javascript"></script>

With protocol-ethereum-sdk, you can:

  • Create sell orders
  • Create/accept bid on NFTs
  • Create/finish/cancel auctions and also put bids and buy out NFTs
  • Buy tokens for regular sell orders
  • Create Lazy Mint NFT ERC721 and ERC1155 tokens
  • Make regular mint
  • Transfer tokens
  • Burn tokens

API reference

You can view the reference for the latest version of the API or choose API on different Ethereum networks.

Libraries support

web3.js and ethers.js libraries are supported.

You can use the following types of providers:

  • web3 - web3.js provider
  • ethersEtherium - ethers.js default provider
  • Web3Ethereum - moving from a web3.js based application to ethers by wrapping an existing Web3-compatible and exposing it as an ethers.js provider

Signer from ethers.js is also supported.

Usage with web3.js

Below examples show how you can implement supported functions in you app.

Configure and create Rarible SDK object

import { createRaribleSdk } from "@rarible/protocol-ethereum-sdk"

const sdk = createRaribleSdk(web3, env, { fetchApi: fetch })
  • web3 - configured with your provider web3js client
  • env - environment configuration name, it should accept one of these values 'ropsten' | 'rinkeby' | 'mainnet' | 'e2e'

Configure Rarible SDK in browser

const web = new Web3(ethereum)
const web3Ethereum = new window.raribleWeb3Ethereum.Web3Ethereum({ web3: web })
const env = "mainnet" // "e2e" | "ropsten" | "rinkeby" | "mainnet"
const raribleSdk = new window.raribleEthereumSdk.createRaribleSdk(web3Ethereum, env)
  • ethereum - metamask browser instance (window.ethereum)

Сheck out our DEMO PAGE

Create sell order

const order: Order = await sdk.order.sell(request)
// Sell request example:
const contractErc20Address: Address = '0x0' // your ERC20 contract address
const contractErc721Address: Address = '0x0' // your ERC721 contract address
const tokenId: BigNumber = '0x0' // the ERC721 Id of the token on which we want to place a bid
const sellerAddress: Address = '0x0' // Owner of ERC721 token
const nftAmount: number = 1 // For ERC721 always be 1
const sellPrice: number = 10 // price per unit of ERC721 or ERC1155 token(s)
const request = {
	makeAssetType: {
		assetClass: "ERC1155",
		contract: contractErc721Address,
		tokenId: tokenId,
	},
	maker: sellerAddress,
	amount: nftAmount,
	originFees: [],
	payouts: [],
	price: sellPrice,
	takeAssetType: {
		assetClass: "ERC20",
		contract: contractErc20Address
	},
}

Returns an object of created order.

Sell e2e test

Create bid

const order: Order = await sdk.order.bid(request)

// Bid request example:
const contractErc20Address: Address = '0x0' // your ERC20 contract address
const contractErc721Address: Address = '0x0' // your ERC721 contract address
const tokenId: BigNumber = '0x0' // the ERC721 Id of the token on which we want to place a bid
const sellerAddress: Address = '0x0' // Owner of ERC721 token
const buyerAddress: Address = '0x0' // Who make a bid
const nftAmount: number = 1 // For ERC721 always be 1
const bidPrice: number = 10 // price per unit of ERC721 or ERC1155 token(s)

const request = {
	makeAssetType: {
		assetClass: "ERC20",
		contract: contractErc20Address,
	},
	maker: buyerAddress,
	takeAssetType: {
		assetClass: "ERC721",
		contract: contractErc721Address,
		tokenId: tokenId,
	},
	taker: sellerAddress,
	amount: nftAmount,
	originFees: [],
	payouts: [],
	price: bidPrice,
}

Returns an object of created bid order.

Bid e2e test

Purchase order or accept bid

const order: SimpleOrder

sdk.order.buy({ order, payouts: [], originFees: [], amount: 1, infinite: true })
// or
sdk.order.acceptBid({ order, payouts: [], originFees: [], amount: 1, infinite: true })

For example, you can get the order object using our sdk api methods sdk.apis.order.getSellOrders({}) and pass it to buy function. You can get more information in the test repository sell e2e test

Auctions

You can create auction:

const auction = sdk.auction.start({
  makeAssetType: { // NFT asset type
    assetClass: "ERC1155",
    contract: toAddress(nftContractAddress),
    tokenId: toBigNumber("1"),
  },
  amount: toBigNumber("1"), // NFT amount, for ERC721 always be 1
  takeAssetType: { // payment token asset type
    assetClass: "ERC20",
    contract: toAddress(paymentTokenContractAddress),
  },
  minimalStepDecimal: toBigNumber("0.1"), // Minimal step of next bid (0.5, 0.6 and etc...)
  minimalPriceDecimal: toBigNumber("0.5"), // Minimal bid price
  duration: 1000, // Auction duration in seconds, less 15 minutes (60*60*15) and greater than 1000 days 
  startTime: 0, // Timestamp start of auction. If not set, auction will start when first bid will place 
  buyOutPriceDecimal: toBigNumber("1"), // Buy out price
  originFees: [], // Origin fees in format: { address, value } (value in range 0-10000, where 10000 - 100%, 0 - 0%)
})
await auction.tx.wait() // Waiting for tx accepting

it returns

{ 
  tx, // EthereumTransaction
  hash, // Promise<string> - auction hash
  auctionId // Promise<string> - ID auction 
}

Place an auction bid:

sdk.auction.putBid({
  hash: auctionHash, // Hash of auction, created during start auction
  priceDecimal: toBigNumber("0.2"), // Bid price
  originFees: [{ // Optional - origin fees
    account: toAddress(feeAddress),
    value: 1000,
  }],
})

Buy out NFT

sdk.auction.putBid({
  hash: auctionHash, // Hash of auction, created during start auction
})

Cancel auction

sdk.auction.cancel({
  hash: auctionHash, // Hash of auction, created during start auction
})

Finish auction

sdk.auction.finish({ // You can finish auction when duration is over and made at least one bid 
  hash: auctionHash, // Hash of auction, created during start auction
})

Mint NFT Tokens

You can mint ERC721 and ERC1155 tokens in two ways:

  1. Regular "on chain" minting using contract.
  2. Off chain minting (the transaction itself and payment for gas occurs at the time of purchase or transfer).

You can use mint to create a token in different collections. Depending on the collection type, different mint requests should be sent to the function (isErc1155v1Collection, isErc1155v2Collection etc).

Mint function checks:

  • Request for MintOffChainResponse or MintOnChainResponse.
  • Token type: ERC721 or ERC1155.

Differences between mint functions in the presence of arguments creators, supply and lazy:

  • creators not use in ERC1155 v1
  • supply used only for ERC1155 v1 and v2
  • lazy is used if the passed collection supports lazy mint. Otherwise, the usual mint will be performed

For more information, see mint.ts.

ERC1155 V2 Lazy example:

return mint({
  collection,    // Collection info
  uri: "",       // Token URI
  royalties: [], // The amount of royalties
  supply: 1,     // Number of the tokens to mint, used only for ERC1155
  creators: [],  // Creators of token
  lazy: true,    // The token will be lazy minted or not
})

For more information, see mint.md.

Mint e2e test

Transfer

transfer(asset, to[, amount])

Transfer request params:

asset: {
    tokenId: BigNumber, // - id of token to transfer
    contract: Address, // - address of token contract
    assetClass?: "ERC721" | "ERC1155" // - not required, type of asset
}
to: Address, // - ethereum address of receiver of token
amount: BigNumber // - amount of asset to transfer, used only for ERC1155 assets

Example

const hash = await sdk.nft.transfer(
	{
		assetClass: "ERC1155",
		contract: toAddress(contractAddress),
		tokenId: toBigNumber(tokenId),
	},
	receiverAddress,
	toAddress('10')
)

Burn

const hash = await sdk.nft.burn({
	contract: contractAddress,
	tokenId: toBigNumber(tokenId),
})

Suggestions

You are welcome to suggest features and report bugs found!

Contributing

The codebase is maintained using the "contributor workflow" where everyone without exception contributes patch proposals using "pull requests" (PRs). This facilitates social contribution, easy testing, and peer review.

See more information on CONTRIBUTING.md.

License

Rarible Protocol Ethereum SDK is available under the MIT License.

Note

This is a pre-release version. Backward compatibility is not fully supported before 1.0 release. Backward compatibility is only guaranteed in minor releases.

For example, 0.2.x version may not be compatible with 0.1.x. So, it's advised to include dependencies using package versions (ex. rarible/[email protected]).

ethereum-sdk's People

Contributors

aciceri avatar atul161 avatar breeeew avatar evgenynacu avatar ex1st0r avatar mazinden avatar nikolay-ryabinin-rarible avatar rzcoder avatar sanufriev avatar sherbakovama avatar sirgawain0x avatar vanya2h avatar vitalbadjo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ethereum-sdk's Issues

sdk order.sell not working for ERC1155

I'm trying to create a sell order from my front-end client on an RFC1155 token I own and I'm getting the following error:

{
  "code": "INCORRECT_LAZY_ASSET",
  "message": "Invalid signatures for creators [0x28d431d565b97815473a4773634acbfc1f12421b] for lazy asset on make side",
  "status": 400
}

Here's the code:

const orderBuilder = await raribleSdk.order.sell({
  makeAssetType: {
    assetClass: 'ERC1155',
    contract: toAddress(
      config.get('myown1155contractaddress')
    ),
    tokenId: toBigNumber(
      extractTokenIdFromItemId(nft.previewNft.itemId)
    ),
  },
  maker: toAddress(ownership.owner.ethAddress),
  amount: quantity,
  price: getValues('price'),
  payouts: [],
  originFees: [
    {
      account: toAddress(config.get('myownaddress')),
      value: 250,
    },
  ],
  takeAssetType: { assetClass: 'ETH' },
});

and here's the request I see in the browser:

{
  "maker": "0x28d431d565b97815473a4773634acbfc1f12421b",
  "make": {
    "assetType": {
      "@type": "ERC1155",
      "contract": "0x927b2ed99edd05a1fbef4de4e1775ada0901d4c2",
      "tokenId": "18467429459816144863947812166421793754398676185957064781363011930739185811472",
      "uri": "/ipfs/QmSsKPRpMwUHNT7fJDJQ3nRsBAJBNskeatbYhNtTKr9uL8",
      "creators": [
        {
          "account": "0x28d431d565b97815473a4773634acbfc1f12421b",
          "value": 10000
        }
      ],
      "royalties": [
        {
          "account": "0x28d431d565b97815473a4773634acbfc1f12421b",
          "value": 500
        },
        {
          "account": "0xee5f8c3e15b2d9280f060f01fc08c2f2f3b4476b",
          "value": 1000
        }
      ],
      "signatures": [
      "0x107899f9ff79bad2c9659c6154d661c5badf20daea4e6f5bcb820d5fe946674e47cb524e0f53842d1df04304ff65da14343a8cb2b5e2cc2b3f87c2f47d3face01c"
      ],
      "supply": "10",
      "assetClass": "ERC721_LAZY"
    },
    "value": "2"
  },
  "take": { "assetType": { "assetClass": "ETH" }, "value": "2" },
  "type": "RARIBLE_V2",
  "data": {
    "dataType": "RARIBLE_V2_DATA_V1",
    "payouts": [],
    "originFees": [
      { "account": "0x28d431d565b97815473a4773634acbfc1f12421b", "value": 250 }
    ]
  },
  "salt": "34945805662674558592829447995129376213206409534291223948514422231105297539999",
  "signature": "0x24bda6f87871cc6fbac173e60aa46b95847a42c1ac7097c5b59bb346289dd1a367272f444f15009d4d875570e154d51aabd1235ea44b3d635af46b20e87d6ee11b"
}

I'm 100% sure I own the NFT, so I'm not sure how the signature could be wrong. I set all this up by following the README on this repo and on the protocol-example repo. Am I sending wrong params when calling order.sell?

I do see "assetClass": "ERC721_LAZY" in the request body, which does seem completely wrong since I'm dealing with an 1155.

Facing Error while creating instance of Ethereum-sdk

image

This is what my code looks like.

  const { library: provider, account: from } = useWeb3React();
  useEffect(() => {
    console.log(`account: ${from}`);
  }, [from]);
  const wallet = useMemo(() => {
    if (provider !== undefined && from !== undefined) {
      const address = toUnionAddress(`ETHEREUM:${from}`);
      return new EthereumWallet(
        new Web3Ethereum({ web3: provider, from }),
        address
      );
    } else {
      return undefined;
    }
  }, [provider, from]);
  const sdk = useMemo(() => {
    if (wallet !== undefined) {
      return createRaribleSdk(wallet, "dev"); // error occurs on this line. I did tried to pass params there. But the error remains same.
    } else {
      return undefined;
    }
  }, [env, wallet]);

The package versions that I am using are.

"@rarible/protocol-ethereum-sdk": "^0.12.8",
"@rarible/sdk-wallet": "^0.7.11",

Can not Purchase order

When I try to purchase order by using this code, I get "transaction underpriced" error.
sdk.order.buy({ order, payouts: [], originFees: [], amount: 1, infinite: true })

ERC1155 Sell and Bid orders error 400

When placing a bid or sell order on an ERC1155 token from the SDK, I get this error every time.
I'm testing on Rinkeby network.

The error:
Failed to load resource: the server responded with a status of 400 ()

Here is the full request that I do:

curl 'https: //ethereum-api-staging.rarible.org/v0.1/order/orders' \ -H 'authority: ethereum-api-staging.rarible.org' \ -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36' \ -H 'content-type: application/json' \ -H 'accept: */*' \ -H 'sec-gpc: 1' \ -H 'origin: https://rarible-demo.bubbleapps.io' \ -H 'sec-fetch-site: cross-site' \ -H 'sec-fetch-mode: cors' \ -H 'sec-fetch-dest: empty' \ -H 'referer: https://rarible-demo.bubbleapps.io/' \ -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \ --data-raw '{"maker":"0xbea9938565b830a263162c86de7642177fa08004","make":{"assetType":{"@type":"ERC1155","contract":"0x1af7a7555263f275433c6bb0b8fdcd231f89b1d7","tokenId":"86239056537866358507050266989756184312317378498709552951663058336055197433857","uri":"QmVeSu3CNqY6PVTkDFzABvQwtBLrK6uwgFZtWo2vMTfmNH","creators":[{"account":"0xbea9938565b830a263162c86de7642177fa08004","value":10000}],"royalties":[{"account":"0xbea9938565b830a263162c86de7642177fa08004","value":1000}],"signatures":["0xd3cf1d4d8129d559a65da90e078a555906e43989226a3043e660686165043280173751fb645946c1510180b5e512c8a4681262a701297753e8f1ecd054d790db1b"],"supply":"6","assetClass":"ERC721_LAZY"},"value":"1"},"take":{"assetType":{"assetClass":"ETH"},"value":"1000000000000000000"},"type":"RARIBLE_V2","data":{"dataType":"RARIBLE_V2_DATA_V1","payouts":[],"originFees":[]},"salt":"18599704616995546978572909908843229650706680586262049193108086493917652791984","signature":"0xfa5ebd00702c401b4bf7e1c603cecef4e93dcddbb2539bfc76e4e896ad195dd40d98c3bd9a896316ea538699e58b7f9f931aaea5ae5e953193182aabb4dc06f81b"}' \ --compressed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.