8000 GitHub - MarcoWorms/SaveState: save and load string-based states in EVM blockchains
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MarcoWorms/SaveState

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

SaveState Contract

Save and load string-based states in EVM blockchains

Integration Guide

The contract ABI can be found here.

To interact with the contract you need to call the following functions (examples for Fantom):

saveState(string memory state)

This function saves a state for a user.

import { use
7A18
Account, useContractWrite, usePrepareContractWrite } from 'wagmi'

const { config } = usePrepareContractWrite({
    address: '0x91afcced2446b635e4988ce4e664234e0ed9c7b0',
    abi: contractABI,
    functionName: 'saveState',
})
const { write } = useContractWrite(config)

const state = {
    counter: 123456
}

write(JSON.stringify(state))

loadState()

This function loads a state for a user.

Example:

import { useAccount, useContractRead, usePrepareContractRead } from 'wagmi'

const { config } = usePrepareContractRead({
    address: '0x91AFCCEd2446B635E4988ce4E664234E0Ed9C7b0',
    abi: contractABI,
    functionName: 'loadState',
})
const { read } = useContractRead(config)

const state = JSON.parse(read()) //{ counter: 123456 }

Saving Many States For A User (Keys)

saveState(string memory key, string memory state)

This function saves a state with a provided key. Default key is "default" (used when function is called without a key).

Example:

import { useAccount, useContractWrite, usePrepareContractWrite } from 'wagmi'

const { config } = usePrepareContractWrite({
    address: '0x91AFCCEd2446B635E4988ce4E664234E0Ed9C7b0',
    abi: contractABI,
    functionName: 'saveState',
})
const { write } = useContractWrite(config)

const state = {
    counter: 123456
}
write('key', JSON.stringify(state))

loadState(string memory key)

This function loads a state with a provided key. Default key is "default" (used when function is called without a key).

Example:

import { useAccount, useContractRead, usePrepareContractRead } from 'wagmi'

const { config } = usePrepareContractRead({
    address: '0x91AFCCEd2446B635E4988ce4E664234E0Ed9C7b0',
    abi: contractABI,
    functionName: 'loadState',
})
const { read } = useContractRead(config)

const state = JSON.parse(read('key')) //{ counter: 123456 }

About

save and load string-based states in EVM blockchains

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0