const { arrayify } = require('@ethersproject/bytes');
const Caver = require('caver-js');
const address = '0x2D526C7698231f70D7b4b2dD485eB2d280B54DbA'
const abi = [
{
"constant": false,
"inputs": [
{
"name": "_id",
"type": "uint256"
},
{
"components": [
{
"name": "trait_type",
"type": "string"
},
{
"name": "display_type",
"type": "string"
},
{
"name": "value",
"type": "uint8"
}
],
"name": "_attr",
"type": "tuple[]"
}
],
"name": "pushAttribute",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_id",
"type": "uint256"
}
],
"name": "test",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "_metas",
"outputs": [
{
"name": "description",
"type": "string"
},
{
"name": "external_url",
"type": "string"
},
{
"name": "image",
"type": "string"
},
{
"name": "name",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_id",
"type": "uint256"
}
],
"name": "gettest",
"outputs": [
{
"name": "_display_types",
"type": "string"
},
{
"name": "_trait_type",
"type": "string"
},
{
"name": "_value",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
const caver = new Caver('https://kaikas.baobab.klaytn.net:8651/');
// caver.klay.getBalance('0x92799E989a144d110E1f24aB20cdCef1dcE03493').then((res)=>{
// console.log(res);
// })
const Contract = new caver.klay.Contract(abi,address)
const test = [
{
trait_type : "trait_type1",
display_type : "display_type1",
value : '100'
}
// ,
// {
// trait_type : "trait_type2",
// display_type : "display_type2",
// value : '200'
// }
];
// const encoded = caver.abi.encodeParameters(
// ['uint256', 'tuple(string,string,uint8)[]'],
// [1, [['traitType', 'displayType', 1], ['traitType2', 'displayType2', 2]]]
// )
const encoded = caver.abi.encodeParameters(
[
{
name: '_id',
type: 'uint256',
},
{
components: [
{
name: 'trait_type',
type: 'string',
},
{
name: 'display_type',
type: 'string',
},
{
name: 'value',
type: 'uint8',
},
],
name: '_attr',
type: 'tuple[]',
},
],
[1, [['traitType', 'displayType', 1], ['traitType2', 'displayType2', 2]]]
)
Contract.methods.pushAttribute('0',encoded).call().then((res)=>{
console.log(res)
})
caver-js 버전은 1.6.4 입니다.