Error from the data field

I am getting arror from terminal that says : “built-in functions not subscriptable”.

  1. If I’m passing in these arguments in the data field, must they all come in order or order not matter?

    data = {
    “sender”: my_address,
    “receiver”: receiver,
    “fee”: params.get(‘minFee’),
    “flat_fee”: True,
    “amt”: 0,
    “first”: params.get(‘lastRound’),
    “last”: params.get(‘lastRound’) + 1000,
    “note”: note,
    “gen”: params.get(‘genesisID’),
    “gh”: params.get(‘genesishashb64’)
    }

  1. Can you send us the code and the full error message?
  2. The order does not matter in a dict such as data.

I’ve been working around it. But here is another error I’m getting when I had to specify each parameter in the data field.

I test for the length of the addresses and it’s 58, so I’m confused.

Not sure if this is the issue, but the line:

receiver=params.get(receiver) looks funny. If params is a dict of suggested parameters returned by the API, then there is no receiver field. Did you mean to just use receiver?

Can you try to remove

receiver = params.get(receiver)

and print receiver to be sure it’s a valid address.

Note: You can copy-paste code in Forum, you just need to put them between three backquotes like ```python
my python code
```
or
```
my result of python
```
It is often more convenient than images.

Yes I. Did. Perhaps I should not have right?

OK great noted. But I had explicitly specify the receiver since I want to send token from one account to another and to another account.

I’ve removed it but getting same error as WrongKeyLengthError: Key length must be 58

Can you print sender and receiver just before the line trxn = transaction... and check those are valid addresses? You can do that by copy-pasting them in an Algorand explorer such as https://goalseeker.purestake.io/algorand/testnet

I tried it. They’re valid addresses as shown in Image.

But if I used the full word receiver, I get this error…

This is a different error, we’re progressing.
Can you copy-paste the full code and the full reported error as a response of this post, inside a code block (i.e., between ``` and ``` in your post)?

1 Like

//generateAccount.py

from algosdk import algod
from connect import Connect

accounts = {}
# To get acount information
getConnect = Connect()
forAlcInfo = getConnect.connectToNetwork() 

# define a function to generate 2 accounts
def generateAccounts():
    # generate accounts 1 and 2
    private_key_1, address_1 = account.generate_account()
    private_key_2, address_2 = account.generate_account()
    account_1 =  {
            "pkey": private_key_1,
            "alc_address":address_1,
            "alc_information": forAlcInfo.account_info(address_1)
        }
    account_2 = {
            "pkey": private_key_2,
            "alc_address":address_2,
            "alc_information": forAlcInfo.account_info(address_2)
        }
    # store accounts 1 and 2
    accounts["account_1"] = account_1
    accounts["account_2"] = account_2
    return (accounts)```

```\\sendTransaction file```

```from algosdk import algod, transaction
from connect import Connect
from generateaccount import accounts, generateAccounts

defaultAddr = "N6SJLDQXCXZ7IJMLM5VVEAWJ36JUJSDQVNQFA2I3BKFOWE3QLKKJGATPJ4"
private_key_alc = "QZkBrhS8lENmn30GyKMPufFPdjG88Knz0Fj279+jxVdvpJWOFxXz9CWLZ2tSAsnfk0TIcKtgUGkbCorrE3BalA=="

forAlgoClient = Connect()
algodClient = forAlgoClient.connectToNetwork()

fees=1000
fstRound=1000
last=fstRound + 1000,
memo = "Hi, sent you some Algo".encode()
# gn="testnet-v1.0"
genhash="SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="

def sendTransaction(privateKey, sender, receiver, amount):
    sndr = sender
    rcv = receiver
    amont = amount
    
    trxn = transaction.PaymentTxn(sndr, fees, fstRound, last, genhash, rcv, amont)
    signTrxn = trxn.sign(privateKey)
    # trxn_id = signTrxn.transaction.get_txid()
    return algodClient.send_transaction(signTrxn)


alc_1_addr = (accounts['account_1']['alc_address'])
alc_2_addr = (accounts['account_2']['alc_address'])
alc_1_pk = (accounts['account_1']['pkey'])

trxn_1 = sendTransaction(private_key_alc, defaultAddr, alc_1_addr, 10)

error report

Traceback (most recent call last):
  File "C:\Users\bobman\AppData\Local\Programs\Python\Python37\lib\site-packages\algosdk\algod.py", line 74, in algod_request
    raise error.AlgodHTTPError(json.loads(e)["message"])
  File "C:\Users\bobman\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\bobman\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\bobman\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:/Users/bobman/Documents/pythonTutorial/pythonTutorial.py", line 33, in <module>
    trxn_1 = sendTransaction(private_key_alc, defaultAddr, alc_1_addr, 10)
  File "c:\Users\bobman\Documents\pythonTutorial\sendtransaction.py", line 30, in sendTransaction
    return algodClient.send_transaction(signTrxn)
  File "C:\Users\bobman\AppData\Local\Programs\Python\Python37\lib\site-packages\algosdk\algod.py", line 273, in send_transaction
    **kwargs)
  File "C:\Users\bobman\AppData\Local\Programs\Python\Python37\lib\site-packages\algosdk\algod.py", line 259, in send_raw_transaction
    return self.algod_request("POST", req, data=txn, **kwargs)["txId"]
  File "C:\Users\bobman\AppData\Local\Programs\Python\Python37\lib\site-packages\algosdk\algod.py", line 76, in algod_request   
    raise error.AlgodHTTPError(e)
algosdk.error.AlgodHTTPError: msgpack decode error [pos 1]: only encoded map or array can be decoded into a struct
PS C:\Users\bobman\Documents\pythonTutorial>```

There is some error being returned, but likely not in JSON which the SDK is expecting.

Can you try / catch the send_transaction statement and print the error it’ll show you what’s wrong.

For example:

try:
    tx_confirm = acl.send_transaction(signed_tx)
    print(tx_confirm)
except Exception as e:
    print(e)

Note if you are using the PureStake API, you need to include the header type with the send, something like algod_client.send_transaction(signed_txn, headers={'content-type': 'application/x-binary'})

Yay! It worked. @Tim that’s cool one from you. Sincerely I had used the same parameter overtime before now and it never work. Perhaps I was using it wrongly. But I learned much from the error. You really helped me a lot get over this. I almost gave up cos its been 3 days now trying to solve just one issue. But I appreciate your help a lot. Thank you and to other guys who have been helpful @fabrice @liz

1 Like