Skip to content

attestate/imgs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imgs smart contract

imgs is a minimal ERC-721 style marketplace that lets creators post image URLs with a mint price and lets collectors mint tokens that point to those URLs. Each mint forwards the payment to the original poster while maintaining full token enumeration support (name, symbol, tokenURI, tokenByIndex, and tokenOfOwnerByIndex).

Features

  • Register image posts with an asking price via post(url, price)
  • Mint ERC-721 compatible tokens that reference the posted URL and emit standard Transfer events
  • Automatic revenue forwarding to the post creator with manual reentrancy protection
  • Full token enumeration helpers (balanceOf, tokenByIndex, etc.) backed by on-chain bookkeeping
  • Comprehensive Foundry test suite covering happy paths, failure cases, and attack attempts

Repository layout

  • src/imgs.sol – the core contract implementation
  • test/imgs.t.sol – Foundry tests that exercise posting, minting, payments, and guard rails
  • foundry.toml – project configuration including Optimism RPC/Etherscan placeholders
  • lib/forge-std – testing utilities vendored from Foundry's standard library

Getting started

  1. Install Foundry:
  2. Fetch dependencies (only needed if lib is empty):
    forge install

Contract walkthrough

Typical interaction flow:

  1. Creator posts an image
    uint256 postId = imgs.post("https://example.com/art.png", 0.1 ether);
    The contract stores the URL and price while tracking the posting account.
  2. Collector mints
    imgs.mint{value: 0.1 ether}(postId);
    • Reverts if the post id is invalid or the payment is too low.
    • Mints a new token whose tokenURI equals the post URL.
    • Forwards the price (if > 0) to the original poster and guards against reentrancy.
  3. Reading state
    • tokenURI(tokenId) returns the stored image URL.
    • tokenOfOwnerByIndex(account, i) enumerates owned tokens.
    • supportsInterface reports ERC-165, ERC-721, metadata, and enumerable support.

Testing

The Foundry tests cover:

  • Metadata queries (name, symbol, tokenURI, enumeration helpers)
  • Posting and minting logic, including multiple minters and free mints
  • Payment forwarding failures (e.g., recipients that reject ETH)
  • Guard rails for insufficient payment, invalid IDs, and manual reentrancy attempts

Run forge test to verify the contract before deploying or modifying it.

Live Deployment

The contract currently lives on Base at 0xcec28473bb6cae7d75e02d534ad81a537e5aaaa5 using CREATE2 via deployer 0x0000000000FFe8B47B3e2130213B802212439497 with salt 0x0000000000000000000000000000000000000000f00df00df00df00df00df00d. The deployed bytecode was:

