Rust client to Opensea's APIs and Ethereum smart contracts

Overview

opensea.rs

Rust bindings & CLI to the Opensea API and Contracts

Github Actions

CLI Usage

Run cargo r -- --help to get the top level help menu:

opensea-cli 0.1.0
Choose what NFT subcommand you want to execute

USAGE:
    opensea-cli <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    buy       Purchase 1 or more NFTs, with optional Flashbots support
    deploy    Deploy the Ethereum contract for doing consistency checks inside a Flashbots bundle
    help      Prints this message or the help of the given subcommand(s)
    prices    Get OpenSea orderbook information about the token

To view each individual subcommand's help menu, run: opensea-cli <subcommand name> --help

Buying NFT(s)

Here's an example command for purchasing some ERC1155 NFTs using Flashbots:

cargo run buy \
    --nft.erc1155 \
    --nft.address "0xTheNFTAddress" \
    --nft.ids 1 --nft.ids 2 --nft.ids 3 \
    --eth.private_key "0xMyPrivateKey" \
    --eth.url http://localhost:8545 \
    --flashbots.bribe 1000000000000000000 \
    --flashbots.bribe_receiver 0xYourBriberContract

Instead of providing nft.ids, you can also provide a CSV file via the --nft.ids_path command, where the first column contains the id of the NFT and the second column contains the quantity of purchased NFT.

Here's an ERC1155 example (which also requires passing the --nft.erc1155 flag)

1,1
2,5
3,2

And an ERC721 example

1
2
3

Flashbots Support: This will proceed to create a Flashbots bundle with 4 transactions: 3 NFT take orders on OpenSea, and a 4th transaction which sends the bribe to the briber contract while also doing consistency checks that we have received the NFTs

Public Mempool: If you omit the Flashbots parameters, it'll proceed to submit the transactions normally via the public mempool.

Development

Rust Toolchain

We use the stable Rust toolchain. Install by running: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Building & testing

cargo check
cargo test
cargo doc --open
cargo build [--release]

Features

  • Opensea API
  • Opensea Types (Orders etc.)
  • Opensea Contract clients
    • ERC721
    • ERC1155
    • Fill a Sell order
    • Generalize the API to arbitrary Opensea marketplace schemas
  • CLI for operations
    • Flashbots contract deployer
    • Query prices
    • Purchase NFT(s)
    • Sniping drops (pre-configuring the target and looping)

Running ignored tests

  1. Create a hardhat.config.js file and fork from mainnet at this block:
export default {
  networks: {
    hardhat: {
      forking: {
        url: "https://eth-mainnet.alchemyapi.io/v2/<YOUR API KEY>",
        blockNumber: 13037331,
      },
      hardfork: "london",
    }
  }
}
  1. cargo test --ignored

Acknowledgements

Briber.sol contract written by Anish Agnihotri

