ERC725 / ERC735 implementation
Implementation Image
At first, read this article and understand basic flow and usage of ERC725 and ERC735
Implementation Sample
Working sample code is here. This is origin protocol repo so that this is reliable.
Update above code for solidity compiler v0.5
Convert accessor constant to view
Specigy "memory" implicitly to arguments of function when it is string or array or bytes
Implecitly padding, like keccak256(msg.sender) => keccak256(abi.encodePacked(msg.sender));
Change return value obtaining and argument passing style of call
success = executions[_id].to.call(executions[_id].data, 0); => (bool success, ) = executions[_id].to.call(executions[_id].data);
Where the mapping of a identity address and a user wallet address store?
In Origin Protocol case, UserRegistory contract hold the mapping
About the data structure passing to "call" function
A call function appear in approve funcion of ERC725, like as follow.
executions[_id].to.call.value(executions[_id].value)(executions[_id].data)
This function is calling executions[_id].data with value of executions[_id].value from executions[_id].to
The structure of data is as follow
Web3 implementation examples
1. Creating calldata for execute function of ERC725
code:sample1.js
import web3 form 'web3'
import json from "/contracts/ClaimHolder.json"
const createCalldata = async (identityAddress, privateKey, claimIssuerAddress, uri) => {
// Create signatute
const hexedData = web3.utils.asciiToHex("this guy is totes legit")
const hashedDataToSign = web3.utils.soliditySha3(
identityAddress, 3, hexedData,)
// The private key must start form '0x...'
const sig = await this.web3.eth.accounts.sign(hashedDataToSign, privateKey).signature
// Create contract instance
const identityContract = new web3.eth.Contract(json.abi, identityAddress)
// Create calldata
const claimIssuer = claimIssuerAddress
const abicode = await identityContract.methods
.addClaim(3, 1, claimIssuer, sig, hexedData, uri)
.encodeABI();
return abicode
}
2. Adding claim to ClaimHolder contract
code: sample2.js
import web3 form 'web3'
import json from "/contracts/ClaimHolder.json"
async addClaim(identityAddress, calldata, account) {
const identityContract = new web3.eth.Contract(json.abi, identityAddress)
const tx = await identityContract.methods.execute(identityAddress, 0, calldata)
const receipt = await tx.send({ from: account, gasPrice: 100000000 })
return recept
}