executeContract params 배열 문의

안녕하세요

KlipSDK 사용 중, executeContract 에서 params 문제가 있어 문의드립니다.

스마트컨트랙트 파라미터로 uint256 배열과 address 배열을 받고 있는데, excuteContract의 params에는 제대로 배열이 들어가는 것 같은데 revert 에러가 발생합니다.
Input 데이터를 보니 값이 빈 배열로 들어가는 것 같습니다. params를 주는 방식에 문제가 있는 것인지 조언이 필요합니다 ㅠ.ㅠ

테스트에 사용한 abi와 params입니다.

const abi = `{
    "inputs": [
      {
        "internalType": "address[]",
        "name": "addressArray",
        "type": "address[]"
      },
      {
        "internalType": "uint256[]",
        "name": "uintArray",
        "type": "uint256[]"
      },
      {
        "internalType": "uint256",
        "name": "uint",
        "type": "uint256"
      }
    ],
    "name": "klipArrayTest",
    "outputs": [],
    "stateMutability": "payable",
    "type": "function",
    "payable": true
  }`;
  const params = `["[0xd5acd24f017a6c01b04a6adefc24cb2979f21921,0xd5acd24f017a6c01b04a6adefc24cb2979f21921]","[1000000, 1000000]",100]`

scope에서 확인한 revert 에러를 디코딩한 값입니다.

{
  name: 'klipArrayTest',
    { name: 'addressArray', value: [], type: 'address[]' },
    { name: 'uintArray', value: [], type: 'uint256[]' },
    { name: 'uint', value: '75', type: 'uint256' }
  ]
}

안녕하세요 :slight_smile:

array type 파라미터 처리를 위한 예제 코드 첨부드립니다. 차이가 있는지 확인해보시면 좋을 것 같습니다.

solidity

pragma solidity ^0.5.0;

contract Test {
    address[] public input;

    function test(address[] memory a) public {
        input = a;
        address(0).transfer(0);
    }
}

ABI

[
	{
		"constant": false,
		"inputs": [
			{
				"name": "a",
				"type": "address[]"
			}
		],
		"name": "test",
		"outputs": [],
		"payable": false,
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"constant": true,
		"inputs": [
			{
				"name": "",
				"type": "uint256"
			}
		],
		"name": "input",
		"outputs": [
			{
				"name": "",
				"type": "address"
			}
		],
		"payable": false,
		"stateMutability": "view",
		"type": "function"
	}
]

App2App API curl 예제

curl -X POST "https://a2a-api.klipwallet.com/v2/a2a/prepare" \
 -d '{"bapp": { "name" : "Test BApp" }, "type": "execute_contract", "transaction": { "to": "0x58aB4632F559899589F63E8EDe3e098a78C6adAC", "value": "0", "abi": "{ \"constant\": false, \"inputs\": [ { \"name\": \"a\", \"type\": \"address[]\" } ], \"name\": \"test\", \"outputs\": [], \"payable\": false, \"stateMutability\": \"nonpayable\", \"type\": \"function\" }",   "params": "[[\"0x89702017A631b125E03F586975Dfe6Ce98E9F35D\", \"0x19702017A631b125E03F586975Dfe6Ce98E9F35D\"]]" } }' \
 -H "Content-Type: application/json"

테스트 트랜잭션 klaytnscope 링크 (바오밥)

1개의 좋아요

감사합니다.
배열을 파라미터로 넘겨줄 때 “[]” 로 감싸줬던 게 문제가 된 것 같습니다 !

klip sdk의 경우

 const params = `[${JSON.stringify(addressArray)},${JSON.stringify(uintArray)},uint256, uint256]`; 

이런 식으로 params를 처리 후 excuteContract를 실행하니 정상 작동합니다.
예제가 많은 도움이 되었습니다. 감사합니다^!^

1개의 좋아요