3

I’m trying to access the keyset of a sender of a transaction without explicitly passing the publicKey as a string function parameter. I know that in the docs there is a (chain-data) function that returns the following object:

{“block-height”: 0,“block-time”: 0,“chain-id”: “”,“gas-limit”: 0,“gas-price”: 0,“sender”: “”}

I have tried using this and the sender always returns an empty string I have been interacting with my smart contract through a javascript front-end and have been hosting a blockchain instance locally on port 9001, as is outlined in the todo-mvc example in Kadena’s github. To interact with the contract I have been using pact-lang-api, and specifically the Pact.fetch.local() and Pact.fetch.send() functions, and in both cases the sender returns “”

Are there any best practices or workarounds for this?

(defun get-sender ()
   (let (tx-data (chain-data))
     [(at "sender" tx-data)]
   )
)
;returns -> [""]

this is the javascript call:

test = (keyset) => {
  const cmdObj = {
    pactCode: `(contract.get-sender)`,
    keyPairs: keyset
  }
  Pact.fetch.local(cmdObj, API_HOST)
  .then(res => {
     console.log(res.data);
  })
}
//logs -> [""]

I am looking for it to return the sender's public key instead

fmelp
  • 31
  • 2

1 Answers1

3

You can manually set sender information using cmd's meta field.

See here: https://github.com/kadena-io/pact-lang-api/blob/master/pact-lang-api.js#L366

For example,

const cmds = {
                    keyPairs: KEY_PAIR,
                    pactCode: 'todos.delete-todos "id-1"',
                    meta: {
                      sender: KEY_PAIR.publicKey,
                      chainId: "",
                      gasPrice: 0,
                      gasLimit: 0
                    }
              }
Pact.fetch.send(cmds, API_HOST)