NeoNEXT / neoline

A handy NEO wallet in your browser.
https://neoline.io
MIT License
9 stars 3 forks source link

How to use Neoline's getStorage() method to obtain 'data' parameter? #125

Closed robliou closed 1 year ago

robliou commented 1 year ago

Hi @hacfox ,

Thanks to your help from yesterday, I was able to use the Neoline.invoke() method to not only call the 'transfer' operation, but also to input a piece of data (string: 'hello') to storage, as seen below:

image

Using dora, I verified that the data was properly stored to the blockchain:

image

My follow up question is, is it possible to use a Neoline call to obtain this data? I tried using the Neoline.getStorage() method:

const invokeMethod = instance.getStorage({
        scriptHash: '0x9c0c81ac61583cc3e2dc325fc51dbce48097a874',
        key: 'data',
        network: 'TestNet'
    })

But I get this error:

There was an error when broadcasting this transaction to the network.

Any idea what I could be doing wrong here, or if there is a better way to get data that has been stored?

For additional reference, this is how data is stored in the Boa smart contract:

@public
def onNEP17Payment(from_address: int, amount: int, data: Union[bytes, int]):
    if from_address is not None:
        assert len(from_address.to_bytes()) == 20

    if from_address is None and runtime.calling_script_hash == GAS_SCRIPT:
        return

    # only accept NEO or GAS
    if runtime.calling_script_hash != GAS_SCRIPT and runtime.calling_script_hash != NEO_SCRIPT:
        abort()

    storage.put(b'X' + from_address.to_bytes(), amount)
    storage.put(b'X' + from_address.to_bytes(), data)

Thanks in advance,

cschuchardt88 commented 1 year ago

You can only get storage information if the contract uses "storage.put" function. You would need to pass the key to the function.

storage.put(b'X' + from_address.to_bytes(), amount)
storage.put(b'X' + from_address.to_bytes(), data)
neolineN3.getStorage({
    scriptHash: 'hash here',
    key: 'X006b26dd0d2aa076b11082847a094772450f05af', // storage.put(b'X' + from_address.to_bytes(), data)
})