All Projects β†’ sagivo β†’ solidity-utils

sagivo / solidity-utils

Licence: Apache-2.0 license
solidity utils to make your life easier

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to solidity-utils

clarinet
Clarinet is a simple, modern and opinionated runtime for testing, integrating and deploying Clarity smart contracts.
Stars: ✭ 209 (+1206.25%)
Mutual labels:  smart-contracts
leafleth
πŸ“‘ Documentation generator for Solidity
Stars: ✭ 24 (+50%)
Mutual labels:  smart-contracts
hardhat-contract-sizer
Output Ethereum contract sizes with Hardhat πŸ“
Stars: ✭ 55 (+243.75%)
Mutual labels:  smart-contracts
ether-swr
Ether-SWR is a React hook that fetches Ethereum data. It streamlines the chores to keep the internal state of the Decentralized App (DApp), batches the RPC calls to an Ethereum node and cache the responses
Stars: ✭ 125 (+681.25%)
Mutual labels:  smart-contracts
akropolis
πŸ’₯ Akropolis+Yearn
Stars: ✭ 0 (-100%)
Mutual labels:  smart-contracts
erc20-balance
πŸ’Ž Get 2000+ ERC-20 token balances with JavaScript. Supports Node.js and Deno
Stars: ✭ 18 (+12.5%)
Mutual labels:  smart-contracts
ipfs-eth-database
An example of usage IPFS in Ethereum Smart Contracts
Stars: ✭ 55 (+243.75%)
Mutual labels:  smart-contracts
nba-smart-contracts
Smart contracts and transactions for Topshot, the official NBA digital collectibles game on the Flow Blockchain
Stars: ✭ 316 (+1875%)
Mutual labels:  smart-contracts
vandal
Static program analysis framework for Ethereum smart contract bytecode.
Stars: ✭ 121 (+656.25%)
Mutual labels:  smart-contracts
flow-js-testing
Testing framework to enable Cadence testing via a set of JavaScript methods and tools
Stars: ✭ 44 (+175%)
Mutual labels:  smart-contracts
koinos-gui-miner
The Koinos Miner (GUI) provides a sleek and functional user interface that allows users to mine the KOIN ERC-20 which will be used to deliver an equitable initial token distribution on the Koinos blockchain.
Stars: ✭ 26 (+62.5%)
Mutual labels:  smart-contracts
prb-math
Solidity library for advanced fixed-point math
Stars: ✭ 404 (+2425%)
Mutual labels:  smart-contracts
erc721
The reference implementation of the ERC-721 non-fungible token standard.
Stars: ✭ 989 (+6081.25%)
Mutual labels:  smart-contracts
solidity-diagram-gen
UML class diagram generator for solidity contracts
Stars: ✭ 33 (+106.25%)
Mutual labels:  smart-contracts
UpSideDai
⬆️ Take a HIGHLY leveraged position on the future price of DAI πŸ“ˆ.
Stars: ✭ 26 (+62.5%)
Mutual labels:  smart-contracts
awesome-solidity-patterns
πŸš€Awesome Solidity patterns to make life easier ✌️
Stars: ✭ 73 (+356.25%)
Mutual labels:  smart-contracts
web3scala
Scala library for integration with Ethereum clients
Stars: ✭ 24 (+50%)
Mutual labels:  smart-contracts
typescript-eth-starter
πŸ”Œ Ethereum Dapp Basic Typescript Starter
Stars: ✭ 125 (+681.25%)
Mutual labels:  smart-contracts
contracts
Alice smart contracts
Stars: ✭ 57 (+256.25%)
Mutual labels:  smart-contracts
Meadow
Integrated Ethereum implementation and tool suite focused on Solidity testing and development.
Stars: ✭ 126 (+687.5%)
Mutual labels:  smart-contracts

solidity-utils

This library has some basic missing utils in Solidity.

Dictionary

mapping + keys iteration.
Inspired by Dictionary in python or 'Objectin javascript,Dictionaryis an improved and faster mapping data-structure that allows you to retrieve all the keys in a mapping object while minimizing storage usage. The data-stucture combines linked-list iteration style with soliditymapping` hash-table.

Using

pragma solidity ^0.4.0;
// import the contract
import "github.com/sagivo/solidity-utils/contracts/lib/Dictionary.sol";

contract Foo {
    // declare and use new Dictionary structure
    using Dictionary for Dictionary.Data;
    Dictionary.Data private dic;

    function Foo() public view returns (uint) {
        dic.set(1, "value");
        dic.set(2, "foo");
        // get an item
        dic.get(2); // => '0x666f6f' (byte hex of 'foo')
        // get all keys
        dic.keys(); // => [1, 2]
    }
}

Basic Operations

set(uint id, bytes data)
get(uint id) --> bytes data
remove(uint id)
getSize() --> uint num of keys

Iteration operations

Keys are stored based on the order you specify, allows you to iterate over keys.
keys() - return an array of all the keys.
next(uint id) / prev(uint id) - return the next/prev key for a given key.
firstNodeId / lastNodeId - return the first/last key.
Example iteration:

uint nodeId = dic.firstNodeId;
while (nodeId != 0) {
  // do something
  nodeId = dic.next(nodeId);
}

Insertion Options

insertBeginning(uint id, bytes data) - add a node to the begining of the list.
insertEnd(uint id, bytes data) - add a node to the end of the list.
insertBefore(uint beforeId, uint id, bytes data) - add a node before another.
insertEnd(uint beforeId, uint id, bytes data) - add a node after another.
The default order for .set(uint id, bytes data) is insertEnd.

Limitation

Key must be bigger than 0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].