Comments
  • Integer overflow when casting to u64

    Integer overflow when casting to u64

    When I provide "long" (widespread at OpenSea shared contract) nft.ids, it returns error. E.g.

    cargo run prices --nft.address 0x495f947276749ce646f68ac8c248420045cb7b5e --nft.ids 96475701516811371815276227977766131962669887094423874457871336890511147401221
    

    Output:

    thread 'main' panicked at 'Integer overflow when casting to u64', /Users/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.9.1/src/lib.rs:38:1
    

    Same happens if provide via csv --nft.ids_path. Seems like it's trying to convert this string to integer somewhere.

    opened by kirmishov 1
  • remove unvalidated fee fields on buy side

    remove unvalidated fee fields on buy side

    Am fairly sure the buy fee params (were previously mirroring sell fee params) are not checked with the default fee setup opensea uses. https://etherscan.io/tx/0x42bf65ad17af8926c86444b0ea5a2177eb44976e71fe5061ff6e5e2ea78dbf02 atomicMatch_ on this commit and no buy fee. It doesn't allow fee avoidance but saves 2 nonezero bytes of calldata

    opened by ghost 0
  • "root path '{}' is not absolute"

    Hi there.

    Running cargo check is giving me the following error:

       Compiling ethers-contract-abigen v0.5.4
    error: 1 positional argument in format string, but no arguments were given
      --> (redacted)/.cargo/registry/src/github.com-1ecc6299db9ec823/ethers-contract-abigen-0.5.4/src/source.rs:93:46
       |
    93 |             .map_err(|_| anyhow!("root path '{}' is not absolute"))?;
       |                                              ^^
    
    error: could not compile `ethers-contract-abigen` due to previous error
    
    opened by moxley01 0
  • current price deserialization u256_from_dec_str

    current price deserialization u256_from_dec_str

    Hi,

    First of all thanks for opensourcing this. I am totally new to rust and experiencing some issues.

    But a notable one (that might actually be an issue) is the following :

    #[serde(deserialize_with = "u256_from_dec_str")] pub current_price: U256,

    has problems with how I receive price from opensea as follows :

    "current_price": "65000000000000000.00000000000"

    To replicate the error you can just add the price above in orders.json and run cargo test

    For now I did fix it like :

    pub fn u256_from_dec_str<'de, D>(deserializer: D) -> Result<U256, D::Error>
    where
     D: de::Deserializer<'de>,
    {
     let s: &str = de::Deserialize::deserialize(deserializer)?;
     let s: &str = &s.replace(".", "");
     U256::from_dec_str(s).map_err(de::Error::custom)
    }```
    opened by OTPkat 0
  • Error 0432 & 0599

    Error 0432 & 0599

    C:\Users\Windows\Documents\opensea-rs-master>cargo run prices Compiling ethers-providers v0.5.4 error[E0432]: unresolved import tokio::net::UnixStream --> C:\Users\Windows.cargo\registry\src\github.com-1ecc6299db9ec823\ethers-providers-0.5.4\src\transports\ipc.rs:22:5 | 22 | net::UnixStream, | ^^^^^^^^^^^^^^^ no UnixStream in net

    error[E0599]: no function or associated item named connect found for struct ipc::Ipc in the current scope --> C:\Users\Windows.cargo\registry\src\github.com-1ecc6299db9ec823\ethers-providers-0.5.4\src\provider.rs:919:31 | 919 | let ipc = crate::Ipc::connect(path).await?; | ^^^^^^^ function or associated item not found in ipc::Ipc | ::: C:\Users\Windows.cargo\registry\src\github.com-1ecc6299db9ec823\ethers-providers-0.5.4\src\transports\ipc.rs:30:1 | 30 | pub struct Ipc { | -------------- function or associated item connect not found for this | = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item connect, perhaps you need to implement one of them: candidate #1: hyper::client::connect::sealed::Connect candidate #2: hyper::client::connect::sealed::ConnectSvc

    opened by JohnnyOmm 1
  • add argument custom gas limit

    add argument custom gas limit

    Would be great to have an option to set gas limit w/ cargo run buy --eth.gas

    cause 300k gas limit nowadays may return [Out of gas] error.

    https://github.com/gakonst/opensea-rs/blob/master/opensea/src/lib.rs#L200

    opened by kirmishov 0
Owner
Georgios Konstantopoulos
blockchain scalability, information security and mechanism design. That Layer 2 guy. Aspiring Rustacean.
Georgios Konstantopoulos
Rust project for working with ETH - Ethereum transactions with Rust on Ganache and also deploy smart contracts :)

Just a test project to work with Ethereum but using Rust. I'm using plain Rust here, not Foundry. In future we will use Foundry. Hope you're already f

Akhil Sharma 2 Dec 20, 2022
Minimal Substrate node configured for smart contracts via pallet-contracts.

substrate-contracts-node This repository contains Substrate's node-template configured to include Substrate's pallet-contracts ‒ a smart contract modu

Parity Technologies 73 Dec 30, 2022
RGB smart contracts: client-facing library & command-line for desktop and mobile

RGB smart contracts RGB is confidential & scalable client-validated smart contracts for Bitcoin & Lightning. It embraces the concepts of private & mut

RGB: scalable & private smart contracts for bitcoin & lightning 4 Mar 15, 2023
Ethereum (and Ethereum like) indexer using P2P message to fetch blocks and transactions

Ethereum P2P indexer This project is an indexer for Ethereum and Ethereum forks. It takes advantage of the ETH (Ethereum Wire Protocol) to fetch block

null 5 Nov 10, 2023
Substreams development kit for Ethereum chains, contains Firehose Block model and helpers as well as utilities for Ethereum ABI encoding/decoding.

Substreams Ethereum Substreams development kit for Ethereum chains, contains Rust Firehose Block model and helpers as well as utilities for Ethereum A

StreamingFast 15 Oct 25, 2022
evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM → NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

Aurora 125 Dec 3, 2022
Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin.

dlctix Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin. This project is part of the Backdrop Build

null 7 Feb 29, 2024
zink! is a library for developing ink! smart contracts with useful Rust macros that extend functionality and reduce boilerplate code.

zink! Smart Contract Macros This is a helper library for developing ink! smart contracts. It contains useful Rust macros that extend functionality and

Scio Labs 3 Nov 3, 2023
A framework for creating PoC's for Solana Smart Contracts in a painless and intuitive way

Solana PoC Framework DISCLAIMER: any illegal usage of this framework is heavily discouraged. Most projects on Solana offer a more than generous bug bo

Neodyme 165 Dec 18, 2022
Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

Jacob 27 Dec 17, 2022
Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

NEARFoundation 9 Aug 3, 2022
A framework for publishing, deploying, invoking, and upgrading soroban smart contracts

SmartDeploy A framework for publishing, deploying, and upgrading Soroban smart contracts. Uses Loam-SDK Publishing Currently smart contracts are insta

null 4 May 10, 2023
An automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function call efficiency.

Solidity-Gas-Optimizoor An high performance automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function

Chia Yong Kang 10 Mar 11, 2024
Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis.

Heimdall is an advanced EVM toolkit which aims to make dealing with smart contracts on EVM based chains easier. Installation & Usage Heimdall's update

Jonathan Becker 489 Jan 2, 2023
A template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

null 1 Mar 7, 2022
Create your personal token with rust smart contracts

Solana Rust Token ?? This application written Rust using Anchor ⚓

Ritesh 6 Nov 22, 2022
Rust library for build smart contracts on Internet Computer, by the Spinner.Cash team.

Spinner Rust library for building smart contracts on the Internet Computer. More specifically it is used by Spinner.Cash, a decentralized layer-2 prot

Spinner 6 May 31, 2022
Rust implementation for Thippy -- a Substrate parachain for smart contracts.

Thippy ‒- A Smart Contracts Parachain This is a node implementation of Thippy, a Substrate parachain for smart contracts. Developing Smart Contracts f

Arthur·Thomas 15 Mar 16, 2022
🖨 Template for Rust applications & smart contracts @okp4.

Rust Template Template for Rust projects @okp4. Purpose & Philosophy This repository holds the template for building Rust projects with a consistent s

OKP4 – Open Knowledge Protocol For 6 Nov 17, 2022