0x6080604052348015600e575f80fd5b506117428061001c5f395ff3fe6080604052600436106100e7575f3560e01c80632f745c591161008957806370a082311161005857806370a082311461034b57806395d89b4114610387578063a0712d68146103b1578063c87b56dd146103e1576100e7565b80632f745c591461025b5780634e6c3c95146102975780634f6ccce7146102d35780636352211e1461030f576100e7565b80630b1e7f83116100c55780630b1e7f831461018d57806316865fe3146101cb57806317906c2e1461020757806318160ddd14610231576100e7565b806301ffc9a7146100eb57806303fac3c31461012757806306fdde0314610163575b5f80fd5b3480156100f6575f80fd5b50610111600480360381019061010c9190610f40565b61041d565b60405161011e9190610f85565b60405180910390f35b348015610132575f80fd5b5061014d6004803603810190610148919061102b565b6104de565b60405161015a9190611078565b60405180910390f35b34801561016e575f80fd5b50610177610509565b6040516101849190611101565b60405180910390f35b348015610198575f80fd5b506101b360048036038101906101ae9190611121565b610546565b6040516101c29392919061115b565b60405180910390f35b3480156101d6575f80fd5b506101f160048036038101906101ec9190611121565b610620565b6040516101fe9190611101565b60405180910390f35b348015610212575f80fd5b5061021b6106bb565b6040516102289190611078565b60405180910390f35b34801561023c575f80fd5b506102456106c1565b6040516102529190611078565b60405180910390f35b348015610266575f80fd5b50610281600480360381019061027c919061102b565b6106c7565b60405161028e9190611078565b60405180910390f35b3480156102a2575f80fd5b506102bd60048036038101906102b891906112c3565b610806565b6040516102ca9190611078565b60405180910390f35b3480156102de575f80fd5b506102f960048036038101906102f49190611121565b6108ed565b6040516103069190611078565b60405180910390f35b34801561031a575f80fd5b5061033560048036038101906103309190611121565b610931565b604051610342919061131d565b60405180910390f35b348015610356575f80fd5b50610371600480360381019061036c9190611336565b610961565b60405161037e9190611078565b60405180910390f35b348015610392575f80fd5b5061039b6109aa565b6040516103a89190611101565b60405180910390f35b6103cb60048036038101906103c69190611121565b6109e7565b6040516103d89190611078565b60405180910390f35b3480156103ec575f80fd5b5061040760048036038101906104029190611121565b610dfe565b6040516104149190611101565b60405180910390f35b5f6301ffc9a760e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061047757506380ac58cd60e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806104a75750635b5e139f60e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806104d7575063780e9d6360e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b9050919050565b6003602052815f5260405f2081815481106104f7575f80fd5b905f5260205f20015f91509150505481565b60606040518060400160405280600481526020017f696d677300000000000000000000000000000000000000000000000000000000815250905090565b60048181548110610555575f80fd5b905f5260205f2090600302015f91509050805f015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010180546105999061138e565b80601f01602080910402602001604051908101604052809291908181526020018280546105c59061138e565b80156106105780601f106105e757610100808354040283529160200191610610565b820191905f5260205f20905b8154815290600101906020018083116105f357829003601f168201915b5050505050908060020154905083565b6001602052805f5260405f205f91509050805461063c9061138e565b80601f01602080910402602001604051908101604052809291908181526020018280546106689061138e565b80156106b35780601f1061068a576101008083540402835291602001916106b3565b820191905f5260205f20905b81548152906001019060200180831161069657829003601f168201915b505050505081565b60065481565b60055481565b5f8073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361072d576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60035f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f208054905082106107a6576040517f4e23d03500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60035f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2082815481106107f5576107f46113be565b5b905f5260205f200154905092915050565b5f806006549050600460405180606001604052803373ffffffffffffffffffffffffffffffffffffffff16815260200186815260200185815250908060018154018082558091505060019003905f5260205f2090600302015f909190919091505f820151815f015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060208201518160010190816108bf9190611588565b5060408201518160020155505060065f8154809291906108de90611684565b91905055508091505092915050565b5f6005548210610929576040517f4e23d03500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b819050919050565b6002602052805f5260405f205f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f60035f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20805490509050919050565b60606040518060400160405280600481526020017f494d475300000000000000000000000000000000000000000000000000000000815250905090565b5f805f9054906101000a900460ff1615610a2d576040517f37ed32e800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015f806101000a81548160ff0219169083151502179055506004805490508210610a84576040517f7e81c05500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60048381548110610a9957610a986113be565b5b905f5260205f2090600302016040518060600160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182018054610b149061138e565b80601f0160208091040260200160405190810160405280929190818152602001828054610b409061138e565b8015610b8b5780601f10610b6257610100808354040283529160200191610b8b565b820191905f5260205f20905b815481529060010190602001808311610b6e57829003601f168201915b50505050508152602001600282015481525050905080604001513414610bdd576040517f569e8c1100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f600554905060055f815480929190610bf590611684565b91905055503360025f8381526020019081526020015f205f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060035f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2081908060018154018082558091505060019003905f5260205f20015f9091909190915055816020015160015f8381526020019081526020015f209081610ccc9190611588565b50803373ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45f82604001511115610ddc575f825f015173ffffffffffffffffffffffffffffffffffffffff168360400151604051610d60906116f8565b5f6040518083038185875af1925050503d805f8114610d9a576040519150601f19603f3d011682016040523d82523d5f602084013e610d9f565b606091505b5050905080610dda576040517f90b8ec1800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5f805f6101000a81548160ff0219169083151502179055508092505050919050565b60606005548210610e3b576040517f3f6cc76800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015f8381526020019081526020015f208054610e579061138e565b80601f0160208091040260200160405190810160405280929190818152602001828054610e839061138e565b8015610ece5780601f10610ea557610100808354040283529160200191610ece565b820191905f5260205f20905b815481529060010190602001808311610eb157829003601f168201915b50505050509050919050565b5f604051905090565b5f80fd5b5f80fd5b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b610f1f81610eeb565b8114610f29575f80fd5b50565b5f81359050610f3a81610f16565b92915050565b5f60208284031215610f5557610f54610ee3565b5b5f610f6284828501610f2c565b91505092915050565b5f8115159050919050565b610f7f81610f6b565b82525050565b5f602082019050610f985f830184610f76565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610fc782610f9e565b9050919050565b610fd781610fbd565b8114610fe1575f80fd5b50565b5f81359050610ff281610fce565b92915050565b5f819050919050565b61100a81610ff8565b8114611014575f80fd5b50565b5f8135905061102581611001565b92915050565b5f806040838503121561104157611040610ee3565b5b5f61104e85828601610fe4565b925050602061105f85828601611017565b9150509250929050565b61107281610ff8565b82525050565b5f60208201905061108b5f830184611069565b92915050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6110d382611091565b6110dd818561109b565b93506110ed8185602086016110ab565b6110f6816110b9565b840191505092915050565b5f6020820190508181035f83015261111981846110c9565b905092915050565b5f6020828403121561113657611135610ee3565b5b5f61114384828501611017565b91505092915050565b61115581610fbd565b82525050565b5f60608201905061116e5f83018661114c565b818103602083015261118081856110c9565b905061118f6040830184611069565b949350505050565b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6111d5826110b9565b810181811067ffffffffffffffff821117156111f4576111f361119f565b5b80604052505050565b5f611206610eda565b905061121282826111cc565b919050565b5f67ffffffffffffffff8211156112315761123061119f565b5b61123a826110b9565b9050602081019050919050565b828183375f83830152505050565b5f61126761126284611217565b6111fd565b9050828152602081018484840111156112835761128261119b565b5b61128e848285611247565b509392505050565b5f82601f8301126112aa576112a9611197565b5b81356112ba848260208601611255565b91505092915050565b5f80604083850312156112d9576112d8610ee3565b5b5f83013567ffffffffffffffff8111156112f6576112f5610ee7565b5b61130285828601611296565b925050602061131385828601611017565b9150509250929050565b5f6020820190506113305f83018461114c565b92915050565b5f6020828403121561134b5761134a610ee3565b5b5f61135884828501610fe4565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806113a557607f821691505b6020821081036113b8576113b7611361565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f600883026114477fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8261140c565b611451868361140c565b95508019841693508086168417925050509392505050565b5f819050919050565b5f61148c61148761148284610ff8565b611469565b610ff8565b9050919050565b5f819050919050565b6114a583611472565b6114b96114b182611493565b848454611418565b825550505050565b5f90565b6114cd6114c1565b6114d881848461149c565b505050565b5b818110156114fb576114f05f826114c5565b6001810190506114de565b5050565b601f82111561154057611511816113eb565b61151a846113fd565b81016020851015611529578190505b61153d611535856113fd565b8301826114dd565b50505b505050565b5f82821c905092915050565b5f6115605f1984600802611545565b1980831691505092915050565b5f6115788383611551565b9150826002028217905092915050565b61159182611091565b67ffffffffffffffff8111156115aa576115a961119f565b5b6115b4825461138e565b6115bf8282856114ff565b5f60209050601f8311600181146115f0575f84156115de578287015190505b6115e8858261156d565b86555061164f565b601f1984166115fe866113eb565b5f5b8281101561162557848901518255600182019150602085019450602081019050611600565b86831015611642578489015161163e601f891682611551565b8355505b6001600288020188555050505b505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61168e82610ff8565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036116c0576116bf611657565b5b600182019050919050565b5f81905092915050565b50565b5f6116e35f836116cb565b91506116ee826116d5565b5f82019050919050565b5f611702826116d8565b915081905091905056fea2646970667358221220a9f04ed7d9f8e96d722b212cf3036432c69dfe98866d4da8d43494585559563a64736f6c63430008190033

License

The Solidity sources now use the MIT SPDX identifier. Ensure downstream consumers adopt compatible licensing terms.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published